Exemplo n.º 1
0
    public void Initialize(Action onComplete)
    {
        if (onComplete != null)
        {
            onStartupFunc = onComplete;
        }

        //取消 Destroy 对象

        InitConsole();
        InitUIRoot();
        InitResolution();

        //平台初始化
        AppPlatform.Initialize();

        //基本设置
        Screen.sleepTimeout                    = SleepTimeout.NeverSleep;
        Application.targetFrameRate            = Global.FrameRate;
        UnityEngine.QualitySettings.vSyncCount = Global.VSyncCount;

        //挂载管理器并初始化
        ManagerCollect.Instance.AddManager <TaskManager>(ManagerName.Task);
        ManagerCollect.Instance.AddManager <AssetLoadManager>(ManagerName.AssetLoad);
        ManagerCollect.Instance.AddManager <SoundManager>(ManagerName.Sound);
        ManagerCollect.Instance.AddManager <GestureManager>(ManagerName.Gesture);

        //创建运行时资源目录
        FileUtil.CreateFolder(AppPlatform.RuntimeAssetsPath);

        AssetsUpdater.Run(() =>
        {
            LoadAssetbundleManifest();
        });
    }
Exemplo n.º 2
0
 public PackingConfig()
 {
     BuildPlatform    = AppPlatform.Windows;
     ResourceOutPath  = "";
     ResourceCatalog  = new List <ResourceCatalog>();
     ModelBuildConfig = new List <ResourceModelConfig>();
 }
Exemplo n.º 3
0
        public static string ToApiString(this AppPlatform appPlatform)
        {
            switch (appPlatform)
            {
            case AppPlatform.Windows32:
                return("windows_x86");

            case AppPlatform.Windows64:
                return("windows_x86_64");

            case AppPlatform.Linux32:
                return("linux_x86");

            case AppPlatform.Linux64:
                return("linux_x86_64");

            case AppPlatform.Mac64:
                return("mac_x86_64");

            default:
                throw new ArgumentOutOfRangeException(
                          "appPlatform",
                          appPlatform,
                          null);
            }
        }
        public void Initialize(AppPlatform platform, AppSecret appSecret)
        {
            _platform              = platform;
            _appName               = string.Empty;
            _appSecret             = appSecret.Value;
            _versionLabel          = string.Empty;
            _versionChangelog      = string.Empty;
            _publishOnUpload       = true;
            _overwriteDraftVersion = true;

            try
            {
                _appName = Core.Api.GetAppInfo(appSecret).Name;
            }
            catch (ApiConnectionException e)
            {
                _appName = "(cannot connect to the API)";

                Debug.LogWarning(e);
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning(e);

                Config.UnlinkApp(_platform);
            }
        }
