コード例 #1
0
    static void BuildClassFile(ClassType classType)
    {
        var enumsPath = InternalEditorUtility.GetAssetsFolder() + "/Scripts/";

        if (!Directory.Exists(enumsPath))
        {
            Directory.CreateDirectory(enumsPath);
        }
        string fileName = "";

        switch (classType)
        {
        case ClassType.Tags:
            fileName = "Tags.cs";
            RebuildTagsFile(enumsPath + fileName);
            break;

        case ClassType.Layers:
            fileName = "Layers.cs";
            RebuildLayersFile(enumsPath + fileName);
            break;

        case ClassType.SortingLayers:
            fileName = "SortingLayers.cs";
            RebuildSortingLayersFile(enumsPath + fileName);
            break;

        default:
            break;
        }
        AssetDatabase.ImportAsset(enumsPath + fileName, ImportAssetOptions.ForceUpdate);
        Debug.Log("已在" + enumsPath + "建立" + fileName);
    }
コード例 #2
0
 private void ExtractTexturesGUI()
 {
     using (new EditorGUILayout.HorizontalScope(new GUILayoutOption[0]))
     {
         EditorGUILayout.PrefixLabel(ModelImporterMaterialEditor.Styles.Textures);
         using (new EditorGUI.DisabledScope(!this.m_HasEmbeddedTextures.boolValue && !this.m_HasEmbeddedTextures.hasMultipleDifferentValues))
         {
             if (GUILayout.Button(ModelImporterMaterialEditor.Styles.ExtractEmbeddedTextures, new GUILayoutOption[0]))
             {
                 List <Tuple <UnityEngine.Object, string> > list = new List <Tuple <UnityEngine.Object, string> >();
                 string text = (base.target as ModelImporter).assetPath;
                 text = EditorUtility.SaveFolderPanel("Select Textures Folder", FileUtil.DeleteLastPathNameComponent(text), "");
                 if (!string.IsNullOrEmpty(text))
                 {
                     text = FileUtil.GetProjectRelativePath(text);
                     try
                     {
                         AssetDatabase.StartAssetEditing();
                         UnityEngine.Object[] targets = base.targets;
                         for (int i = 0; i < targets.Length; i++)
                         {
                             UnityEngine.Object @object = targets[i];
                             string             text2   = FileUtil.GetUniqueTempPathInProject();
                             text2 = text2.Replace("Temp", InternalEditorUtility.GetAssetsFolder());
                             list.Add(Tuple.Create <UnityEngine.Object, string>(@object, text2));
                             ModelImporter modelImporter = @object as ModelImporter;
                             modelImporter.ExtractTextures(text2);
                         }
                     }
                     finally
                     {
                         AssetDatabase.StopAssetEditing();
                     }
                     try
                     {
                         AssetDatabase.Refresh();
                         AssetDatabase.StartAssetEditing();
                         foreach (Tuple <UnityEngine.Object, string> current in list)
                         {
                             ModelImporter modelImporter2 = current.Item1 as ModelImporter;
                             string[]      array          = AssetDatabase.FindAssets("t:Texture", new string[]
                             {
                                 current.Item2
                             });
                             string[] array2 = array;
                             for (int j = 0; j < array2.Length; j++)
                             {
                                 string  guid    = array2[j];
                                 string  text3   = AssetDatabase.GUIDToAssetPath(guid);
                                 Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(text3);
                                 if (!(texture == null))
                                 {
                                     modelImporter2.AddRemap(new AssetImporter.SourceAssetIdentifier(texture), texture);
                                     string text4 = Path.Combine(text, FileUtil.UnityGetFileName(text3));
                                     text4 = AssetDatabase.GenerateUniqueAssetPath(text4);
                                     AssetDatabase.MoveAsset(text3, text4);
                                 }
                             }
                             AssetDatabase.ImportAsset(modelImporter2.assetPath, ImportAssetOptions.ForceUpdate);
                             AssetDatabase.DeleteAsset(current.Item2);
                         }
                     }
                     finally
                     {
                         AssetDatabase.StopAssetEditing();
                     }
                 }
             }
         }
     }
 }