Exemple #1
0
    public void EnablePanelLogo(bool enable)
    {
        if (PanelLogo == null)
        {
            return;
        }

        if (enable)
        {
            PanelLogo.SetActive(true);
        }
        else
        {
            GameObject.Destroy(PanelLogo);
            PanelLogo = null;
        }
    }
Exemple #2
0
    IEnumerable InitGameCoroutine()
    {
        DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine Start...");

        foreach (var item in PreInitGameCoroutine())
        {
            yield return(item);
        }

        SetupPath();

        HobaDebuger.GameLogLevel = WriteLogLevel;

        //IOS Application.persistentDataPath  /var/mobile/Containers/Data/Application/app sandbox/Documents
        //Android /storage/emulated/0/Android/data/package name/files
#if UNITY_IOS
        _DocPath = Application.persistentDataPath;
        _LibPath = Path.Combine(Application.persistentDataPath, "UpdateRes");
        _TmpPath = Path.Combine(Application.persistentDataPath, "Tmp");
#elif UNITY_ANDROID
        _DocPath = Application.persistentDataPath;
        _LibPath = Path.Combine(Application.persistentDataPath, "UpdateRes");
        _TmpPath = Path.Combine(Application.persistentDataPath, "Tmp");
#else
        _DocPath = Environment.CurrentDirectory;
        _LibPath = Path.Combine(Environment.CurrentDirectory, "UpdateRes");
        _TmpPath = Path.Combine(Environment.CurrentDirectory, "Tmp");
#endif
        yield return(null);

#if UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS
        //初始化异常上报SDK
        CLogReport.Init();
        yield return(null);
#endif

        //初始化基础目录
        {
            string path = EntryPoint.Instance.ResPath;
            path = path.Replace("file://", "");
            LuaDLL.HOBA_Init(path, _DocPath, _LibPath, _TmpPath);
        }

        _VoiceDir         = Path.Combine(_TmpPath, "Voice");
        _CustomPicDir     = Path.Combine(_TmpPath, "CustomPic");
        _UserLanguageFile = Path.Combine(_DocPath, "userlanguage.txt");
        _UserBillingFile  = Path.Combine(_DocPath, "userbilling.bin");
        _UserDataDir      = Path.Combine(_DocPath, "UserData");

        string strOSLanguage   = OSUtility.GetSystemLanguageCode();
        string strUserLanguage = GetUserLanguageCode();

        if (!Directory.Exists(_LibPath))
        {
            Directory.CreateDirectory(_LibPath);
        }
        if (!Directory.Exists(_VoiceDir))
        {
            Directory.CreateDirectory(_VoiceDir);
        }
        if (!Directory.Exists(_CustomPicDir))
        {
            Directory.CreateDirectory(_CustomPicDir);
        }
        if (!Directory.Exists(_UserDataDir))
        {
            Directory.CreateDirectory(_UserDataDir);
        }
        LuaDLL.HOBA_DeleteFilesInDirectory(_VoiceDir);               //清空Tmp目录
        LuaDLL.HOBA_DeleteFilesInDirectory(_CustomPicDir);           //清空Tmp目录
        yield return(null);

        if (!File.Exists(_UserLanguageFile))                //创建语言配置文件
        {
            WriteUserLanguageCode(strOSLanguage);
        }
        yield return(null);

        //目录信息
//#if (UNITY_EDITOR || UNITY_STANDALONE_WIN)
//         var pType = LTPlatformBase.ShareInstance().GetPlatformType();
//         HobaDebuger.LogWarningFormat("LTPlatformType: {0}", pType.ToString());
//         HobaDebuger.LogWarningFormat("AssetBundlePath: {0}", _AssetBundlePath);
//         HobaDebuger.LogWarningFormat("ResPath: {0}", ResPath);
//         HobaDebuger.LogWarningFormat("DocPath: {0}", _DocPath);
//         HobaDebuger.LogWarningFormat("LibPath: {0}", _LibPath);
//         HobaDebuger.LogWarningFormat("TmpPath: {0}", _TmpPath);
//         HobaDebuger.LogWarningFormat("ConfigPath: {0}", _ConfigPath);
//         HobaDebuger.LogWarningFormat("LuaPath: {0}", _LuaPath);
//         HobaDebuger.LogWarningFormat("VoiceDir: {0}", _VoiceDir);
//         HobaDebuger.LogWarningFormat("CustomPickDir: {0}", _CustomPicDir);
//         HobaDebuger.LogWarningFormat("OSLanguage: {0}, UserLanguage: {1}", strOSLanguage, strUserLanguage);
//         yield return null;
//#endif

        //根据语言设置更新语言
        ReadUpdateStringXmlFromResources(strUserLanguage);
        yield return(null);

#if (UNITY_EDITOR || UNITY_STANDALONE_WIN)               //只在windows下起作用
        bool bDebugSetting = ReadDebugSettingXml();
//         HobaDebuger.LogWarningFormat("DebugSetting: {0}", bDebugSetting);
//         HobaDebuger.LogWarningFormat("DebugSetting SkipUpdate: {0}, Shortcut: {1}, LocalData: {2}, LocalLua: {3}, Is1080P: {4}, FullScreen: {5}",
//             _DebugSetting.SkipUpdate,
//             _DebugSetting.ShortCut,
//             _DebugSetting.LocalData,
//             _DebugSetting.LocalLua,
//             _DebugSetting.Is1080P,
//             _DebugSetting.FullScreen);

        _SkipUpdate = _DebugSetting.SkipUpdate || File.Exists(Path.Combine(_DocPath, "skip.txt"));
        //HobaDebuger.LogWarningFormat("SkipUpdate: {0}", _SkipUpdate);
#endif

#if !UNITY_EDITOR && UNITY_STANDALONE_WIN
        if (_DebugSetting.Is1080P)
        {
            Screen.SetResolution(1920, 1080, _DebugSetting.FullScreen);
        }

        if (_DebugSetting.FPSLimit > 0)
        {
            Application.targetFrameRate = _DebugSetting.FPSLimit;
        }
#endif

        //初始化平台SDK
        {
            GameUpdateMan.Instance.InitUpdateUI(); //显示更新界面

            bool isFinish = false;
            int  code     = -1;
            LTPlatformBase.ShareInstance().InitSDK((_, resultCode) =>
            {
                code     = resultCode;
                isFinish = true;
            });
            LTPlatformBase.ShareInstance().SetBreakPoint(SDK.POINT_STATE.Game_Start); //平台SDK打点:开始游戏

            while (!isFinish)
            {
                yield return(null);
            }

            bool isInited = LTPlatformBase.ShareInstance().IsInited;
            var  pType    = LTPlatformBase.ShareInstance().GetPlatformType();
            DeviceLogger.Instance.WriteLogFormat("LTPlatform InitSDK result:{0}, return code:{1}, platform type:{2}", isInited.ToString(), code.ToString(), pType.ToString());
            if (!isInited)
            {
                // 初始化失败,弹窗提示,退出游戏
                GameUpdateMan.Instance.HotUpdateViewer.SetCircle(false);
                string errStr = LTPlatformBase.ShareInstance().GetErrStr(code);
                yield return(new WaitForUserClick(MessageBoxStyle.MB_OK, errStr, _UpdateStringConfigParams.PlatformSDKString_InitFailedTitle));

                ExitGame();
                yield break;
            }
        }

        {
            // copy base res
#if UNITY_ANDROID
            string srcDir  = "res_base";
            string destDir = Path.Combine(Application.persistentDataPath, "res_base");

            if (!Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }

            IsInstallFinished = File.Exists(destDir + "/.lock");
            if (!IsInstallFinished)
            {
                DeviceLogger.Instance.WriteLog(string.Format("Begin RunInstallStage... from {0} to {1}", srcDir, destDir));
                foreach (var item in GameUpdateMan.Instance.RunInstallStage(srcDir, destDir))
                {
                    yield return(item);
                }
                DeviceLogger.Instance.WriteLog("End RunInstallStage...");
            }

            if (IsInstallFinished)
            {
                string       lockFile = Path.Combine(destDir, ".lock");
                StreamWriter writer   = File.CreateText(lockFile);
                writer.Write(TotalSizeToCopy);
                writer.Close();
                DeviceLogger.Instance.WriteLog("EntryPoint InitGameCoroutine EntryPoint.Instance.RunInstallStage() Success...");
            }
            else
            {
                DeviceLogger.Instance.WriteLog("EntryPoint InitGameCoroutine EntryPoint.Instance.RunInstallStage() Failed!");
            }
            yield return(null);
#endif
            //在更新开始前,获取ServerConfig.xml
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
            {
                string configsDir = Path.Combine(_ResPath, "Configs");
                string path       = Path.Combine(configsDir, "ServerConfig.xml");
                if (!ReadServerConfigXml(path))
                {
                    HobaDebuger.LogWarningFormat("Read ServerConfig Failed: {0}", path);
                }
            }
#else
            {
                string url     = EntryPoint.Instance.GetClientServerUrl().NormalizeDir() + "ServerConfig.xml";
                string tmpPath = Path.Combine(EntryPoint.Instance.TmpPath, "ServerConfig.xml");
                string errMsg;
                var    code = Patcher.FetchByUrl(url, tmpPath, Downloader.DownloadMan.reqTimeOut, out errMsg);
                if (code == Downloader.DownloadTaskErrorCode.Success)
                {
                    if (!ReadServerConfigXml(tmpPath))
                    {
                        HobaDebuger.LogWarningFormat("Read ServerConfig Failed: {0}", url);
                    }
                }
                else
                {
                    HobaDebuger.LogWarningFormat("Download ServerConfig Failed: {0}, {1}", url, code);
                }
            }
#endif
            yield return(null);

            DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine UpdateRoutine Start...");
            //IAP Verify url init and check receipt cache.
            LTPlatformBase.ShareInstance().InitPurchaseVerifyUrl(_ServerConfigParams.GetPurchaseVerifyUrl());
            LTPlatformBase.ShareInstance().ProcessPurchaseCache();
            LTPlatformBase.ShareInstance().SetBreakPoint(SDK.POINT_STATE.Game_Start_Update); //平台SDK打点:开始更新

            // App & 资源更新
            foreach (var item in GameUpdateMan.Instance.UpdateRoutine())
            {
                yield return(item);
            }
            LTPlatformBase.ShareInstance().SetBreakPoint(SDK.POINT_STATE.Game_End_Update); //平台SDK打点:结束更新

            DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine UpdateRoutine End...");
        }

        //初始化pck包, 编辑器模式下不使用pck,策划编辑器模式下使用
#if !UNITY_EDITOR
        {
            string path = _ResPath;
            path = path.Replace("file://", "");
            LuaDLL.HOBA_InitPackages(path);
        }
#endif
        //FIX ME:: 加载不等待2帧 Windows崩溃 待查
        yield return(null);  //等待一帧,否则部分 Android 设置闪烁

        yield return(null);  //等待一帧,否则部分 Android 设置闪烁

        ReadGameCustomConfigParams();
        yield return(null);

        ReadWwiseBankConfigParams();
        yield return(null);

        ReadWwiseSoundConfigParams();
        yield return(null);

        ReadPlayerFollowCameraConfig();
        yield return(null);

        CLogFile.Init();
        yield return(null);

        CGameSession.Instance().PingInterval              = GameCustomConfigParams.PingInterval;
        CGameSession.Instance().MaxProcessProtocol        = GameCustomConfigParams.MaxProcessProtocol;
        CGameSession.Instance().MaxProcessSpecialProtocol = GameCustomConfigParams.MaxProcessSpecialProtocol;

        foreach (var item in InitGameInternal())
        {
            yield return(item);
        }

        CleanupUpdateResources();

        if (PanelLogo != null)
        {
            PanelLogo.SetActive(true);
            yield return(null);
        }

        string videoPath = System.IO.Path.Combine(Application.streamingAssetsPath, "TERA_BackgroundStory.mp4");
        VideoManager.PlayVideo(videoPath, null, null, null, true);
        yield return(null);

        GFXConfig.Instance.Init();

        foreach (var item in DoStartGame())
        {
            yield return(item);
        }

        //DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine DoStartGame End...");

        DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine End...");

        //TestLoadResource("Assets/Outputs/Sfx/Scene/scene_chuansong_chuanzou01.prefab");
    }
