/// <summary>
        /// Migrate all prefabs
        /// </summary>
        /// <param name="destinationProjectPath"></param>
        /// <param name="originalProjectPath"></param>
        /// <param name="onComplete"></param>
        public void MigrateAllPrefabs(string destinationProjectPath, string originalProjectPath = null,
                                      Action onComplete = null, List <ScriptMapping> scriptMappings = null)
        {
            if (originalProjectPath == null)
            {
                ThreadUtility.RunWaitMainTask(() =>
                {
                    originalProjectPath =
                        EditorUtility.OpenFolderPanel("Export all prefabs in folder", destinationProjectPath, "");
                }
                                              );
            }

            if (string.IsNullOrEmpty(originalProjectPath))
            {
                Debug.Log("Copy prefabs aborted, no path given.");
                return;
            }

            //Deserialize the ScriptMappings
            if (scriptMappings == null && File.Exists(destinationProjectPath + constants.RelativeScriptMappingPath))
            {
                scriptMappings =
                    MappingController.DeserializeMapping(destinationProjectPath + constants.RelativeScriptMappingPath);
            }

            List <PrefabModel> prefabs = prefabController.ExportPrefabs(originalProjectPath + "/Assets");

            for (var i = 0; i < prefabs.Count; i++)
            {
                PrefabModel prefab = prefabs[i];
                MigrationWindow.DisplayProgressBar("Migrating prefab (" + (i + 1) + "/" + prefabs.Count + ")",
                                                   info: "Migrating prefab: " + prefab.Path.Substring(originalProjectPath.Length),
                                                   progress: (float)(i + 1) / prefabs.Count);
                ThreadUtility.RunWaitTask(() =>
                {
                    MigratePrefab(prefab.Path, originalProjectPath, destinationProjectPath, prefabs,
                                  prefab.Guid, scriptMappings);
                }
                                          );
                GC.Collect();
            }

            MigrationWindow.ClearProgressBar();

            ThreadUtility.RunMainTask(() => { AssetDatabase.Refresh(); });
            Debug.Log("Migrated all prefabs");

            if (onComplete != null)
            {
                onComplete.Invoke();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Migrate a scene
        /// </summary>
        /// <param name="scenePath">The scene file to migrate</param>
        public void MigrateScene(string scenePath = null, string rootPath = null)
        {
            try
            {
                if (scenePath == null)
                {
                    ThreadUtility.RunWaitMainTask(() =>
                    {
                        scenePath =
                            EditorUtility.OpenFilePanel("Scene to import", constants.RootDirectory,
                                                        "unity");
                    });
                    if (scenePath.Length == 0)
                    {
                        Debug.LogWarning("No path was selected");
                        return;
                    }
                }

                if (rootPath == null)
                {
                    rootPath = constants.RootDirectory;
                }

                Debug.Log("Started migration of scene: " + scenePath);
                if (BinaryUtility.IsBinaryFile(scenePath))
                {
                    Debug.LogError("Could not parse file, since it's a binary file. Scene file: " + scenePath);
                    return;
                }

                string IDPath = ProjectPathUtility.getProjectPathFromFile(scenePath) + constants.RelativeExportPath;

                if (!File.Exists(IDPath))
                {
                    ThreadUtility.RunWaitMainTask(() =>
                    {
                        EditorUtility.DisplayDialog("Could not find old ID's",
                                                    "Could not find the ID's of the original project.  File does not exist : \r\n" + IDPath,
                                                    "Ok");
                    });
                    return;
                }

                List <ClassModel> oldIDs =
                    Administration.Instance.oldIDsOverride ?? IDController.DeserializeIDs(IDPath);

                string newIDsPath = rootPath + constants.RelativeExportPath;

                List <ClassModel> newIDs;
                if (Administration.Instance.newIDsOverride == null)
                {
                    newIDs = File.Exists(newIDsPath)
                        ? IDController.DeserializeIDs(newIDsPath)
                        : idController.ExportClassData(rootPath);
                }
                else
                {
                    newIDs = Administration.Instance.newIDsOverride;
                }

                List <ScriptMapping> scriptMappings = new List <ScriptMapping>();
                string scriptMappingsPath           = rootPath + constants.RelativeScriptMappingPath;
                if (Administration.Instance.ScriptMappingsOverride != null)
                {
                    scriptMappings = Administration.Instance.ScriptMappingsOverride;
                }
                else if (File.Exists(scriptMappingsPath))
                {
                    scriptMappings = MappingController.DeserializeMapping(scriptMappingsPath);
                }

                this.MigrateSceneIDs(rootPath, oldIDs, newIDs, scenePath, scriptMappings);
                Debug.Log("Migrated scene : " + scenePath);
            }
            catch (Exception e)
            {
                Debug.LogError("Could not migrate scene: " + scenePath + "\r\nException: " + e);
            }
        }