예제 #1
0
    public static void CreateAssetRule()
    {
        DDSMeshImportRule newRule = CreateInstance <DDSMeshImportRule>();

        string selectionpath = "Assets";

        foreach (Object obj in Selection.GetFiltered(typeof(Object), SelectionMode.Assets))
        {
            selectionpath = AssetDatabase.GetAssetPath(obj);
            Debug.Log("selectionpath in foreach: " + selectionpath);
            if (File.Exists(selectionpath))
            {
                Debug.Log("File.Exists: " + selectionpath);
                selectionpath = Path.GetDirectoryName(selectionpath);
            }
            break;
        }

        Debug.Log("selectionpath: " + selectionpath);
        string newRuleFileName = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(selectionpath, "New Mesh Rule.asset"));

        newRuleFileName = newRuleFileName.Replace("\\", "/");
        AssetDatabase.CreateAsset(newRule, newRuleFileName);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.FocusProjectWindow();
        Selection.activeObject = newRule;
    }
예제 #2
0
    private void Apply(DDSMeshImportRule assetRule)
    {
        //get the directories that we do not want to apply changes to
        List <string> dontapply     = new List <string>();
        string        assetrulepath = AssetDatabase.GetAssetPath(assetRule).Replace(assetRule.name + ".asset", "").TrimEnd('/');
        string        projPath      = Application.dataPath;

        projPath = projPath.Remove(projPath.Length - 6);

        string[] directories = Directory.GetDirectories(Path.GetDirectoryName(projPath + AssetDatabase.GetAssetPath(assetRule)), "*", SearchOption.AllDirectories);
        foreach (string directory in directories)
        {
            string   d       = directory.Replace(Application.dataPath, "Assets");
            string[] appDirs = AssetDatabase.FindAssets("t:AssetRule", new[] { d });
            if (appDirs.Length != 0)
            {
                d = d.TrimEnd('/');
                d = d.Replace('\\', '/');
                dontapply.Add(d);
            }
        }

        List <string> finalAssetList = new List <string>();

        foreach (string findAsset in AssetDatabase.FindAssets("", new[] { assetrulepath }))
        {
            string asset = AssetDatabase.GUIDToAssetPath(findAsset);
            if (!File.Exists(asset))
            {
                continue;
            }
            if (dontapply.Contains(Path.GetDirectoryName(asset)))
            {
                continue;
            }
            if (!assetRule.IsMatch(AssetImporter.GetAtPath(asset)))
            {
                continue;
            }
            if (finalAssetList.Contains(asset))
            {
                continue;
            }
            if (asset == AssetDatabase.GetAssetPath(assetRule))
            {
                continue;
            }
            finalAssetList.Add(asset);
        }

        foreach (string asset in finalAssetList)
        {
            AssetImporter.GetAtPath(asset).SaveAndReimport();
        }

        changed = false;
    }