Exemplo n.º 5
0
 public static string AssetSuffix(this AppPlatform value)
 {
     return(value switch
     {
         AppPlatform.Linux64 => "linux64",
         AppPlatform.OsX => "osx",
         AppPlatform.Windows => "win64",
         AppPlatform.Universal => "universal",
         _ => throw new ArgumentException("Unknown platform", nameof(value)),
     });
Exemplo n.º 6
0
    public static void PackageAllResource()
    {
        BuildAssetResource(BuildTarget.StandaloneWindows, AppPlatform.GetPackageResPath(BuildTarget.StandaloneWindows));
        BuildAssetResource(BuildTarget.Android, AppPlatform.GetPackageResPath(BuildTarget.Android));
        BuildAssetResource(BuildTarget.iOS, AppPlatform.GetPackageResPath(BuildTarget.iOS));

        BuildTargetGroup curtargetgroup = AppPlatform.GetCurBuildTargetGroup();
        BuildTarget      curtarget      = AppPlatform.GetCurBuildTarget();

        EditorUserBuildSettings.SwitchActiveBuildTarget(curtargetgroup, curtarget);
    }
Exemplo n.º 7
0
        public void GetDbPath_Platform_CorrectPath(AppPlatform platform, string expectedPathSegment)
        {
            // Arrange
            ExecutingPlatform.Current = platform;

            // Act
            string result = DatabasePathHelper.GetDbPath();

            // Assert
            result.ShouldContain(expectedPathSegment);
        }
Exemplo n.º 8
0
    void LoadAssetbundleManifest()
    {
        LoadingLayer.SetProgressbarTips("游戏初始化中");
        LoadingLayer.SetProgressbarValue(5);
        string bundlName = AppPlatform.GetAssetBundleDirName();

        Global.AssetLoadManager.DownloadingURL = AppPlatform.GetRuntimeAssetBundleUrl();
        Global.AssetLoadManager.LoadManifest(bundlName, () =>
        {
            onStartupFunc();
        });
    }
Exemplo n.º 9
0
        public AppInfoOutput GetAppInfo(AppPlatform platform)
        {
            var cacheKey = string.Format(RedisKeyConstants.APPINFO_KEY, platform);

            return(_cacheManager.Get <AppInfoOutput>(cacheKey, () =>
            {
                using (var conn = GetLotteryConnection())
                {
                    var sql = "SELECT * FROM[dbo].[B_AppInfo] WHERE Platform = @Platform";
                    conn.Open();
                    return conn.QueryFirst <AppInfoOutput>(sql, new { Platform = platform });
                }
            }));
        }
        public void Initialize(AppPlatform platform)
        {
            _platform = platform;

            AppSecret?appSecret = Config.GetConnectedAppSecret(platform);

            if (appSecret.HasValue)
            {
                _connectedAppSecret = appSecret.Value.Value;
            }
            else
            {
                _connectedAppSecret = null;
            }
        }
Exemplo n.º 11
0
    public void Initialize(Action onComplete)
    {
        if (onComplete != null)
        {
            onStartupFunc = onComplete;
        }
        else
        {
            DebugConsole.Log("未设置游戏启动函数");
        }

        //取消 Destroy 对象
        DontDestroyOnLoad(gameObject);

        InitConsole();
        InitUIRoot();
        InitResolution();

        //平台初始化
        AppPlatform.Initialize();

        //基本设置
        Screen.sleepTimeout                    = SleepTimeout.NeverSleep;
        Application.targetFrameRate            = Global.FrameRate;
        UnityEngine.QualitySettings.vSyncCount = Global.VSyncCount;

        //挂载管理器并初始化
        ManagerCollect.Instance.AddManager(ManagerName.Script, ScriptManager.Instance);
        ManagerCollect.Instance.AddManager(ManagerName.Panel, PanelManager.Instance);
        ManagerCollect.Instance.AddManager(ManagerName.Popups, PopupsManager.Instance);

        ManagerCollect.Instance.AddManager <ResourcesUpdateManager>(ManagerName.ResourcesUpdate);
        ManagerCollect.Instance.AddManager <CoroutineManager>(ManagerName.Coroutine);
        ManagerCollect.Instance.AddManager <TimerManager>(ManagerName.Timer);
        ManagerCollect.Instance.AddManager <AssetLoadManager>(ManagerName.Asset);
        ManagerCollect.Instance.AddManager <SceneLoadManager>(ManagerName.Scene);
        ManagerCollect.Instance.AddManager <MusicManager>(ManagerName.Music);
        ManagerCollect.Instance.AddManager <GestureManager>(ManagerName.Gesture);

        //创建运行时资源目录
        FileUtil.CreateFolder(AppPlatform.RuntimeAssetsPath);

        Global.ResourcesUpdateManager.ResourceUpdateStart(() =>
        {
            LoadAssetbundleManifest();
        });
    }
Exemplo n.º 12
0
    // Load AssetBundleManifest.
    public void Initialize(string manifestName, Action initOK)
    {
        m_BaseDownloadingURL = AppPlatform.GetRelativePath();
        LoadAsset <AssetBundleManifest>(manifestName, new string[] { "AssetBundleManifest" }, delegate(UObject[] objs)
        {
            if (objs.Length > 0)
            {
                m_AssetBundleManifest = objs[0] as AssetBundleManifest;
                m_AllManifest         = m_AssetBundleManifest.GetAllAssetBundles();
            }

            if (initOK != null)
            {
                initOK();
            }
        });
    }
Exemplo n.º 13
0
        public static bool IsWindows(this AppPlatform @this)
        {
            switch (@this)
            {
            case AppPlatform.Windows32:
            case AppPlatform.Windows64:
                return(true);

            case AppPlatform.Linux32:
            case AppPlatform.Linux64:
            case AppPlatform.Mac64:
                return(false);

            default:
                throw new ArgumentOutOfRangeException("this", @this, null);
            }
        }
Exemplo n.º 14
0
    private void Start()
    {
        _camera.transform.position = new Vector3(0, 100, 0);

        _instance = this;
        _platform = new AppPlatform();

        _resources    = new ResourceManager();
        _resourcePack = new ResourcePack(Path.Combine(AppPlatform.StreamingAssetsPath, "resource_packs/vanilla"));
        _resources.AddResourcePack(_resourcePack);

        _atlas = new TextureAtlas();
        _atlas.LoadFromResources(_resourcePack);

        _material.SetTexture(MainTex, _atlas.Texture);

        _screenManager.ShowMainMenu();
    }
        public static AppSecret?GetConnectedAppSecret(AppPlatform platform)
        {
            Config instance = FindOrCreateInstance();

            string value;

            switch (platform)
            {
            case AppPlatform.Windows32:
                value = instance._linkedWindows32AppSecret;
                break;

            case AppPlatform.Windows64:
                value = instance._linkedWindows64AppSecret;
                break;

            case AppPlatform.Linux32:
                value = instance._linkedLinux32AppSecret;
                break;

            case AppPlatform.Linux64:
                value = instance._linkedLinux64AppSecret;
                break;

            case AppPlatform.Mac64:
                value = instance._linkedMac64AppSecret;
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          "platform",
                          platform,
                          null);
            }

            try
            {
                return(new AppSecret(value));
            }
            catch (ValidationException)
            {
                return(null);
            }
        }
