miduo_client/Assets/Scripts/GameInit/GameStart.cs

111 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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)
{
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 playSplash()
{
bool isShowSplash = true;
if (isShowSplash)
{
#if PLATFORM_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 = 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.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.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();
//}
}