Exemplo n.º 1
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            bool hasPacakgesToInstall = false;

            foreach (string path in importedAssets)
            {
                if (path.Contains(MCSUpgrade.pathToPackages))
                {
                    hasPacakgesToInstall = true;
                    break;
                }
            }

            if (hasPacakgesToInstall)
            {
                MCSUpgrade.UpgradeMeta meta = MCSUpgrade.GetMeta();
                if (meta.autoInstallPackages)
                {
                    foreach (string path in importedAssets)
                    {
                        if (!path.Contains(MCSUpgrade.pathToPackages))
                        {
                            continue;
                        }

                        MCSUpgrade.InstallPackage(path);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Update()
        {
            if (refresh)
            {
                refresh  = false;
                lastTime = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                AssetDatabase.Refresh(ImportAssetOptions.Default | ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive);
                return;
            }

            if ((packageQueue == null || packageQueue.Count <= 0) && (deleteQueue == null || deleteQueue.Count <= 0))
            {
                return;
            }

            Int32 currentTime = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            Int32 delta = currentTime - lastTime;

            if (delta < 5)
            {
                //wait for later
                return;
            }

            lastTime = currentTime;

            if (packageQueue.Count > 0)
            {
                string path = packageQueue[0];
                packageQueue.RemoveAt(0);
                bool?result = MCSUpgrade.InstallPackage(path);
                if (result == false)
                {
                    UnityEngine.Debug.LogError("Aborting package install as: " + path + " failed to install");
                    packageQueue.Clear();
                }
                else
                {
                    if (result == true)
                    {
                        MCSUpgrade.UpgradeMeta meta = MCSUpgrade.GetMeta();
                        if (meta.installed == null)
                        {
                            meta.installed = new string[] { };
                        }
                        List <string> installed = new List <string>(meta.installed);
                        installed.Add(path);
                        meta.installed = installed.ToArray();
                        MCSUpgrade.SaveMeta(meta);
                    }

                    deleteQueue.Add(path);
                }
                refresh = true;

                //wait until later
                return;
            }

            if (deleteQueue.Count > 0)
            {
                try
                {
                    foreach (string path in deleteQueue)
                    {
                        if (!path.EndsWith(".unitypackage") || !File.Exists(path) || !path.Contains(MCSUpgrade.pathToPackages))
                        {
                            UnityEngine.Debug.Log("Skipping: " + path);
                            continue;
                        }
                        UnityEngine.Debug.Log("Removing install file: " + path);
                        AssetDatabase.DeleteAsset(path);
                    }
                } catch (Exception e)
                {
                    UnityEngine.Debug.LogError("Unable to remove all install packages");
                    UnityEngine.Debug.LogException(e);
                }

                deleteQueue.Clear();

                if (File.Exists(MCSUpgrade.pathToInstallScript))
                {
                    UnityEngine.Debug.Log("Removing installer script");
                    AssetDatabase.DeleteAsset(MCSUpgrade.pathToInstallScript);
                }


                Close();
            }
        }