Exemplo n.º 1
0
        private void ParseSourceFile(float progress, string file, ref List <ClassModel> data,
                                     int gcLimit,
                                     ref int gcCount)
        {
            MigrationWindow.DisplayProgressBar("Exporting IDs", "Exporting IDs " + Path.GetFileName(file),
                                               progress);
            IEnumerable <string> lines = File.ReadLines(file);
            string className;

            foreach (string line in lines)
            {
                Match match = constants.RegexGuid.Match(line);
                if (!match.Success)
                {
                    continue;
                }

                className = getTypeByMetafileFileName(file);
                if (String.IsNullOrEmpty(className))
                {
                    continue;
                }

                data.Add(new ClassModel(className, match.Value));
                break;
            }
            gcCount++;
            if (gcCount > gcLimit)
            {
                GC.Collect();
            }
        }
Exemplo n.º 2
0
        /// <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();
            }
        }
Exemplo n.º 3
0
        private void ParseDLLFile(float progress, string metaFile, ref List <ClassModel> data,
                                  int gcLimit,
                                  ref int gcCount)
        {
            MigrationWindow.DisplayProgressBar("Exporting IDs", "Exporting IDs " + Path.GetFileName(metaFile),
                                               progress);
            string text  = File.ReadAllText(metaFile);
            Match  match = constants.RegexGuid.Match(text);

            if (!match.Success)
            {
                Debug.LogError("Could not parse the guid from the dll meta file. File : " +
                               metaFile);
            }

            string file = metaFile.Replace(".meta", "");

            try
            {
                if (Path.GetFileName(file).Contains("Newtonsoft.Json") ||
                    Path.GetFileName(file).Contains("YamlDotNet"))
                {
                    return;
                }

                Assembly assembly = Assembly.LoadFile(file);
                foreach (Type type in assembly.GetTypes())
                {
                    if (!type.IsSubclassOf(typeof(MonoBehaviour)))
                    {
                        continue;
                    }

                    MigrationWindow.DisplayProgressBar("Exporting IDs", "Exporting IDs " + type, progress);
                    data.Add(new ClassModel(type, match.Value, FileIDUtil.Compute(type).ToString()));

                    gcCount++;
                    if (gcCount > gcLimit)
                    {
                        GC.Collect();
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogWarning("Could not load assembly : " + file + "\nException : " + e);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Replaces all old GUIDs and old fileIDs with the new GUID and fileID and returns a the new scenefile.
        /// This can be saved as an .unity file and then be opened in the editor.
        /// </summary>
        /// <param name="fileToChange"></param>
        /// <param name="oldIDs"></param>
        /// <param name="newIDs"></param>
        /// <param name="foundScripts"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public string[] TransformIDs(string fileToChange, List <ClassModel> oldIDs,
                                     List <ClassModel> newIDs, ref List <FoundScript> foundScripts)
        {
            MigrationWindow.DisplayProgressBar("Migration started",
                                               "Start importing current project classData and migrating scene.", 0.5f);
            if (oldIDs == null || newIDs == null || foundScripts == null)
            {
                throw new NullReferenceException("Some of the data with which to export is null.");
            }

            string[] linesToChange = File.ReadAllLines(fileToChange);

            linesToChange = MigrateGUIDsAndFieldIDs(linesToChange, oldIDs, newIDs, ref foundScripts);
            MigrationWindow.ClearProgressBar();

            return(linesToChange);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Generate a mapping of all scriptMappings in a project.
 /// Which means it creates a mapping between versions.
 /// </summary>
 /// <param name="oldIDs"></param>
 /// <param name="newIDs"></param>
 /// <returns></returns>
 public void MapAllClasses(List <ClassModel> oldIDs, List <ClassModel> newIDs)
 {
     ThreadUtility.RunTask(() =>
     {
         MigrationWindow.DisplayProgressBar("starting migration export", "Mapping classes", 0.4f);
         mappingController.MapAllClasses(oldIDs, newIDs,
                                         mergedScriptMapping =>
         {
             SaveScriptMappings(constants.RootDirectory, mergedScriptMapping);
             MigrationWindow.ClearProgressBar();
             ThreadUtility.RunMainTask(() =>
             {
                 EditorUtility.DisplayDialog("Completed mapping",
                                             "Completed the mapping. Saved the mapping to: " + constants.RelativeScriptMappingPath,
                                             "Ok");
             });
         });
     });
 }
Exemplo n.º 6
0
        public List <PrefabModel> ExportPrefabs(string path)
        {
            //Get all prefabs
            string[] prefabMetaFiles = Directory.GetFiles(path, "*.prefab.meta", SearchOption.AllDirectories);


            List <PrefabModel> prefabModels = new List <PrefabModel>(prefabMetaFiles.Length);

            for (var i = 0; i < prefabMetaFiles.Length; i++)
            {
                string file = prefabMetaFiles[i];
                MigrationWindow.DisplayProgressBar("Exporting Prefabs", "Exporting prefab " + Path.GetFileName(file),
                                                   prefabMetaFiles.Length / i);

                ParsePrefabFile(file, ref prefabModels);
            }

            return(prefabModels);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Migrate all scenes in a project at once at once
        /// </summary>
        /// <param name="projectToExportFromPath">The path of the project that needs to be migrated to the current project</param>
        /// <param name="onComplete">Runs after all scenes have been exported</param>
        public void MigrateAllScenes(string projectToExportFromPath = null, Action onComplete = null)
        {
            MigrationWindow.DisplayProgressBar("Migrating scenes", "Migrating scenes", 0.2f);

            if (projectToExportFromPath == null)
            {
                projectToExportFromPath =
                    EditorUtility.OpenFolderPanel("Export all scenes in folder", constants.RootDirectory, "");
            }

            if (string.IsNullOrEmpty(projectToExportFromPath))
            {
                Debug.Log("Migrating all scenes aborted, no path given.");
                MigrationWindow.ClearProgressBar();
                return;
            }

            ThreadUtility.RunTask(() =>
            {
                string[] sceneFiles =
                    Directory.GetFiles(projectToExportFromPath, "*.unity", SearchOption.AllDirectories);

                for (var i = 0; i < sceneFiles.Length; i++)
                {
                    string scene = sceneFiles[i];
                    MigrationWindow.DisplayProgressBar("Migrating scenes (" + (i + 1) + "/" + sceneFiles.Length + ")",
                                                       "Migrating scene: " + scene.Substring(projectToExportFromPath.Length),
                                                       (float)(i + 1) / sceneFiles.Length);

                    ThreadUtility.RunWaitTask(() => { MigrateScene(scene, constants.RootDirectory); });
                    GC.Collect();
                }

                MigrationWindow.ClearProgressBar();
                Debug.Log("Migrated all scenes");

                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
            });
        }