2020-05-09 13:31:21 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using GameLogic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 游戏启动驱动
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class GameStart : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private AssetBundle bundle;
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
2021-08-27 16:44:29 +08:00
|
|
|
|
// 判断是否是覆盖安装了包,是就清除缓存
|
|
|
|
|
ClearCach();
|
|
|
|
|
// 开始启动游戏
|
2020-05-09 13:31:21 +08:00
|
|
|
|
if (Application.isEditor && AppConst.bundleMode && AppConst.isUpdate)
|
|
|
|
|
{
|
|
|
|
|
if (!System.IO.Directory.Exists(Util.AppContentPath()))
|
|
|
|
|
{
|
|
|
|
|
XDebug.Log.error("还未打包平台资源,移放到StreamAssets目录");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Application.isEditor)
|
|
|
|
|
{
|
2021-04-15 17:29:21 +08:00
|
|
|
|
StartCoroutine(StartGame());
|
2021-06-03 13:52:55 +08:00
|
|
|
|
//playSplash();
|
2020-05-09 13:31:21 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (AppConst.bundleMode) //先走闪屏流程
|
|
|
|
|
{
|
2020-07-17 17:50:05 +08:00
|
|
|
|
if (AppConst.isSDKLogin && !SDK.SDKManager.Instance.IsInit) //当登录sdk时,等待初始化完成后再走闪屏流程
|
2020-05-09 13:31:21 +08:00
|
|
|
|
{
|
2020-07-15 13:44:37 +08:00
|
|
|
|
SDK.SDKManager.Instance.Initialize();
|
2020-07-15 17:53:40 +08:00
|
|
|
|
SDK.SDKManager.Instance.onInitLaunchCallback += s => {
|
2020-05-09 13:31:21 +08:00
|
|
|
|
playSplash();
|
2020-07-15 17:53:40 +08:00
|
|
|
|
};
|
2020-05-09 13:31:21 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
playSplash();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-27 16:44:29 +08:00
|
|
|
|
//请本地缓存
|
|
|
|
|
void ClearCach()
|
|
|
|
|
{
|
|
|
|
|
int localCode = PlayerPrefs.GetInt("SDKVersionCode", -1);
|
|
|
|
|
int code = localCode;
|
|
|
|
|
if (AppConst.isSDK)
|
|
|
|
|
{
|
|
|
|
|
code = AndroidDeviceInfo.Instance.GetVersionCode();
|
|
|
|
|
}
|
|
|
|
|
#if !UNITY_EDITOR
|
|
|
|
|
if (code != localCode)
|
|
|
|
|
{
|
|
|
|
|
string RootPath = AppConst.PersistentDataPath;
|
|
|
|
|
string path = RootPath.Substring(0, RootPath.Length - 1);
|
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(path, true);
|
|
|
|
|
}
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
PlayerPrefs.SetInt("SDKVersionCode", code);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2020-05-09 13:31:21 +08:00
|
|
|
|
|
|
|
|
|
void playSplash()
|
|
|
|
|
{
|
2021-06-03 13:52:55 +08:00
|
|
|
|
bool isShowSplash = true;
|
2021-02-26 17:58:10 +08:00
|
|
|
|
if (isShowSplash)
|
2020-05-09 13:31:21 +08:00
|
|
|
|
{
|
2021-07-13 18:20:03 +08:00
|
|
|
|
#if UNITY_IOS
|
2021-07-12 18:31:52 +08:00
|
|
|
|
string splashFilePath = "lz4_splashpanel.unity3d";
|
|
|
|
|
#else
|
|
|
|
|
string splashFilePath = "lz4/splashpanel.unity3d";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
string path = AppConst.PersistentDataPath + splashFilePath;
|
2021-02-26 17:58:10 +08:00
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
{
|
2021-07-12 18:31:52 +08:00
|
|
|
|
path = AppConst.StreamPath + splashFilePath;
|
2021-02-26 17:58:10 +08:00
|
|
|
|
}
|
|
|
|
|
bundle = AssetBundle.LoadFromFile(path, 0, GameLogic.AppConst.EncyptBytesLength);
|
|
|
|
|
GameObject gameObj = bundle.LoadAsset<GameObject>("SplashPanel");
|
|
|
|
|
GameObject gameObj2 = Instantiate(gameObj, Vector3.zero, Quaternion.identity);
|
|
|
|
|
Image image = gameObj2.transform.Find("Canvas/image").GetComponent<Image>();
|
2021-06-04 09:49:08 +08:00
|
|
|
|
image.transform.localScale = Vector3.one * 0.9f;
|
2021-06-03 17:46:38 +08:00
|
|
|
|
//Image image2 = gameObj2.transform.Find("Canvas/image2").GetComponent<Image>();
|
|
|
|
|
//image2.gameObject.SetActive(false);
|
|
|
|
|
//image2.DOFade(1, 0).OnComplete(() => {
|
|
|
|
|
// image2.DOFade(0, 0).SetDelay(0).OnComplete(() => {
|
2021-02-26 17:58:10 +08:00
|
|
|
|
image.color = new Color(image.color.r, image.color.g, image.color.b, 0);
|
|
|
|
|
image.DOFade(1, 1).OnComplete(() => {
|
|
|
|
|
image.DOFade(0, 1).SetDelay(2).OnComplete(() => {
|
|
|
|
|
DestroyImmediate(gameObj2);
|
|
|
|
|
if (bundle != null) bundle.Unload(true);
|
|
|
|
|
bundle = null;
|
2021-04-15 17:29:21 +08:00
|
|
|
|
StartCoroutine(StartGame());
|
2021-02-26 17:58:10 +08:00
|
|
|
|
//StartCoroutine(playMovice());
|
|
|
|
|
});
|
2020-08-22 15:31:14 +08:00
|
|
|
|
});
|
2021-06-03 17:46:38 +08:00
|
|
|
|
// });
|
|
|
|
|
//});
|
2021-02-26 17:58:10 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-15 17:29:21 +08:00
|
|
|
|
StartCoroutine(StartGame());
|
2021-02-26 17:58:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 13:31:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 17:29:21 +08:00
|
|
|
|
IEnumerator StartGame()
|
2021-02-26 17:58:10 +08:00
|
|
|
|
{
|
2021-04-15 17:29:21 +08:00
|
|
|
|
yield return App.Instance.Initialize();
|
2021-08-25 19:38:49 +08:00
|
|
|
|
// 初始化数数
|
|
|
|
|
App.TAMgr.Init();
|
2021-04-15 17:29:21 +08:00
|
|
|
|
//App.Instance.Initialize();
|
2021-02-26 17:58:10 +08:00
|
|
|
|
UpdateManager.Instance.StartUp();
|
|
|
|
|
}
|
2020-08-22 15:31:14 +08:00
|
|
|
|
//IEnumerator playMovice()
|
|
|
|
|
//{
|
|
|
|
|
// Handheld.PlayFullScreenMovie("PV_v5_0521_1.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput);
|
2020-05-09 13:31:21 +08:00
|
|
|
|
|
2020-08-22 15:31:14 +08:00
|
|
|
|
// yield return new WaitForEndOfFrame();
|
2020-05-09 13:31:21 +08:00
|
|
|
|
|
2020-08-22 15:31:14 +08:00
|
|
|
|
// App.Instance.Initialize();
|
|
|
|
|
// UpdateManager.Instance.StartUp();
|
|
|
|
|
//}
|
2021-08-25 19:38:49 +08:00
|
|
|
|
}
|