private void Initialize()
        {
            if (m_mappings != null)
            {
                return;
            }

            m_mappings = new List <PersistentClassMapping>();

            PersistentClassMapping[] mappings = MappingsUtility.GetAllMappings();
            for (int i = 0; i < mappings.Length; ++i)
            {
                PersistentClassMapping classMapping = mappings[i];
                if (string.IsNullOrEmpty(classMapping.Version))
                {
                    classMapping.MappedTypeName         = MappingsUtility.FixTypeName(classMapping.MappedTypeName);
                    classMapping.PersistentTypeName     = MappingsUtility.FixTypeName(classMapping.PersistentTypeName);
                    classMapping.PersistentBaseTypeName = MappingsUtility.FixTypeName(classMapping.PersistentBaseTypeName);
                }

                if (classMapping.IsOn && Type.GetType(classMapping.MappedAssemblyQualifiedName) != null)
                {
                    m_mappings.Add(classMapping);
                }
            }

            m_mappings.Sort((m1, m2) => m1.MappedFullTypeName.CompareTo(m2.MappedFullTypeName));
            m_selection = new bool[m_mappings.Count];
            m_indices   = new int[m_mappings.Count];
            for (int i = 0; i < m_mappings.Count; ++i)
            {
                m_indices[i] = i;
            }
        }
        private void Buttons()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            GUILayout.Button("Select All", GUILayout.Height(20));
            if (EditorGUI.EndChangeCheck())
            {
                for (int i = 0; i < m_indices.Length; ++i)
                {
                    m_selection[m_indices[i]] = true;
                }
            }
            EditorGUI.BeginChangeCheck();
            GUILayout.Button("Unselect All", GUILayout.Height(20));
            if (EditorGUI.EndChangeCheck())
            {
                for (int i = 0; i < m_indices.Length; ++i)
                {
                    m_selection[m_indices[i]] = false;
                }
            }
            EditorGUI.BeginChangeCheck();
            GUILayout.Button("Export", GUILayout.Height(20));
            if (EditorGUI.EndChangeCheck())
            {
                string path = EditorUtility.SaveFilePanel("Export Mappings", "", "Mappings", "txt");
                if (!string.IsNullOrEmpty(path))
                {
                    Debug.Log("Export to " + path);

                    List <PersistentClassMapping> classMappings     = new List <PersistentClassMapping>();
                    List <PersistentClassMapping> surrogateMappings = new List <PersistentClassMapping>();
                    for (int i = 0; i < m_selection.Length; ++i)
                    {
                        if (m_selection[i])
                        {
                            if (typeof(UnityEngine.Object).IsAssignableFrom(Type.GetType(m_mappings[i].MappedAssemblyQualifiedName)))
                            {
                                classMappings.Add(m_mappings[i]);
                            }
                            else
                            {
                                surrogateMappings.Add(m_mappings[i]);
                            }
                        }
                    }

                    MappingsUtility.Export(path, classMappings.ToArray(), surrogateMappings.ToArray());
                }
            }

            EditorGUILayout.EndHorizontal();
        }
Exemplo n.º 3
0
        public static void ImportMappings()
        {
            string path = EditorUtility.OpenFilePanel("Import Mappings", "", "txt");

            PersistentClassMapping[] classMappings     = null;
            PersistentClassMapping[] surrogateMappings = null;

            try
            {
                MappingsUtility.Import(path, out classMappings, out surrogateMappings);
                MappingsUtility.MergeClassMappings(classMappings);
                MappingsUtility.MergeSurrogateMappings(surrogateMappings);
            }
            finally
            {
                Cleanup(classMappings);
                Cleanup(surrogateMappings);
            }
        }
        private static void CompleteImportMappings(string mappingsPath)
        {
            EditorPrefs.DeleteKey("RTSL_ImportMappings");

            PersistentClassMapping[] classMappings     = null;
            PersistentClassMapping[] surrogateMappings = null;

            try
            {
                MappingsUtility.Import(mappingsPath, out classMappings, out surrogateMappings);
                MappingsUtility.MergeClassMappings(classMappings);
                MappingsUtility.MergeSurrogateMappings(surrogateMappings);
            }
            finally
            {
                Cleanup(classMappings);
                Cleanup(surrogateMappings);
                File.Delete(mappingsPath);
                File.Delete(mappingsPath + ".meta");
            }

            EditorCoroutine.Start(CoBuildAll());
        }
        private void Buttons()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            GUILayout.Button("Select All", GUILayout.Height(20));
            if (EditorGUI.EndChangeCheck())
            {
                for (int i = 0; i < m_indices.Length; ++i)
                {
                    m_selection[m_indices[i]] = true;
                }
            }
            EditorGUI.BeginChangeCheck();
            GUILayout.Button("Unselect All", GUILayout.Height(20));
            if (EditorGUI.EndChangeCheck())
            {
                for (int i = 0; i < m_indices.Length; ++i)
                {
                    m_selection[m_indices[i]] = false;
                }
            }
            EditorGUI.BeginChangeCheck();
            GUILayout.Button("Export", GUILayout.Height(20));
            if (EditorGUI.EndChangeCheck())
            {
                string packagePath = EditorUtility.SaveFilePanel("Export Mappings", "", "Mappings", "unitypackage");
                if (!string.IsNullOrEmpty(packagePath))
                {
                    Debug.Log("Export to " + packagePath);

                    List <PersistentClassMapping> classMappings     = new List <PersistentClassMapping>();
                    List <PersistentClassMapping> surrogateMappings = new List <PersistentClassMapping>();
                    for (int i = 0; i < m_selection.Length; ++i)
                    {
                        if (m_selection[i])
                        {
                            if (typeof(UnityEngine.Object).IsAssignableFrom(Type.GetType(m_mappings[i].MappedAssemblyQualifiedName)))
                            {
                                classMappings.Add(m_mappings[i]);
                            }
                            else
                            {
                                surrogateMappings.Add(m_mappings[i]);
                            }
                        }
                    }

                    string mappingsPath = Application.dataPath + "/Mappings.txt";
                    MappingsUtility.Export(mappingsPath, classMappings.ToArray(), surrogateMappings.ToArray());
                    AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

                    m_assetsPath.Add("Assets/Mappings.txt");

                    AssetDatabase.ExportPackage(m_assetsPath.ToArray(), packagePath, ExportPackageOptions.Default);
                    AssetDatabase.DeleteAsset("Assets/Mappings.txt");

                    m_dropAreaText = string.Empty;
                    m_assetsPath.Clear();
                }
            }

            EditorGUILayout.EndHorizontal();
        }