Пример #1
0
    private void SetupFoldoutHeader(MaterialEditor materialEditor)
    {
        Material material = materialEditor.target as Material;

        EditorPersistantBoolVariable.Initialize(ref this.surfaceOptionFoldout, EditorPersistantBoolVariable.BuildKeyFromObject(material, nameof(this.surfaceOptionFoldout)));
        EditorPersistantBoolVariable.Initialize(ref this.toonDiffuseOptionsFoldout, EditorPersistantBoolVariable.BuildKeyFromObject(material, nameof(this.toonDiffuseOptionsFoldout)));
        EditorPersistantBoolVariable.Initialize(ref this.toonRimOptionsFoldout, EditorPersistantBoolVariable.BuildKeyFromObject(material, nameof(this.toonRimOptionsFoldout)));
        EditorPersistantBoolVariable.Initialize(ref this.toonSpecularOptionsFoldout, EditorPersistantBoolVariable.BuildKeyFromObject(material, nameof(this.toonSpecularOptionsFoldout)));
        EditorPersistantBoolVariable.Initialize(ref this.toonNormalOptionsFoldout, EditorPersistantBoolVariable.BuildKeyFromObject(material, nameof(this.toonNormalOptionsFoldout)));
        EditorPersistantBoolVariable.Initialize(ref this.toonEmissionOptionsFodlout, EditorPersistantBoolVariable.BuildKeyFromObject(material, nameof(this.toonEmissionOptionsFodlout)));
        EditorPersistantBoolVariable.Initialize(ref this.advancedOptionsFoldout, EditorPersistantBoolVariable.BuildKeyFromObject(material, nameof(this.advancedOptionsFoldout)));
    }
Пример #2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        try
        {
            EditorPersistantBoolVariable.Initialize(ref this.folded, EditorPersistantBoolVariable.BuildKeyFromObject(property.serializedObject.targetObject, property.name));

            Inline byEnumProperty = (Inline)attribute;
            EditorGUI.BeginChangeCheck();
            string propertyName = "";
            for (var i = 0; i < EditorGUI.indentLevel; i++)
            {
                propertyName += " ";
            }

            propertyName += property.name;

            this.folded.SetValue(EditorGUILayout.BeginFoldoutHeaderGroup(this.folded.GetValue(), propertyName));
            EditorGUILayout.EndFoldoutHeaderGroup();

            if (EditorGUI.EndChangeCheck())
            {
                if (!this.folded.GetValue())
                {
                    if (this.inlineEditor != null)
                    {
                        Editor.DestroyImmediate(inlineEditor);
                        this.inlineEditor = null;
                    }
                }
            }

            if (this.folded.GetValue())
            {
                EditorGUI.indentLevel += 1;
                EditorGUILayout.PropertyField(property);
                EditorGUI.indentLevel -= 1;

                if (property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue != null)
                {
                    if (this.inlineEditor == null)
                    {
                        inlineEditor = DynamicEditorCreation.Get().CreateEditor(property.objectReferenceValue);
                    }

                    if (this.inlineEditor != null)
                    {
                        EditorGUI.indentLevel += 1;
                        this.inlineEditor.OnInspectorGUI();
                        EditorGUI.indentLevel -= 1;
                    }
                }
                else
                {
                    if (EditorUtility.IsPersistent(property.serializedObject.targetObject))
                    {
                        if (byEnumProperty.CreateAtSameLevelIfAbsent)
                        {
                            if (GUILayout.Button(new GUIContent("CREATE")))
                            {
                                var fieldType = SerializableObjectHelper.GetPropertyFieldInfo(property).FieldType;
                                if (fieldType.IsAbstract || fieldType.IsInterface)
                                {
                                    //Open popup to select implementation
                                    ClassSelectionEditorWindow.Show(Event.current.mousePosition, fieldType, (Type selectedType) =>
                                    {
                                        var createdAsset = AssetHelper.CreateAssetAtSameDirectoryLevel((ScriptableObject)property.serializedObject.targetObject, selectedType.Name, property.name);
                                        property.objectReferenceValue = (Object)createdAsset;
                                    });
                                }
                                else
                                {
                                    var createdAsset = AssetHelper.CreateAssetAtSameDirectoryLevel((ScriptableObject)property.serializedObject.targetObject, property.type.Replace("PPtr<$", "").Replace(">", ""), property.name);
                                    property.objectReferenceValue = (Object)createdAsset;
                                }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
        }
    }