Exemplo n.º 16
0
        public Auth(string Authority, AppPlatform platform, string clientId, string[] scopes, object parentActivity)
        {
            this.appPlatform    = platform;
            this.clientId       = clientId;
            this.parentActivity = parentActivity;
            this.scopes         = scopes;

            string userDir = MyDocumentsRoot() + @"\";

            this.RedirectUri = $@"msal{this.clientId}://auth";

            this.pca = PublicClientApplicationBuilder.Create(this.clientId)
                       .WithB2CAuthority(Authority)
                       .WithRedirectUri(RedirectUri)
                       .Build();

            Debug.WriteLine($@"Creating auth context with:
            B2C authority: {Authority}
            Client id: {this.clientId}
            Redirect uri: {RedirectUri}");
            if (this.scopes is null)
            {
                System.Diagnostics.Debug.WriteLine("** Scopes are NULL **");
            }
            else
            {
                foreach (var s in scopes)
                {
                    System.Diagnostics.Debug.WriteLine(s);
                }
            }

            switch (platform)
            {
            case AppPlatform.DesktopClient:
                TokenCacheHelper.CacheFilePath = userDir + "msalcache.bin3";
                TokenCacheHelper.EnableSerialization(this.pca.UserTokenCache);
                break;

            default:
                break;
            }
        }
Exemplo n.º 17
0
        public void Initialize(AppPlatform platform, AppSecret appSecret)
        {
            _platform              = platform;
            _appName               = string.Empty;
            _appSecret             = appSecret.Value;
            _versionLabel          = string.Empty;
            _versionChangelog      = string.Empty;
            _publishOnUpload       = true;
            _overwriteDraftVersion = true;
            _removePdbFiles        = true;

            try
            {
                var appInfo = Core.Api.GetAppInfo(appSecret);
                _appName = appInfo.name;

                if (appInfo.removed)
                {
                    Dispatch(
                        () =>
                    {
                        EditorUtility.DisplayDialog(
                            "Game Not Found",
                            "This game does no longer exist on your PatchKit account.\n\n",
                            "OK");
                        Config.UnlinkApp(_platform);
                    });
                }
            }
            catch (ApiConnectionException e)
            {
                _appName = "(cannot connect to the API)";

                Debug.LogWarning(e);
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning(e);

                Dispatch(() => Config.UnlinkApp(_platform));
            }
        }
        public static void ConnectApp(AppSecret appSecret, AppPlatform platform)
        {
            if (!appSecret.IsValid)
            {
                throw new InvalidArgumentException("appSecret");
            }

            Config instance = FindOrCreateInstance();

            switch (platform)
            {
            case AppPlatform.Windows32:
                instance._linkedWindows32AppSecret = appSecret.Value;
                break;

            case AppPlatform.Windows64:
                instance._linkedWindows64AppSecret = appSecret.Value;
                break;

            case AppPlatform.Linux32:
                instance._linkedLinux32AppSecret = appSecret.Value;
                break;

            case AppPlatform.Linux64:
                instance._linkedLinux64AppSecret = appSecret.Value;
                break;

            case AppPlatform.Mac64:
                instance._linkedMac64AppSecret = appSecret.Value;
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          "platform",
                          platform,
                          null);
            }

            EditorUtility.SetDirty(instance);
            AssetDatabase.SaveAssets();
        }
