138 lines
4.4 KiB
C#
138 lines
4.4 KiB
C#
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()
|
||
{
|
||
// 判断是否是覆盖安装了包,是就清除缓存
|
||
ClearCach();
|
||
// 开始启动游戏
|
||
if (Application.isEditor && AppConst.bundleMode && AppConst.isUpdate)
|
||
{
|
||
if (!System.IO.Directory.Exists(Util.AppContentPath()))
|
||
{
|
||
XDebug.Log.error("还未打包平台资源,移放到StreamAssets目录");
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (Application.isEditor)
|
||
{
|
||
StartCoroutine(StartGame());
|
||
//playSplash();
|
||
}
|
||
else
|
||
{
|
||
if (AppConst.bundleMode) //先走闪屏流程
|
||
{
|
||
if (AppConst.isSDKLogin && !SDK.SDKManager.Instance.IsInit) //当登录sdk时,等待初始化完成后再走闪屏流程
|
||
{
|
||
SDK.SDKManager.Instance.Initialize();
|
||
SDK.SDKManager.Instance.onInitLaunchCallback += s => {
|
||
playSplash();
|
||
};
|
||
}
|
||
else
|
||
{
|
||
playSplash();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//请本地缓存
|
||
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
|
||
}
|
||
|
||
void playSplash()
|
||
{
|
||
bool isShowSplash = true;
|
||
if (isShowSplash)
|
||
{
|
||
#if UNITY_IOS
|
||
string splashFilePath = "lz4_splashpanel.unity3d";
|
||
#else
|
||
string splashFilePath = "lz4/splashpanel.unity3d";
|
||
#endif
|
||
|
||
string path = AppConst.PersistentDataPath + splashFilePath;
|
||
if (!File.Exists(path))
|
||
{
|
||
path = AppConst.StreamPath + splashFilePath;
|
||
}
|
||
bundle = MEncyptUtil.LoadAssetBundle(path, AppConst.EncyptKey, 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>();
|
||
image.transform.localScale = Vector3.one * 0.9f;
|
||
//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(() => {
|
||
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;
|
||
StartCoroutine(StartGame());
|
||
//StartCoroutine(playMovice());
|
||
});
|
||
});
|
||
// });
|
||
//});
|
||
}
|
||
else
|
||
{
|
||
StartCoroutine(StartGame());
|
||
}
|
||
|
||
}
|
||
|
||
IEnumerator StartGame()
|
||
{
|
||
yield return App.Instance.Initialize();
|
||
// 初始化数数
|
||
App.TAMgr.Init();
|
||
//App.Instance.Initialize();
|
||
UpdateManager.Instance.StartUp();
|
||
}
|
||
//IEnumerator playMovice()
|
||
//{
|
||
// Handheld.PlayFullScreenMovie("PV_v5_0521_1.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput);
|
||
|
||
// yield return new WaitForEndOfFrame();
|
||
|
||
// App.Instance.Initialize();
|
||
// UpdateManager.Instance.StartUp();
|
||
//}
|
||
} |