Exemple #3
0
    void Start()
    {
#if UNITY_IPHONE || UNITY_ANDROID
        _WriteLogLevel = LogLevel.Warning;
#endif

#if AssetsUnloadTest
        //test "Assets/Outputs/Scenes/SelectChar.prefab"
        SetupPath();
        CAssetBundleManager.Instance.Init(_ResPath, _AssetBundlePath);
        return;
#endif

        /*
         * {
         *  UnityEngine.Transform component = this.gameObject.transform;
         *  System.Reflection.PropertyInfo propertyInfo = CinemaSuite.Common.ReflectionHelper.GetProperty(typeof(UnityEngine.Transform), "localPosition");
         *  object value = propertyInfo.GetValue(component, null);
         *  //System.Reflection.MethodInfo mi = propertyInfo.GetGetMethod();
         *  //object value = mi.Invoke(component, null);
         * }
         * */
        /*
         * {
         *  GameObject obj = new GameObject("test1");
         *  Quaternion q = Quaternion.Euler(new Vector3(271.31f, 158.38f, 34.74f));
         *  Vector3 dir = q * Vector3.forward;
         *
         *  obj.transform.forward = dir;
         * }
         * */

        {
            GameObject go = GameObject.Find("UICamera");
            if (go != null)
            {
                Main.UICamera = go.GetComponent <Camera>();
            }
            go = GameObject.Find("UIRootCanvas");
            if (go != null)
            {
                Main.UIRootCanvas = go.transform;
                Main.PanelRoot    = go.transform.Find("PanelRoot");
                Main.PanelHUD     = go.transform.Find("Panel_HUD");
            }
            go = GameObject.Find("TopPateCanvas");
            {
                Main.TopPateCanvas = go.transform;
            }
            Main.BlockCanvas = Main.UIRootCanvas.Find("PanelRoot/BlockCanvas");
            Main.EnableBlockCanvas(false);
        }

        DeviceLogger.Instance.WriteLogFormat("EntryPoint Start Begin...");

        GFXConfig.CreateGFXConfig();

        // 隐藏FPS
        var transFPS = Main.UIRootCanvas.Find("Panel_FPS");
        if (transFPS != null)
        {
            _PanelFPS = transFPS.gameObject;
            _PanelFPS.SetActive(false);
        }

        //游戏Logo
        if (PanelLogo != null)
        {
            PanelLogo.SetActive(false);
        }

        //更新界面   _PanelUpdate 在 UpdateRoutine() 中控制显隐
        {
            UnityEngine.Object panelHotUpdate = Resources.Load("UI/Panel_HotUpdate", typeof(GameObject));
            if (panelHotUpdate != null)
            {
                PanelHotUpdate = Instantiate(panelHotUpdate) as GameObject;
                PanelHotUpdate.transform.SetParent(Main.PanelRoot);
                RectTransform rcTransform = PanelHotUpdate.GetComponent <RectTransform>();
                rcTransform.offsetMin               = Vector2.zero;
                rcTransform.offsetMax               = Vector2.zero;
                rcTransform.anchoredPosition3D      = Vector3.zero;
                PanelHotUpdate.transform.localScale = Vector3.one;
                {
                    // TODO:加载更新图上的Tip和背景图更换
                }
                PanelHotUpdate.SetActive(false);
            }
            else
            {
                DeviceLogger.Instance.WriteLog("Failed to Load Panel_HotUpdate!");
            }
        }

        //Splash界面
        {
            UnityEngine.Object panelSplash = Resources.Load("UI/Panel_Splash", typeof(GameObject));
            if (panelSplash != null)
            {
                _PanelSplash = Instantiate(panelSplash) as GameObject;
                _PanelSplash.transform.SetParent(Main.PanelRoot);
                //GameObject img = _PanelSplash.FindChild("Img_Splash");
                RectTransform rcTransform = _PanelSplash.GetComponent <RectTransform>();
                rcTransform.offsetMin             = Vector2.zero;
                rcTransform.offsetMax             = Vector2.zero;
                rcTransform.anchoredPosition3D    = Vector3.zero;
                _PanelSplash.transform.localScale = Vector3.one;

                _PanelSplash.SetActive(false);
            }
            else
            {
                DeviceLogger.Instance.WriteLog("Failed to Load Panel_Splash!");
            }
        }

        //游戏忠告界面
        {
            UnityEngine.Object panelMonition = Resources.Load("UI/Panel_Monition", typeof(GameObject));
            if (panelMonition != null)
            {
                _PanelMonition = Instantiate(panelMonition) as GameObject;
                _PanelMonition.transform.SetParent(Main.PanelRoot, false);
                //RectTransform rcTransform = _PanelMonition.GetComponent<RectTransform>();
                //rcTransform.offsetMin = Vector2.zero;
                //rcTransform.offsetMax = Vector2.zero;
                //rcTransform.anchoredPosition3D = Vector3.zero;
                //_PanelMonition.transform.localScale = Vector3.one;

                _PanelMonition.SetActive(false);
            }
            else
            {
                DeviceLogger.Instance.WriteLog("Failed to Load Panel_Monition!");
            }
        }

        try
        {
            _IsCurlInited = (CURLcode.CURLE_OK == Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL));
            if (!_IsCurlInited)
            {
                DeviceLogger.Instance.WriteLogFormat("Curl Init Failed: Curl.GlobalInit");
            }
            else
            {
                DeviceLogger.Instance.WriteLogFormat("Curl Init Succeed: {0}", Curl.Version);
            }
        }
        catch (Exception e)
        {
            DeviceLogger.Instance.WriteLogFormat("Curl Init Failed: {0}", e.Message);
        }

        StartCoroutine(InitGameCoroutine().GetEnumerator());
        DeviceLogger.Instance.WriteLogFormat("EntryPoint Start End...");
    }