Example #1
0
        public static ZBaseEditorCoroutines StartEditorCoroutine(IEnumerator routine)
        {
            ZBaseEditorCoroutines coroutine = new ZBaseEditorCoroutines(routine);

            coroutine.start();
            return(coroutine);
        }
        private void GetPackageFromServer(string packageName, System.Action <Dictionary <string, object> > callback)
        {
            string urlPackage = string.Format(PackVersionURL, ZBasePackageIdConfig.Repo, packageName);

            mEditorCoroutines =
                ZBaseEditorCoroutines.StartEditorCoroutine(GetRequest(urlPackage, (result) => callback(result)));
        }
        private void GetPackageIdConfig()
        {
            string urlPackageIdConfig = string.Format(PackIdConfigURL, ZBasePackageIdConfig.Repo);

            mEditorCoroutines = ZBaseEditorCoroutines.StartEditorCoroutine(GetRequest(urlPackageIdConfig,
                                                                                      (result) => GetDataFromPackageConfig(result)));
        }
        private void GetPackageLockServer()
        {
            string urlPackageLock = string.Format(PackLockURL, ZBasePackageIdConfig.Repo);

            mEditorCoroutines = ZBaseEditorCoroutines.StartEditorCoroutine(GetRequest(urlPackageLock,
                                                                                      (result) => GetDataFromPackageLockServer(result)));
        }
        private void RemoveButton(ProviderModel providerData)
        {
            GUI.enabled = true;
            var btn = GUILayout.Button(new GUIContent
            {
                text = "Remove",
            }, buttonWidth, buttonHeight);

            if (btn && !isProcessing)
            {
                GUI.enabled = true;
                try
                {
                    ZLog.Warning(">>>>>>>>> Remove Click! <<<<<<<<<<");

                    if (EditorUtility.DisplayDialog("Remove Package", "Are you sure you want to remove this package?",
                                                    "Remove", "Cancle"))
                    {
                        ZBaseEditorCoroutines.StartEditorCoroutine(RemovePackage(providerData.providerName, (result) =>
                        {
                            if (result.Status == StatusCode.Success)
                            {
                                ZLog.Info(string.Format("***Remove Success {0} {1}***", providerData.providerName,
                                                        providerData.latestUnityVersion));
                                canRefresh = true;
                            }
                        }));
                    }
                }
                catch (System.Exception e)
                {
                    ZLog.Error("Error " + e.Message);
                }
            }
        }
        private void CancelDownload()
        {
            isProcessing = false;

            if (mEditorCoroutines != null)
            {
                mEditorCoroutines.StopEditorCoroutine();
                mEditorCoroutines = null;
            }
        }
        private void InstallButton(ProviderModel providerData)
        {
            bool btn = GUILayout.Button(new GUIContent
            {
                text = "Install",
            }, buttonWidth, buttonHeight);

            if (btn && !isProcessing)
            {
                GUI.enabled = true;
                try
                {
                    ZLog.Warning(">>>>>>>>> Install Click! <<<<<<<<<<");
                    if (providersSet[providerData.providerName].dependencies.Count == 0)
                    {
                        ZBaseEditorCoroutines.StartEditorCoroutine(AddPackage(providerData, (result) =>
                        {
                            if (result.Status == StatusCode.Success)
                            {
                                ZLog.Info(string.Format("***Install Success {0} {1}***", providerData.providerName,
                                                        providerData.latestUnityVersion));
                                canRefresh = true;
                                if (!providerData.providerName.StartsWith("com"))
                                {
                                    EditorPrefs.SetString("key_package_import", providerData.providerName);
                                }
                            }
                        }));
                    }
                    else
                    {
                        ZBaseEditorCoroutines.StartEditorCoroutine(AddPackageWithDependencie(providerData, (result) =>
                        {
                            if (result.Status == StatusCode.Success)
                            {
                                ZLog.Info(string.Format("***Install Success {0} {1}***", providerData.providerName,
                                                        providerData.latestUnityVersion));
                                EditorApplication.UnlockReloadAssemblies();
                                canRefresh = true;
                                if (!providerData.providerName.StartsWith("com"))
                                {
                                    EditorPrefs.SetString("key_package_import", providerData.providerName);
                                }
                            }
                        }));
                    }
                }
                catch (System.Exception e)
                {
                    ZLog.Error("Error " + e.Message);
                }
            }
        }
        private IEnumerator AddPackageWithDependencie(ProviderModel providerInfo, System.Action <AddRequest> callback)
        {
            pkgNameQueue.Clear();
            urlQueue.Clear();

            CheckDependenciesPackage(providerInfo);
            AddMultiPackage();

            while (isAddMultiPkg)
            {
                isProcessing = true;
                yield return(new WaitForSeconds(0.1f));
            }

            ZBaseEditorCoroutines.StartEditorCoroutine(AddPackage(providerInfo, callback));
        }
        private void GetDataFromPackageLockServer(Dictionary <string, object> data)
        {
            providersSet.Clear();

            try
            {
                object dependencies;

                if (data.TryGetValue("dependencies", out dependencies))
                {
                    if (dependencies != null)
                    {
                        foreach (var item in dependencies as Dictionary <string, object> )
                        {
                            ProviderModel info = new ProviderModel();
                            if (ZBasePackageIdConfig.ListPackages.ContainsKey(item.Key))
                            {
                                if (info.GetFromJson(item.Key, item.Value as Dictionary <string, object>))
                                {
                                    providersSet.Add(info.providerName, info);
                                    if (info.currentUnityVersion != "none")
                                    {
                                        ZLog.Info(string.Format("***Package {0} on server, version {1}***",
                                                                info.displayProviderName, info.latestUnityVersion));
                                    }
                                }
                            }
                        }
                    }
                }

                progressLoadData++;

                ZBaseEditorCoroutines.StartEditorCoroutine(GetVersionForEmbeddedPack());
            }
            catch (Exception e)
            {
                ZLog.Error("Error Get Version From Package Lock Server: " + e.Message);
            }
        }
 private void CheckVersion()
 {
     progressLoadData = 0;
     GetPackageIdConfig();
     mEditorCoroutines = ZBaseEditorCoroutines.StartEditorCoroutine(GetVersionFromPackageLockLocal());
 }