Exemplo n.º 19
0
    public void Initialize()
    {
        env = new CLRSharp.CLRSharp_Environment(new Logger());
        byte[] dll, pdb;
        if (Application.isEditor)
        {
            dll = FileUtil.ReadFileWithByte(AppPlatform.GetRawResourcesPath() + "Code/" + "HotFixCode.dll.bytes");
            pdb = FileUtil.ReadFileWithByte(AppPlatform.GetRawResourcesPath() + "Code/" + "HotFixCode.pdb.bytes");
        }
        else
        {
            dll = FileUtil.ReadFileWithByte(AppPlatform.GetRuntimePackagePath() + "Code/" + "HotFixCode.dll.bytes");
            pdb = FileUtil.ReadFileWithByte(AppPlatform.GetRuntimePackagePath() + "Code/" + "HotFixCode.pdb.bytes");
        }

        System.IO.MemoryStream msDll = new System.IO.MemoryStream(dll);
        System.IO.MemoryStream msPdb = new System.IO.MemoryStream(pdb);

        env.LoadModule(msDll, msPdb, new Mono.Cecil.Pdb.PdbReaderProvider());
        context        = new CLRSharp.ThreadContext(env);
        IsScriptInited = true;
    }
Exemplo n.º 20
0
    IEnumerator LoadSceneBundle()
    {
        LoadingLayer.SetProgressbarTips("Loading Scene...");
        LoadingLayer.SetProgressbarValue(1);

        var rUrl = AppPlatform.GetRuntimeSceneBundleUrl() + loadSceneName.ToLower() + "." + Global.BundleExtName;

        Debug.Log("[DownloadSceneBundle]:>" + rUrl);
        var download = new WWW(rUrl);

        yield return(download);

        if (download.error != null)
        {
            Debug.LogError(download.error);
            yield break;
        }

        sceneBundle = download.assetBundle;

        StartCoroutine(LoadSceneInternal());
    }
Exemplo n.º 21
0
    static void CheckUnpackAssets()
    {
        //首次运行时解包资源
        bool needExtracted = true;

        if (File.Exists(AppPlatform.RuntimeAssetsPath + "server.ini") &&
            File.Exists(AppPlatform.RuntimeAssetsPath + "user.ini") &&
            Directory.Exists(AppPlatform.GetRuntimePackagePath()))//解压过了
        {
            needExtracted = false;
        }

        if (needExtracted && Global.IsSandboxMode) // 不为沙盒模式,则不需要解包,直接取Streaming
        {
            //需要解包,那么先解包,再更新
            Global.TaskManager.StartTask(OnUnpackAssets());
        }
        else
        {
            //不需要解包,直接更新
            Global.TaskManager.StartTask(OnUpdatePackage());
        }
    }
