コード例 #1
0
        /// <summary>
        /// Gets all the classes in the project and gets the name of the class, the guid that unity assigned and the fileID.
        /// Then checks all to be serialized fields and returns them in a list
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List <ClassModel> ExportClassData(string path)
        {
            //Get all meta files
            string[] classMetaFiles = Directory.GetFiles(path, "*.cs.meta", SearchOption.AllDirectories);

            //Get all dlls
            string[] dllMetaFiles = Directory.GetFiles(path, "*.dll.meta", SearchOption.AllDirectories);

            int gcCount = 0;
            int gcLimit = 50000;
            List <ClassModel> classes = new List <ClassModel>();
            string            file;

            for (var i = 0; i < classMetaFiles.Length; i++)
            {
                file = classMetaFiles[i];
                ParseSourceFile((float)i / classMetaFiles.Length, file, ref classes, gcLimit, ref gcCount);
            }

            string metaFile;

            for (var i = 0; i < dllMetaFiles.Length; i++)
            {
                metaFile = dllMetaFiles[i];
                ParseDLLFile((float)i / dllMetaFiles.Length, metaFile, ref classes, gcLimit, ref gcCount);
            }

            GC.Collect();
            MigrationWindow.ClearProgressBar();
            return(classes);
        }
コード例 #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();
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets all the classes in the project and gets the name of the class, the guid that unity assigned and the fileID.
        /// Then checks all to be serialized fields and returns them in a list
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List <ClassModel> ExportClassData(string path)
        {
            float progress = 0;

            //Get all meta files
            string[] classMetaFiles = Directory.GetFiles(path, "*.cs.meta", SearchOption.AllDirectories);

            //Get all dlls
            string[] dllMetaFiles = Directory.GetFiles(path, "*.dll.meta", SearchOption.AllDirectories);

            int totalFiles = classMetaFiles.Length + dllMetaFiles.Length;

            int gcCount = 0;
            int gcLimit = 50000;
            List <ClassModel> classes = new List <ClassModel>();

            for (var i = 0; i < classMetaFiles.Length; i++)
            {
                string file = classMetaFiles[i];
                ParseSourceFile((float)i / classMetaFiles.Length, file, ref classes, gcLimit, ref gcCount);
            }

            // Loop through dlls
            if (!constants.DEBUG)
            {
//                Thread[] dllThreads = new Thread[dllMetaFiles.Length];
                for (var i = 0; i < dllMetaFiles.Length; i++)
                {
                    string metaFile = dllMetaFiles[i];
//                    dllThreads[i] =
//                        new Thread(() =>
                    ParseDLLFile((float)i / dllMetaFiles.Length, metaFile, ref classes, gcLimit, ref gcCount)
//                                )
                    ;
//                    dllThreads[i].Start();
                }

//                bool stillRunning = true;
//                while (stillRunning)
//                {
//                    int threadsRunning = dllThreads.Where(thread => thread.IsAlive).ToArray().Length;
//                    stillRunning = threadsRunning > 0;
//
//                    MigrationWindow.DisplayProgressBar("Exporting IDs from DLLs",
//                        "Threads running " + threadsRunning + "/" + dllThreads.Length,
//                        threadsRunning / dllThreads.Length);
//                    Thread.Sleep(100);
//                }
            }

            MigrationWindow.ClearProgressBar();
            return(classes);
        }
コード例 #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);
        }
コード例 #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");
             });
         });
     });
 }
コード例 #6
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();
                }
            });
        }