miduo_client/Assets/Scripts/GameInit/GameStart.cs

128 lines
4.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()
{
2021-01-26 17:08:39 +08:00
//PlayerPrefs.DeleteKey("language");
if (!PlayerPrefs.HasKey("language"))
{
if (Application.systemLanguage == SystemLanguage.Chinese || Application.systemLanguage == SystemLanguage.ChineseSimplified || Application.systemLanguage == SystemLanguage.ChineseTraditional)
{
PlayerPrefs.SetInt("language", 0);
}
2021-02-18 17:21:14 +08:00
else if (Application.systemLanguage == SystemLanguage.Vietnamese)
{
PlayerPrefs.SetInt("language", 2);
}
2021-01-26 17:08:39 +08:00
else
{
PlayerPrefs.SetInt("language", 1);
}
}
else if(PlayerPrefs.HasKey("language_flag")&& PlayerPrefs.GetInt("language")!= PlayerPrefs.GetInt("language_flag"))
{
PlayerPrefs.SetInt("language", PlayerPrefs.GetInt("language_flag"));
}
if (!PlayerPrefs.HasKey("language_flag"))
{
PlayerPrefs.SetInt("language_flag", PlayerPrefs.GetInt("language"));
}
2021-02-18 17:21:14 +08:00
string languageStr = "";
if (PlayerPrefs.GetInt("language") == 0)
{
languageStr = "中文";
}
else if (PlayerPrefs.GetInt("language") == 1)
{
languageStr = "英文";
}
else
{
languageStr = "越南语";
}
2021-01-26 17:08:39 +08:00
Debug.Log("当前语言是:" + languageStr);
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)
{
App.Instance.Initialize();
UpdateManager.Instance.StartUp();
}
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()
{
string path = AppConst.PersistentDataPath + "lz4/splashpanel.unity3d";
if (!File.Exists(path))
{
path = AppConst.StreamPath + "lz4/splashpanel.unity3d";
}
2020-08-22 15:31:14 +08:00
bundle = AssetBundle.LoadFromFile(path, 0, GameLogic.AppConst.EncyptBytesLength);
2020-05-09 13:31:21 +08:00
GameObject gameObj = bundle.LoadAsset<GameObject>("SplashPanel");
GameObject gameObj2 = Instantiate(gameObj, Vector3.zero, Quaternion.identity);
Image image = gameObj2.transform.Find("Canvas/image").GetComponent<Image>();
2020-08-22 15:31:14 +08:00
Image image2 = gameObj2.transform.Find("Canvas/image2").GetComponent<Image>();
2020-05-09 13:31:21 +08:00
2020-08-22 15:31:14 +08:00
image2.DOFade(1, 0).OnComplete(() =>{
2020-08-27 19:18:31 +08:00
image2.DOFade(0, 0).SetDelay(2).OnComplete(() =>{
2020-08-22 15:31:14 +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;
App.Instance.Initialize();
UpdateManager.Instance.StartUp();
//StartCoroutine(playMovice());
});
});
2020-05-09 13:31:21 +08:00
});
});
}
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
}