Exemplo n.º 22
0
        public static string ToDisplayString(this AppPlatform @this)
        {
            switch (@this)
            {
            case AppPlatform.Windows32:
                return("Windows 32-bit");

            case AppPlatform.Windows64:
                return("Windows 64-bit");

            case AppPlatform.Linux32:
                return("Linux 32-bit");

            case AppPlatform.Linux64:
                return("Linux 64-bit");

            case AppPlatform.Mac64:
                return("Mac OSX 64-bit");

            default:
                throw new ArgumentOutOfRangeException("this", @this, null);
            }
        }
        public static App CreateNewApp(AppName name, AppPlatform platform)
        {
            if (!name.IsValid)
            {
                throw new InvalidArgumentException("name");
            }

            ApiKey apiKey = GetApiKey();

            App app = ApiConnection.PostUserApplication(
                apiKey.Value,
                name.Value,
                platform.ToApiString());

            if (_cachedApps == null || !_cachedApps.ApiKey.Equals(apiKey))
            {
                _cachedApps = new CachedApps(apiKey);
            }

            _cachedApps.List.RemoveAll(x => x.secret == app.secret);
            _cachedApps.List.Add(app);

            return(app);
        }
        public static void UnlinkApp(AppPlatform platform)
        {
            Config instance = FindOrCreateInstance();

            switch (platform)
            {
            case AppPlatform.Windows32:
                instance._linkedWindows32AppSecret = string.Empty;
                break;

            case AppPlatform.Windows64:
                instance._linkedWindows64AppSecret = string.Empty;
                break;

            case AppPlatform.Linux32:
                instance._linkedLinux32AppSecret = string.Empty;
                break;

            case AppPlatform.Linux64:
                instance._linkedLinux64AppSecret = string.Empty;
                break;

            case AppPlatform.Mac64:
                instance._linkedMac64AppSecret = string.Empty;
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          "platform",
                          platform,
                          null);
            }

            EditorUtility.SetDirty(instance);
            AssetDatabase.SaveAssets();
        }
Exemplo n.º 25
0
 public static bool IsSplashEnabled(AppPlatform platform)
 {
     return(true);
 }
Exemplo n.º 26
0
    IEnumerator OnUpdateResource()
    {
        LoadingLayer.Show();

        if (!AppConst.UpdateMode)
        {
            ResourceUpdateEnd();
            yield break;
        }

        string dataPath = AppPlatform.DataPath;  //数据目录
        string url      = AppConst.WebUrl + AppPlatform.GetCurPackageResPath();
        string listUrl  = url + "files.txt";

        Debuger.Log("LoadUpdate---->>>" + listUrl);

        WWW www = new WWW(listUrl);

        yield return(www);

        if (!string.IsNullOrEmpty(www.error))
        //if (www.error != null)
        {
            Debuger.Log(www.error);
            LoadingLayer.Hide();
            yield break;
        }

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

        File.WriteAllBytes(dataPath + "files.txt", www.bytes);

        string filesText = www.text;

        string[] files = filesText.Split('\n');
        for (int i = 0; i < files.Length; i++)
        {
            float percent = (float)i / (files.Length - 1);
            LoadingLayer.SetProgressbarValue(percent);

            if (string.IsNullOrEmpty(files[i]))
            {
                continue;
            }

            string[] keyValue  = files[i].Split('|');
            string   f         = keyValue[0];
            string   localfile = (dataPath + f).Trim();

            string path = Path.GetDirectoryName(localfile);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string fileUrl   = url + f;
            bool   canUpdate = !File.Exists(localfile);
            if (!canUpdate)
            {
                string remoteMd5 = keyValue[1].Trim();
                string localMd5  = Utility.Md5file(localfile);
                canUpdate = !remoteMd5.Equals(localMd5);
                if (canUpdate)
                {
                    File.Delete(localfile);
                }
            }

            if (canUpdate)
            {
                //本地缺少文件
                Debuger.Log(fileUrl);

                www = new WWW(fileUrl);
                yield return(www);

                if (!string.IsNullOrEmpty(www.error))
                //   if (www.error != null)
                {
                    Debuger.Log(www.error);
                    LoadingLayer.Hide();
                    yield break;
                }

                File.WriteAllBytes(localfile, www.bytes);
            }
        }

        yield return(new WaitForEndOfFrame());

        ResourceUpdateEnd();
    }