예제 #3
0
    public override void OnInspectorGUI()
    {
        DDSMeshImportRule t = (DDSMeshImportRule)target;

        EditorGUI.BeginChangeCheck();


        // Always allow user to switch between tabs even when the editor is disabled, so they can look at all parts
        // of read-only assets
        using (new EditorGUI.DisabledScope(false)) // this doesn't enable the UI, but it seems correct to push the stack
        {
            GUI.enabled = true;
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                using (EditorGUI.ChangeCheckScope check = new EditorGUI.ChangeCheckScope())
                {
                    m_ActiveEditorIndex = GUILayout.Toolbar(m_ActiveEditorIndex, m_TabNames, "LargeButton");
                    if (check.changed)
                    {
                        EditorPrefs.SetInt(GetType().Name + "ActiveEditorIndex", m_ActiveEditorIndex);
                        activeTab = m_Tabs[m_ActiveEditorIndex];
                        activeTab.OnInspectorGUI(t);
                    }
                }
                GUILayout.FlexibleSpace();
            }
        }

        // the activeTab can get destroyed when opening particular sub-editors (such as the Avatar configuration editor on the Rig tab)
        if (activeTab != null)
        {
            activeTab.OnInspectorGUI(t);
        }

        //// show a single Apply/Revert set of buttons for all the tabs
        ApplyRevertGUI();


        if (EditorGUI.EndChangeCheck())
        {
            changed = true;
        }

        if (changed)
        {
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Apply"))
            {
                Apply(t);
            }
            EditorUtility.SetDirty(t);
            GUILayout.EndHorizontal();
        }
    }
    private void NormalsAndTangentsGUI(DDSMeshImportRule rule)
    {
        // Tangent space
        GUILayout.Label(styles.TangentSpace, EditorStyles.boldLabel);
        // TODO : check if normal import is supported!
        //normalImportMode = styles.TangentSpaceModeOptEnumsAll[EditorGUILayout.Popup(styles.TangentSpaceNormalLabel, (int)normalImportMode, styles.TangentSpaceModeOptLabelsAll)];
        EditorGUI.BeginChangeCheck();
        rule.m_NormalImportMode = (ModelImporterNormals)EditorGUILayout.EnumPopup(styles.TangentSpaceNormalLabel, rule.m_NormalImportMode);
        if (EditorGUI.EndChangeCheck())
        {
            // Let the tangent mode follow the normal mode - that's a sane default and it's needed
            // because the tangent mode value can't be lower than the normal mode.
            // We make the tangent mode follow in BOTH directions for consistency
            // - so that if you change the normal mode one way and then back, the tangent mode will also go back again.
            if (rule.m_NormalImportMode == ModelImporterNormals.None)
            {
                rule.m_TangentImportMode = ModelImporterTangents.None;
            }
            else if (rule.m_NormalImportMode == ModelImporterNormals.Import)
            {
                rule.m_TangentImportMode = ModelImporterTangents.Import;
            }
            else
            {
                rule.m_TangentImportMode = ModelImporterTangents.CalculateMikk;
            }
        }

        // Normal split angle
        using (new EditorGUI.DisabledScope(rule.m_NormalImportMode != ModelImporterNormals.Calculate))
        {
            rule.m_NormalSmoothAngle = EditorGUILayout.Slider(styles.SmoothingAngle, rule.m_NormalSmoothAngle, 0f, 180f);
        }
        GUIContent[]            displayedOptions = styles.TangentSpaceModeOptLabelsAll;
        ModelImporterTangents[] array            = styles.TangentSpaceModeOptEnumsAll;
        if (rule.m_NormalImportMode == ModelImporterNormals.Calculate)
        {
            displayedOptions = styles.TangentSpaceModeOptLabelsCalculate;
            array            = styles.TangentSpaceModeOptEnumsCalculate;
        }
        else if (rule.m_NormalImportMode == ModelImporterNormals.None)
        {
            displayedOptions = styles.TangentSpaceModeOptLabelsNone;
            array            = styles.TangentSpaceModeOptEnumsNone;
        }
        using (new EditorGUI.DisabledScope(rule.m_NormalImportMode == ModelImporterNormals.None))
        {
            int num = Array.IndexOf(array, rule.m_TangentImportMode);
            EditorGUI.BeginChangeCheck();
            num = EditorGUILayout.Popup(styles.TangentSpaceTangentLabel, num, displayedOptions, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                rule.m_TangentImportMode = array[num];
            }
        }
    }
    public override void OnInspectorGUI(DDSMeshImportRule t)
    {
        if (styles == null)
        {
            styles = new Styles();
        }

        MeshesGUI(t);
        NormalsAndTangentsGUI(t);
    }
    private void MeshesGUI(DDSMeshImportRule t)
    {
        GUILayout.Label(styles.Meshes, EditorStyles.boldLabel);

        t.m_GlobalScale = EditorGUILayout.FloatField(styles.ScaleFactor, t.m_GlobalScale, new GUILayoutOption[0]);

        // File Scale Factor
        t.m_UseFileScale = EditorGUILayout.Toggle(styles.UseFileScale, t.m_UseFileScale);

        if (t.m_UseFileScale)
        {
            EditorGUI.indentLevel++;
            t.m_FileScale = EditorGUILayout.FloatField(styles.UseFileScale, t.m_FileScale, new GUILayoutOption[0]);
            EditorGUI.indentLevel--;
        }

        //// mesh compression
        t.m_MeshCompression = (ModelImporterMeshCompression)
                              EditorGUILayout.EnumPopup(styles.MeshCompressionLabel, t.m_MeshCompression);

        t.m_IsReadable         = EditorGUILayout.Toggle(styles.IsReadable, t.m_IsReadable);
        t.m_OptimizeMeshForGPU = EditorGUILayout.Toggle(styles.OptimizeMeshForGPU, t.m_OptimizeMeshForGPU);
        t.m_ImportBlendShapes  = EditorGUILayout.Toggle(styles.ImportBlendShapes, t.m_ImportBlendShapes);
        t.m_AddColliders       = EditorGUILayout.Toggle(styles.MeshCompressionLabel, t.m_AddColliders);

        using (new EditorGUI.DisabledScope(true))
        {
            t.m_KeepQuads = EditorGUILayout.Toggle(styles.KeepQuads, t.m_KeepQuads);
        }


        //EditorGUILayout.Popup(m_IndexFormat, styles.IndexFormatOpt, styles.IndexFormatLabel);

        //// Weld Vertices
        t.m_WeldVertices = EditorGUILayout.Toggle(styles.WeldVertices, t.m_WeldVertices);

        //// Import visibility
        //EditorGUILayout.PropertyField(m_ImportVisibility, styles.ImportVisibility);

        //// Import Cameras
        //EditorGUILayout.PropertyField(m_ImportCameras, styles.ImportCameras);

        //// Import Lights
        //EditorGUILayout.PropertyField(m_ImportLights, styles.ImportLights);

        //// Preserve Hierarchy
        //EditorGUILayout.PropertyField(m_PreserveHierarchy, styles.PreserveHierarchy);

        //// Swap uv channel
        t.m_SwapUVChannels = EditorGUILayout.Toggle(styles.SwapUVChannels, t.m_SwapUVChannels);

        // Secondary UV generation
        EditorGUILayout.BeginHorizontal();
        t.m_GenerateSecondaryUV = EditorGUILayout.Toggle(styles.GenerateSecondaryUV, t.m_GenerateSecondaryUV);
        if (t.m_GenerateSecondaryUV)
        {
            t.TipsForGenerate2UV = EditorGUILayout.Toggle(styles.TipsForGenerate2UV, t.TipsForGenerate2UV);
        }
        EditorGUILayout.EndHorizontal();
        if (t.m_GenerateSecondaryUV && t.TipsForGenerate2UV)
        {
            EditorGUI.indentLevel++;
            t.m_SecondaryUVAdvancedOptions = EditorGUILayout.Foldout(t.m_SecondaryUVAdvancedOptions,
                                                                     styles.GenerateSecondaryUVAdvanced, EditorStyles.foldout);
            if (t.m_SecondaryUVAdvancedOptions)
            {
                t.m_SecondaryUVHardAngle = Mathf.Max(EditorGUILayout.Slider(styles.secondaryUVHardAngle,
                                                                            t.m_SecondaryUVHardAngle, 0f, 180f, new GUILayoutOption[0]), 0.1f);
                t.m_SecondaryUVPackMargin = Mathf.Max(EditorGUILayout.Slider(styles.secondaryUVPackMargin,
                                                                             t.m_SecondaryUVPackMargin, 0f, 180f, new GUILayoutOption[0]), 0.1f);
                t.m_SecondaryUVAngleDistortion = Mathf.Max(EditorGUILayout.Slider(styles.secondaryUVAngleDistortion,
                                                                                  t.m_SecondaryUVAngleDistortion, 0f, 180f, new GUILayoutOption[0]), 0.1f);
                t.m_SecondaryUVAreaDistortion = Mathf.Max(EditorGUILayout.Slider(styles.secondaryUVAreaDistortion,
                                                                                 t.m_SecondaryUVAreaDistortion, 0f, 180f, new GUILayoutOption[0]), 0.1f);
            }
            EditorGUI.indentLevel--;
        }
    }
예제 #7
0
 public virtual void OnInspectorGUI(DDSMeshImportRule ddsMeshImportRule)
 {
 }