コード例 #1
0
ファイル: FileLogger.cs プロジェクト: randomize/ProjectAct
        public FileLogger()
        {
            var logDir = UGCoreConfig.GetExternalLogFolder();

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

            m_LogFilePath = Path.Combine(logDir, String.Format(m_LogFileName, DateTime.Today.ToString("yyyy_MM_dd")));
            try
            {
                m_FileStream   = new FileStream(m_LogFilePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                m_StreamWriter = new StreamWriter(m_FileStream);

                if (m_LogThread == null)
                {
                    m_LogThread = new Thread(WriteLogHandler);
                    m_LogThread.Start();
                }
                m_InitSuccess = true;
            }
            catch (Exception ex)
            {
                m_InitSuccess = false;
                Debug.LogError("init file error:" + ex.Message);
            }
        }
コード例 #2
0
        public override IEnumerator CheckVersion()
        {
            var progressDelta = 1 / 5f;

            m_ShowTipCoroutine = GameCore.Instance.StartCoroutine(ShowCheckTip());

            //1 先检查本地版本信息,执行相关清理操作
            m_CoroutineWorkflow.AddLast("CheckLocalVersionInfo", CheckLocalVersionInfo);
            LoadingUI.Instance.SetLoadingBarProgressDelta(progressDelta);

            //2 检查远程配置信息
            m_CoroutineWorkflow.AddLast("CheckRemoteConfig", CheckRemoteConfig);
            LoadingUI.Instance.SetLoadingBarProgressDelta(progressDelta);

            //3 加载远程配置信息
            m_CoroutineWorkflow.AddLast("LoadRemoteControlConfig", LoadRemoteControlConfig);
            LoadingUI.Instance.SetLoadingBarProgressDelta(progressDelta);

            //4 检查Apk下载
            m_CoroutineWorkflow.AddLast("CheckProgramVersion", CheckProgramVersion);
            LoadingUI.Instance.SetLoadingBarProgressDelta(progressDelta);

            //5 检查资源版本
            m_CoroutineWorkflow.AddLast("CheckResourceVersion", CheckResourceVersion);
            LoadingUI.Instance.SetLoadingBarProgressDelta(progressDelta);

            yield return(GameCore.Instance.StartCoroutine(m_CoroutineWorkflow.ExecuteTasksAsync()));

            GameCore.Instance.StopCoroutine(m_ShowTipCoroutine);
            FileSystemUtility.ClearDirectory(UGCoreConfig.GetExternalDownloadFolder() + "/Patches");
            FileSystemUtility.ClearDirectory(UGCoreConfig.GetExternalDownloadFolder() + "/Apk");
            LoadingUI.Instance.SetLoadingBarProgressDelta(0.04f);
        }
コード例 #3
0
        private Object LoadAssetsSync()
        {
            Object asset = null;

            for (int i = 0; i < m_AssetLoadOrder.Count; ++i)
            {
                var assetName = m_AssetLoadOrder[i];
                if (AssetManager.Instance.ContainAsset(assetName))
                {
                    continue;
                }

                var assetBundlePath = m_AssetDependences[assetName].AssetBundlePath;
                var assetBundle     = m_AssetBundleCollector.GetAssetBundle(assetBundlePath);
                if (assetBundle != null)
                {
                    asset = assetBundle.LoadAsset(assetName);
                    m_AssetLoadDoneEvent(assetName, asset);
                    m_AssetBundleCollector.AddAssetBundleReference(assetName, assetBundlePath);
                    continue;
                }

                var www = new WWW(UGCoreConfig.GetAssetBundlePath(assetBundlePath));
                assetBundle = www.assetBundle;
                asset       = www.assetBundle.LoadAsset(assetName);
                m_AssetLoadDoneEvent(assetName, asset);
                m_AssetBundleCollector.AddAssetBundle(assetBundlePath, assetBundle);
                m_AssetBundleCollector.AddAssetBundleReference(assetName, assetBundlePath);
            }
            return(asset);
        }
コード例 #4
0
        public override IEnumerator LoadModuleAsync()
        {
            if (UseAssetBundle)
            {
                var www = new WWW(UGCoreConfig.GetAssetBundlePath("AssetsDependences.pkg"));
                yield return(www);

                var assetbundleRequest = www.assetBundle.LoadAssetAsync("Assets/Resources/AssetsDependences", typeof(Object));
                yield return(assetbundleRequest);

                var assetDependences = assetbundleRequest.asset as TextAsset;
                if (assetDependences != null)
                {
                    AssetBundleManager.InitializeAssetManager(assetDependences.bytes);
                }
                else
                {
                    Debug.LogError("Dont have asset dependences config");
                }

                www.assetBundle.Unload(true);
            }
            else
            {
                ResourcesAssetManager.InitializeAssetManager();
            }

            TimerHelper.AddTimer((uint)AssetLoadConfig.CheckAssetReferenceDeltaTime, AssetLoadConfig.CheckAssetReferenceDeltaTime, AssetManager.Instance.CheckExpiredAssets);
            LoadingUI.Instance.SetLoadingBarProgressDelta(1);
        }
コード例 #5
0
        protected IEnumerator DownloadPatches()
        {
            m_VersionCheckState = VersionCheckState.DownloadingPatch;
            for (int i = m_HasDownloadDoneCount; i < m_PatchKeyList.Count; ++i)
            {
                var result           = 0;
                var downloadProgress = 0f;
                var url         = m_PatchesMap[m_PatchKeyList[i]].PatchPath;
                var downloadDir = UGCoreConfig.GetExternalDownloadFolder() + "/Patches";
                var localPath   = Path.Combine(downloadDir, m_PatchKeyList[i]);
                if (!Directory.Exists(downloadDir))
                {
                    Directory.CreateDirectory(downloadDir);
                }

                LoadingUI.Instance.ShowLoadingTip(string.Format(LoadingLanguageData.Instance.GetString(14), (i + 1), m_PatchKeyList.Count, 0));
                LoadingUI.Instance.PushLoadTaskProgressDelta(1);
                LoadingUI.Instance.SetLoadingBarProgress(0);
                HttpDownloadUtility.DownloadFileAsync(url, localPath, (progress) =>
                {
                    downloadProgress = progress;
                },
                                                      () =>
                {
                    ++m_HasDownloadDoneCount;
                    result = 1;
                },
                                                      () =>
                {
                    result = 2;
                });

                while (result == 0)
                {
                    LoadingUI.Instance.ShowLoadingTip(string.Format(LoadingLanguageData.Instance.GetString(14), (i + 1),
                                                                    m_PatchKeyList.Count, (int)downloadProgress));
                    LoadingUI.Instance.SetLoadingBarProgress(downloadProgress * 0.01f);
                    yield return(null);
                }

                if (result == 1)
                {
                    LoadingUI.Instance.ShowLoadingTip(string.Format(LoadingLanguageData.Instance.GetString(14), (i + 1),
                                                                    m_PatchKeyList.Count, 100));
                    LoadingUI.Instance.SetLoadingBarProgress(1);
                    LoadingUI.Instance.PopLoadTaskProgressDelta();
                }
                else if (result == 2)
                {
                    m_CoroutineWorkflow.AddFirst("ShowDownlaodPatchesError", ShowDownlaodPatchesError);
                    yield break;
                }
                yield return(null);
            }

            m_HasDownloadDoneCount = 0;
            m_CoroutineWorkflow.AddFirst("UncompressPatches", UncompressPatches);
        }
コード例 #6
0
        protected IEnumerator UncompressPatches()
        {
            m_VersionCheckState = VersionCheckState.UncompressPatch;

            for (int i = m_HasDownloadDoneCount; i < m_PatchKeyList.Count; ++i)
            {
                var result           = 0;
                var downloadProgress = 0f;
                var localPath        = Path.Combine(UGCoreConfig.GetExternalDownloadFolder() + "/Patches", m_PatchKeyList[i]);

                LoadingUI.Instance.ShowLoadingTip(string.Format(LoadingLanguageData.Instance.GetString(16), (i + 1), m_PatchKeyList.Count, 0));
                LoadingUI.Instance.PushLoadTaskProgressDelta(1);
                LoadingUI.Instance.SetLoadingBarProgress(0);

                ZipUtility.UnzipDirectoryAsync(localPath, UGCoreConfig.GetExternalResourceFolder(),
                                               (progress) =>
                {
                    downloadProgress = progress;
                },
                                               () =>
                {
                    ++m_HasDownloadDoneCount;
                    result = 1;
                },
                                               () =>
                {
                    result = 2;
                });

                while (result == 0)
                {
                    LoadingUI.Instance.ShowLoadingTip(string.Format(LoadingLanguageData.Instance.GetString(16), (i + 1),
                                                                    m_PatchKeyList.Count, (int)downloadProgress));
                    LoadingUI.Instance.SetLoadingBarProgress(downloadProgress * 0.01f);
                    yield return(null);
                }

                if (result == 1)
                {
                    LoadingUI.Instance.ShowLoadingTip(string.Format(LoadingLanguageData.Instance.GetString(16), (i + 1),
                                                                    m_PatchKeyList.Count, 100));
                    LoadingUI.Instance.SetLoadingBarProgress(1);
                    LoadingUI.Instance.PopLoadTaskProgressDelta();
                }
                else if (result == 2)
                {
                    m_CoroutineWorkflow.AddFirst("ShowUncompressPatchesError", ShowUncompressPatchesError);
                    yield break;
                }
                yield return(null);
            }

            //保存资源版本号
            GameRuntimeInfo.ResourceVersion = GameRuntimeInfo.RemoteControlConfig.ResourceVersion;
            SaveVersionInfo(GameRuntimeInfo.ProgramVersion, GameRuntimeInfo.ResourceVersion, false);
        }
コード例 #7
0
        protected IEnumerator DownloadApk()
        {
            var result           = 0;
            var downloadProgress = 0f;
            var apkDir           = UGCoreConfig.GetExternalDownloadFolder() + "/Apk/";
            var apkPath          = apkDir + Path.GetFileName(GameRuntimeInfo.RemoteControlConfig.ApkInfo.ApkPath);

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

            LoadingUI.Instance.ShowLoadingTip(string.Format(LoadingLanguageData.Instance.GetString(23), 0));
            LoadingUI.Instance.PushLoadTaskProgressDelta(1);
            LoadingUI.Instance.SetLoadingBarProgress(0);
            HttpDownloadUtility.DownloadFileAsync(GameRuntimeInfo.RemoteControlConfig.ApkInfo.ApkPath, apkPath,
                                                  (progress) =>
            {
                downloadProgress = progress;
            },
                                                  () =>
            {
                result = 1;
            },
                                                  () =>
            {
                result = 2;
            });

            while (result == 0)
            {
                LoadingUI.Instance.ShowLoadingTip(string.Format(LoadingLanguageData.Instance.GetString(23), (int)downloadProgress));
                LoadingUI.Instance.SetLoadingBarProgress(downloadProgress * 0.01f);
                yield return(null);
            }

            if (result == 1)
            {
                LoadingUI.Instance.ShowLoadingTip(string.Format(LoadingLanguageData.Instance.GetString(23), 100));
                LoadingUI.Instance.SetLoadingBarProgress(1);
                LoadingUI.Instance.PopLoadTaskProgressDelta();

                AndroidUtility.InstallApk(apkPath, true);
            }
            else if (result == 2)
            {
                m_CoroutineWorkflow.AddFirst("DownloadApkError", DownloadApkError);
                yield break;
            }
            yield return(null);
        }
コード例 #8
0
        protected void SaveVersionInfo(string programVersion, string resourceVersion, bool needClearResources = true)
        {
            GameRuntimeInfo.ProgramVersion  = programVersion;
            GameRuntimeInfo.ResourceVersion = resourceVersion;

            var programData  = Encoding.UTF8.GetBytes(programVersion);
            var resourceData = Encoding.UTF8.GetBytes(resourceVersion);

            var data = new byte[programData.Length + resourceData.Length + 1];

            for (int i = 0; i < programData.Length; i++)
            {
                data[i] = programData[i];
            }
            data[programData.Length] = 0;
            for (int i = 0; i < resourceData.Length; i++)
            {
                data[programData.Length + i + 1] = resourceData[i];
            }

            var versionFileDir  = UGCoreConfig.GetExternalConfigFolder();
            var versionFilePath = Path.Combine(versionFileDir, "Version.config");

            if (!Directory.Exists(versionFileDir))
            {
                Directory.CreateDirectory(versionFileDir);
            }
            StreamWriter sw = new StreamWriter(new FileStream(versionFilePath, FileMode.Create));

            sw.Write(Convert.ToBase64String(data));
            sw.Flush();
            sw.Close();

            if (needClearResources)
            {
                FileSystemUtility.ClearDirectory(UGCoreConfig.GetExternalResourceFolder());
            }
        }
コード例 #9
0
        protected IEnumerator LoadRuntimeScripts()
        {
            var www = new WWW(UGCoreConfig.GetAssetBundlePath("RuntimeScripts.pkg"));

            yield return(www);

            if (www.error != null)
            {
                Debug.LogError("ScriptsLoadModule - load runtime scripts error : " + www.error);
                m_CoroutineWorkflow.AddFirst("ShowLoadRumtimeScriptsError", ShowLoadRumtimeScriptsError);
            }
            else
            {
                var assetBundleRequest = www.assetBundle.LoadAssetAsync("Assets/Resources/RuntimeScripts", typeof(UnityEngine.Object));
                yield return(assetBundleRequest);

                try
                {
                    var assembly = System.Reflection.Assembly.Load((assetBundleRequest.asset as TextAsset).bytes);
                    var logicModuleLoaderType = assembly.GetType("GameLogic.LogicCore.LogicModuleLoader");
                    if (logicModuleLoaderType != null)
                    {
                        GameCore.Instance.gameObject.AddComponent(logicModuleLoaderType);
                    }
                    else
                    {
                        Debug.LogError("ScriptsLoadModule - logicModuleLoaderType is null");
                        m_CoroutineWorkflow.AddFirst("ShowLoadRumtimeScriptsError", ShowLoadRumtimeScriptsError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("criptsLoadModule - load runtime scripts error : " + e);
                    m_CoroutineWorkflow.AddFirst("ShowLoadRumtimeScriptsError", ShowLoadRumtimeScriptsError);
                }
            }
        }
コード例 #10
0
        protected void LoadVersionInfo()
        {
            var versionFilePath = Path.Combine(UGCoreConfig.GetExternalConfigFolder(), "Version.config");

            if (!File.Exists(versionFilePath))
            {
                GameRuntimeInfo.ProgramVersion  = "";
                GameRuntimeInfo.ResourceVersion = "";
                return;
            }

            var versionText = File.ReadAllText(versionFilePath);

            try
            {
                var versionData = Convert.FromBase64String(versionText);
                var startIndex  = 0;
                var endIndex    = 0;
                for (int i = 0; i < versionData.Length; ++i)
                {
                    if (versionData[i] == 0)
                    {
                        endIndex = i;
                        break;
                    }
                }

                GameRuntimeInfo.ProgramVersion  = Encoding.UTF8.GetString(versionData, startIndex, endIndex);
                GameRuntimeInfo.ResourceVersion = Encoding.UTF8.GetString(versionData, endIndex + 1, versionData.Length - endIndex - 1);
            }
            catch (Exception e)
            {
                Debug.LogError("version control - parse local version info error :" + e);
                GameRuntimeInfo.ProgramVersion  = "";
                GameRuntimeInfo.ResourceVersion = "";
            }
        }
コード例 #11
0
        IEnumerator LoadAsset(string assetName)
        {
            GetAssetDependencesForAysnc(assetName);
            Object asset = null;

            var progress = 0f;
            var count    = m_AssetAsyncLoadOrder.Count;

            for (int i = 0; i < count; ++i)
            {
                var loadAssetName = m_AssetAsyncLoadOrder[i];
                asset = AssetManager.Instance.ContainAsset(loadAssetName);
                if (asset != null)
                {
                    continue;
                }

                var assetBundlePath = m_AssetDependences[loadAssetName].AssetBundlePath;
                var assetBundle     = m_AssetBundleCollector.GetAssetBundle(assetBundlePath);
                AssetBundleRequest assetbundleRequest = null;
                if (assetBundle != null)
                {
                    if (m_CurrentLoadTask.HasProgressCallback)
                    {
                        var deltaProgress = 1f / count;
                        assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object));
                        while (!assetbundleRequest.isDone)
                        {
                            var tempProgress = progress + deltaProgress * assetbundleRequest.progress;
                            m_CurrentLoadTask.SafeInvokeAllProgressCallback(tempProgress);
                            yield return(null);
                        }

                        progress += deltaProgress;
                        m_CurrentLoadTask.SafeInvokeAllProgressCallback(progress);
                    }
                    else
                    {
                        assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object));
                        yield return(assetbundleRequest);
                    }

                    asset = assetbundleRequest.asset;
                    m_AssetLoadDoneEvent(loadAssetName, asset);
                    m_AssetBundleCollector.AddAssetBundleReference(loadAssetName, assetBundlePath);
                    continue;
                }

                WWW www = null;
                if (m_CurrentLoadTask.HasProgressCallback)
                {
                    var deltaProgress = 1f / count;
                    www = new WWW(UGCoreConfig.GetAssetBundlePath(assetBundlePath));
                    while (!www.isDone)
                    {
                        var tempProgress = progress + deltaProgress * 0.5f * www.progress;
                        m_CurrentLoadTask.SafeInvokeAllProgressCallback(tempProgress);
                        yield return(null);
                    }

                    assetBundle = m_AssetBundleCollector.GetAssetBundle(assetBundlePath);
                    if (assetBundle == null)
                    {
                        assetBundle = www.assetBundle;
                    }
                    assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object));

                    while (!assetbundleRequest.isDone)
                    {
                        var tempProgress = progress + deltaProgress * 0.5f * (1 + assetbundleRequest.progress);
                        m_CurrentLoadTask.SafeInvokeAllProgressCallback(tempProgress);
                        yield return(null);
                    }

                    progress += deltaProgress;
                    m_CurrentLoadTask.SafeInvokeAllProgressCallback(progress);
                }
                else
                {
                    www = new WWW(UGCoreConfig.GetAssetBundlePath(assetBundlePath));
                    yield return(www);

                    assetBundle = m_AssetBundleCollector.GetAssetBundle(assetBundlePath);
                    if (assetBundle == null)
                    {
                        assetBundle = www.assetBundle;
                    }
                    assetbundleRequest = assetBundle.LoadAssetAsync(loadAssetName, typeof(Object));
                    yield return(assetbundleRequest);
                }

                asset = assetbundleRequest.asset;
                m_AssetLoadDoneEvent(loadAssetName, asset);

                m_AssetBundleCollector.AddAssetBundle(assetBundlePath, assetBundle);
                m_AssetBundleCollector.AddAssetBundleReference(loadAssetName, assetBundlePath);
            }

            m_AssetLoadDoneEvent.Invoke(assetName, asset);
            m_CurrentLoadTask.SafeInvokeAllCallback(asset);

            AssetLoadTask.ReleaseAssetLoadTask(m_CurrentLoadTask);
            m_CurrentLoadTask = PopAssetLoadTask();

            while (m_CurrentLoadTask != null)
            {
                asset = AssetManager.Instance.ContainAsset(m_CurrentLoadTask.AssetName);
                if (asset == null)
                {
                    break;
                }

                m_CurrentLoadTask.SafeInvokeAllCallback(asset);
                m_CurrentLoadTask = PopAssetLoadTask();
            }

            if (m_CurrentLoadTask != null)
            {
                StartLoadAsset();
            }
        }
コード例 #12
0
 public override IEnumerator LoadModuleAsync()
 {
     LocalStorage.LoadLocalStorage(UGCoreConfig.GetExternalConfigFolder() + GameLogicConfig.LocalStorageFileName, mLocalStorageDefaultData);
     yield break;
 }