Exemplo n.º 27
0
    static IEnumerator OnUnpackAssets()
    {
        LoadingLayer.SetProgressbarTips("开始解包资源");

        //解包config server
        string infile  = Application.streamingAssetsPath + "/" + "server.ini";
        string outfile = AppPlatform.RuntimeAssetsPath + "server.ini";

        if (infile != outfile)
        {
            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }
            if (AppPlatform.PlatformCurrent == Platform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(null);
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
            DebugConsole.Log("[extracting config]:>" + infile + "[TO]" + outfile);
            yield return(new WaitForEndOfFrame());
        }


        //解包config user
        if (infile != outfile)
        {
            infile  = Application.streamingAssetsPath + "/" + "user.ini";
            outfile = AppPlatform.RuntimeAssetsPath + "user.ini";
            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }
            if (AppPlatform.PlatformCurrent == Platform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(null);
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
            DebugConsole.Log("[extracting config]:>" + infile + "[TO]" + outfile);
            yield return(new WaitForEndOfFrame());
        }


        //检查是否有预装package需要解包
        bool needExtractPackage = true;

        if (AppPlatform.PlatformCurrent == Platform.Android)
        {
            var ver = AppPlatform.GetPackagePath() + Global.PackageVersionFileName;
            WWW www = new WWW(ver);
            yield return(www);

            if (www.error != null)
            {
                DebugConsole.Log("没有预装的Package");
                www.Dispose();
                needExtractPackage = false;
            }
        }
        else
        {
            var ver = AppPlatform.GetPackagePath() + Global.PackageVersionFileName;
            if (!File.Exists(ver))
            {
                DebugConsole.Log("没有预装的Package");
                needExtractPackage = false;
            }
        }

        if (needExtractPackage)
        {
            //清理package文件夹
            if (Directory.Exists(AppPlatform.GetRuntimePackagePath()))
            {
                Directory.Delete(AppPlatform.GetRuntimePackagePath(), true);
            }
            Directory.CreateDirectory(AppPlatform.GetRuntimePackagePath());

            //解包package的checklist
            infile  = AppPlatform.GetPackagePath() + Global.PackageManifestFileName;
            outfile = AppPlatform.GetRuntimePackagePath() + Global.PackageManifestFileName;
            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }
            if (AppPlatform.PlatformCurrent == Platform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(null);
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
            DebugConsole.Log("[extracting checklist]:>" + infile + "[TO]" + outfile);
            yield return(new WaitForEndOfFrame());

            //解包package
            string[] files           = File.ReadAllLines(outfile);
            float    downloadedCount = 0f;
            for (int i = 0; i < files.Length; i++)
            {
                var      file      = files[i];
                string[] rKeyValue = file.Split('|');
                infile  = AppPlatform.GetPackagePath() + rKeyValue[0];
                outfile = AppPlatform.GetRuntimePackagePath() + rKeyValue[0];

                DebugConsole.Log("[extracting package]:>" + infile + "[TO]" + outfile);

                string rDirName = Path.GetDirectoryName(outfile);
                if (!Directory.Exists(rDirName))
                {
                    Directory.CreateDirectory(rDirName);
                }

                if (AppPlatform.PlatformCurrent == Platform.Android)
                {
                    WWW www = new WWW(infile);
                    yield return(www);

                    if (www.isDone)
                    {
                        File.WriteAllBytes(outfile, www.bytes);
                    }
                    yield return(0);
                }
                else
                {
                    if (File.Exists(outfile))
                    {
                        File.Delete(outfile);
                    }
                    File.Copy(infile, outfile, true);
                }
                yield return(new WaitForEndOfFrame());

                downloadedCount++;
                float p = (downloadedCount / (float)files.Length) * 100f;
                p = Mathf.Clamp(p, 0, 100);
                LoadingLayer.SetProgressbarValue((int)p);
            }
        }

        LoadingLayer.SetProgressbarTips("解包资源文件完成");
        yield return(new WaitForSeconds(0.1f));

        Global.TaskManager.StartTask(OnUpdatePackage());
    }
