示例#1
0
 public static void Initialize(ref EditorPersistantBoolVariable EditorPersistantBoolVariable, string key)
 {
     if (EditorPersistantBoolVariable == null)
     {
         EditorPersistantBoolVariable = new EditorPersistantBoolVariable(key);
     }
 }
示例#2
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)));
    }
示例#3
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)
        {
        }
    }
示例#4
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        CustomEnum searchableEnum = (CustomEnum)attribute;

        if (property.propertyType == SerializedPropertyType.Enum)
        {
            EditorGUI.BeginProperty(position, null, property);

            var targetEnum    = SerializableObjectHelper.GetBaseProperty <Enum>(property);
            int currentLineNB = 0;

            if (searchableEnum.IsSearchable)
            {
                Rect lineRect = this.GetRectFromLineNb(currentLineNB, position);

                var labelFieldRect = new Rect(lineRect.x, lineRect.y, lineRect.width / 2, lineRect.height);
                EditorGUI.LabelField(labelFieldRect, label);
                var enumPopupRect = new Rect(lineRect.x + lineRect.width / 2, lineRect.y, lineRect.width / 2, lineRect.height);
                if (EditorGUI.DropdownButton(enumPopupRect, new GUIContent(targetEnum.ToString()), FocusType.Keyboard))
                {
                    if (windowInstance == null)
                    {
                        windowInstance = EditorWindow.CreateInstance <EnumSearchGUIWindow>();
                        windowInstance.Init(targetEnum, (newSelectedEnum) =>
                        {
                            property.longValue = (int)Convert.ChangeType(newSelectedEnum, newSelectedEnum.GetTypeCode());
                            property.serializedObject.ApplyModifiedProperties();
                            property.serializedObject.Update();
                            EditorUtility.SetDirty(property.serializedObject.targetObject);
                        });
                    }

                    var windowRect = new Rect(GUIUtility.GUIToScreenPoint(enumPopupRect.position), new Vector2(0, enumPopupRect.height));
                    windowInstance.ShowAsDropDown(windowRect, new Vector2(enumPopupRect.width, 500));
                }

                currentLineNB += 1;
            }

            if (searchableEnum.ConfigurationType != null)
            {
                if (updateConfigurationView)
                {
                    var foundAssets = AssetFinder.SafeAssetFind("t:" + searchableEnum.ConfigurationType.Name);
                    if (foundAssets != null && foundAssets.Count > 0)
                    {
                        var configuration = (IConfigurationSerialization)foundAssets[0];
                        configuration.GetEntryTry(targetEnum, out ScriptableObject so);
                        if (so != null)
                        {
                            this.CachedConfigurationEditor = DynamicEditorCreation.Get().CreateEditor(so);
                            this.ConfigurationFoldableArea = new FoldableArea(false, so.name, false, new EditorPersistantBoolVariable(EditorPersistantBoolVariable.BuildKeyFromObject(so, so.name)));
                        }
                        else
                        {
                            this.CachedConfigurationEditor = null;
                            this.ConfigurationFoldableArea = null;
                        }
                    }

                    updateConfigurationView = false;
                }

                if (this.lastFrameEnum == null)
                {
                    this.CachedConfigurationEditor = null;
                    this.ConfigurationFoldableArea = null;
                }

                if (CachedConfigurationEditor != null && this.ConfigurationFoldableArea != null)
                {
                    try
                    {
                        var oldBackGroundColor = GUI.backgroundColor;
                        GUI.backgroundColor = MyColors.HotPink;
                        this.ConfigurationFoldableArea.OnGUI(() =>
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.ObjectField(this.CachedConfigurationEditor.target, typeof(ScriptableObject), false);
                            EditorGUI.EndDisabledGroup();
                            this.CachedConfigurationEditor.OnInspectorGUI();
                        });
                        GUI.backgroundColor = oldBackGroundColor;
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (CachedConfigurationEditor == null)
                {
                    try
                    {
                        //We propose creation wizard
                        if (GUILayout.Button("CREATE IN WIZARD"))
                        {
                            GameCreationWizard.InitWithSelected(targetEnum.GetType().Name.Replace("ID", "CreationWizard"));
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                EditorGUILayout.Space();
            }

            updateConfigurationView = this.lastFrameEnum == null || (this.lastFrameEnum != null && this.lastFrameEnum.ToString() != targetEnum.ToString());

            if (searchableEnum.OpenToConfiguration)
            {
                if (searchableEnum.ConfigurationType != null)
                {
                    try
                    {
                        if (GUILayout.Button("OPEN CONFIGURATION"))
                        {
                            var gameDesignerEditor = ConfigurationInspector.OpenConfigurationEditor(searchableEnum.ConfigurationType);
                            var currentGameModule  = gameDesignerEditor.GetCrrentGameDesignerModule();
                            if (typeof(IConfigurationModule).IsAssignableFrom(currentGameModule.GetType()))
                            {
                                ((IConfigurationModule)currentGameModule).SetSearchString(targetEnum.ToString());
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            this.lastFrameEnum = targetEnum;

            EditorGUI.EndProperty();
        }
    }
示例#5
0
 public FoldableAreaPersistance(EditorPersistantBoolVariable isFoldedPersisted)
 {
     this.isFoldedPersisted = isFoldedPersisted;
 }
示例#6
0
 public FoldableArea(bool canBeDisabled, string foldContent, bool isEnabledStartValue, EditorPersistantBoolVariable isFoldedPersistedBoolVariable = null)
 {
     this.canBeDisabled = canBeDisabled;
     this.foldContent   = foldContent;
     this.isEnabled     = isEnabledStartValue;
     if (isFoldedPersistedBoolVariable == null)
     {
         this.IFoldableAreaFoldoutValueStrategy = new NonPersistedFoldableArea();
     }
     else
     {
         this.IFoldableAreaFoldoutValueStrategy = new FoldableAreaPersistance(isFoldedPersistedBoolVariable);
     }
 }
示例#7
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        IncludeConfiguration IncludeConfigurationEnum = (IncludeConfiguration)attribute;

        if (property.propertyType == SerializedPropertyType.Enum)
        {
            var targetEnum = SerializableObjectHelper.GetBaseProperty <Enum>(property);
            if (this.CachedConfigurationEditor == null || this.lastFrameEnum.ToString() != targetEnum.ToString())
            {
                var configuration = (IConfigurationSerialization)AssetFinder.SafeAssetFind("t:" + IncludeConfigurationEnum.ConfigurationType.Name)[0];
                var so            = configuration.GetEntry(targetEnum);
                this.CachedConfigurationEditor = DynamicEditorCreation.Get().CreateEditor(so);
                this.FoldableArea = new FoldableArea(false, so.name, false, new EditorPersistantBoolVariable(EditorPersistantBoolVariable.BuildKeyFromObject(so, so.name)));
            }

            if (CachedConfigurationEditor != null)
            {
                this.FoldableArea.OnGUI(() => { this.CachedConfigurationEditor.OnInspectorGUI(); });
            }

            this.lastFrameEnum = targetEnum;
        }
    }