miduo_client/Assets/Scripts/GameInit/GameStart.cs

104 lines
3.3 KiB
C#
Raw Normal View History

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()
{
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();
}
}
}
}
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-02-26 17:58:10 +08:00
string path = AppConst.PersistentDataPath + "lz4/splashpanel.unity3d";
if (!File.Exists(path))
{
path = AppConst.StreamPath + "lz4/splashpanel.unity3d";
}
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>();
Image image2 = gameObj2.transform.Find("Canvas/image2").GetComponent<Image>();
2020-05-09 13:31:21 +08:00
2021-02-26 17:58:10 +08:00
image2.DOFade(1, 0).OnComplete(() => {
2021-06-03 13:52:55 +08:00
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
});
});
2020-05-09 13:31:21 +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();
//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();
//}
2020-05-09 13:31:21 +08:00
}