Exemplo n.º 28
0
    static IEnumerator OnUpdatePackage()
    {
        if (!Global.IsUpdateMode)
        {
            AssetsUpdateEnd();
            yield break;
        }

        LoadingLayer.SetProgressbarTips("开始更新资源");

        //比对服务器版本
        WWW www = new WWW(Global.ServerPackageVersionURL);

        yield return(www);

        if (www.error != null)
        {
            DebugConsole.Log("未在服务器上找到最新版本文件");
            www.Dispose();
            yield break;
        }
        var lastestVer = www.text;
        var curVer     = "";

        if (File.Exists(AppPlatform.GetRuntimePackagePath() + Global.PackageVersionFileName))
        {
            curVer = FileUtil.ReadFile(AppPlatform.GetRuntimePackagePath() + Global.PackageVersionFileName);
        }

        if (curVer == lastestVer)
        {
            DebugConsole.Log("当前package已是最新版本,无需更新");
            www.Dispose();
            yield break;
        }


        // 获取更新文件列表
        string listUrl = Global.PackageUpdateURL + lastestVer + "/" + AppPlatform.GetPackageName() + "/" + Global.PackageManifestFileName;

        www = new WWW(listUrl);
        yield return(www);

        if (www.error != null)
        {
            DebugConsole.Log("未在服务器上找到checklist");
            www.Dispose();
            yield break;
        }

        if (!Directory.Exists(AppPlatform.GetRuntimePackagePath()))
        {
            Directory.CreateDirectory(AppPlatform.GetRuntimePackagePath());
        }

        File.WriteAllBytes(AppPlatform.GetRuntimePackagePath() + Global.PackageManifestFileName, www.bytes);

        //按照更新列表增量更新文件
        string fileslist = www.text;

        string[] files           = fileslist.Split('\n');
        float    downloadedCount = 0f;

        for (int i = 0; i < files.Length; i++)
        {
            if (string.IsNullOrEmpty(files[i]))
            {
                continue;
            }
            string[] keyValue      = files[i].Split('|');
            string   fileName      = keyValue[0];
            string   localfilePath = (AppPlatform.GetRuntimePackagePath() + fileName).Trim();
            string   path          = Path.GetDirectoryName(localfilePath);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            //检查是否可以更新这个文件
            bool canUpdate = !File.Exists(localfilePath);
            if (!canUpdate)
            {
                string remoteMd5 = keyValue[1].Trim();
                string localMd5  = Util.MD5File(localfilePath);
                canUpdate = !remoteMd5.Equals(localMd5);
                if (canUpdate)
                {
                    File.Delete(localfilePath);
                }
            }

            //可以更新这个文件
            if (canUpdate)
            {
                string fileUrl = Global.PackageUpdateURL + lastestVer + "/" + AppPlatform.GetPackageName() + "/" + fileName;
                Debug.Log(fileUrl);
                www = new WWW(fileUrl);
                yield return(www);

                if (www.error != null)
                {
                    Debug.Log(www.error + path);
                    yield break;
                }
                File.WriteAllBytes(localfilePath, www.bytes);

                downloadedCount++;
                float p = (downloadedCount / (float)files.Length) * 100f;
                p = Mathf.Clamp(p, 0, 100);
                LoadingLayer.SetProgressbarValue((int)p);
            }
        }

        www.Dispose();
        LoadingLayer.SetProgressbarTips("更新资源完成");
        yield return(new WaitForEndOfFrame());

        AssetsUpdateEnd();
    }
 public void Initialize(AppPlatform platform)
 {
     _platform = platform;
 }
Exemplo n.º 30
0
        public void Initialize(AppPlatform platform)
        {
            _platform = platform;

            _name = string.Empty;
        }