Пример #1
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);
            }

            if (CachedConfigurationEditor != null)
            {
                this.FoldableArea.OnGUI(() =>
                {
                    this.CachedConfigurationEditor.OnInspectorGUI();
                });
            }
            this.lastFrameEnum = targetEnum;
        }
    }
Пример #2
0
    public override void OnGenerationClicked(AbstractCreationWizardEditorProfile editorProfile)
    {
        var generatedHierarchy = this.CreateAsset(InstancePath.PuzzleLevelHierarchyDataPath, this.GetLevelZonesID(editorProfile) + NameConstants.LevelHierarchyConfigurationData, editorProfile);

        this.GetCommonGameConfigurations(editorProfile).GetConfiguration <LevelHierarchyConfiguration>().SetEntry(this.GetLevelZonesID(editorProfile), generatedHierarchy);
        editorProfile.GameConfigurationModified(this.GetCommonGameConfigurations(editorProfile).GetConfiguration <LevelHierarchyConfiguration>(), this.GetLevelZonesID(editorProfile), generatedHierarchy);

        var generatedHierarchySerialized = new SerializedObject(generatedHierarchy);

        SerializableObjectHelper.SetArray((new List <LevelZoneChunkID>()).ConvertAll(e => (Enum)e), generatedHierarchySerialized.FindProperty(nameof(generatedHierarchy.LevelHierarchy)));
        generatedHierarchySerialized.ApplyModifiedProperties();
    }
Пример #3
0
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     if (SerializableObjectHelper.GetArrayIndex(property) == 0)
     {
         if (this.rList != null)
         {
             return(this.rList.GetHeight());
         }
         return(base.GetPropertyHeight(property, label));
     }
     else
     {
         return(0f);
     }
 }
Пример #4
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Foldable foldableAttribute = (Foldable)attribute;

        SerializedProperty disablingProperty = null;

        if (foldableAttribute.CanBeDisabled)
        {
            var parentProperty = SerializableObjectHelper.GetParentProperty(property);
            disablingProperty = parentProperty.FindPropertyRelative(foldableAttribute.DisablingBoolAttribute);
            if (this.foldableArea == null)
            {
                this.foldableArea = new FoldableArea(foldableAttribute.CanBeDisabled, property.name, disablingProperty.boolValue);
            }
        }
        else
        {
            if (this.foldableArea == null)
            {
                this.foldableArea = new FoldableArea(foldableAttribute.CanBeDisabled, property.name, false);
            }
        }


        EditorGUI.BeginProperty(position, null, property);
        this.foldableArea.OnGUI(() =>
        {
            try
            {
                foreach (var childPropery in SerializableObjectHelper.GetChildren(property))
                {
                    EditorGUILayout.PropertyField(childPropery, true);
                }
            }
            catch (Exception) { }
        });

        if (foldableAttribute.CanBeDisabled)
        {
            disablingProperty.boolValue = this.foldableArea.IsEnabled;
        }
        EditorGUI.EndProperty();
    }
Пример #5
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        ReorderableListAttribute attr = (ReorderableListAttribute)attribute;
        var parentProperty            = SerializableObjectHelper.GetParentProperty(property);

        position.height *= 3;
        if (parentProperty != null && parentProperty.isArray)
        {
            if (SerializableObjectHelper.GetArrayIndex(property) == 0)
            {
                if (this.rList == null)
                {
                    this.rList = new ReorderableList(property.serializedObject, parentProperty);
                    this.rList.drawHeaderCallback = (Rect rect) =>
                    {
                        EditorGUI.LabelField(rect, SerializableObjectHelper.GetParentProperty(parentProperty).name);
                    };
                    this.rList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
                    {
                        rect.y      += 2;
                        rect.height -= 5;
                        if (attr.DisplayLineLabel)
                        {
                            EditorGUI.PropertyField(rect, this.rList.serializedProperty.GetArrayElementAtIndex(index), true);
                        }
                        else
                        {
                            EditorGUI.PropertyField(rect, this.rList.serializedProperty.GetArrayElementAtIndex(index), GUIContent.none, true);
                        }
                    };
                    this.rList.elementHeightCallback = (int index) =>
                    {
                        return(EditorGUI.GetPropertyHeight(this.rList.serializedProperty.GetArrayElementAtIndex(index)) + 3);
                    };
                }
                this.rList.DoList(position);
            }
        }

        parentProperty.serializedObject.ApplyModifiedProperties();
    }
Пример #6
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)
        {
        }
    }
Пример #7
0
 public override void AfterGeneration(AbstractCreationWizardEditorProfile editorProfile)
 {
     SerializableObjectHelper.Modify(this.CreatedObject, (so) => { so.FindProperty(nameof(this.CreatedObject.scene)).objectReferenceValue = this.GetCreatedSceneAsset(editorProfile); });
 }
Пример #8
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();
        }
    }
Пример #9
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        try
        {
            Inline byEnumProperty = (Inline)attribute;

            EditorGUI.BeginProperty(position, label, property);
            EditorGUILayout.BeginVertical(EditorStyles.textArea);

            EditorGUI.BeginChangeCheck();
            this.folded = EditorGUILayout.Foldout(this.folded, property.name, true);
            if (EditorGUI.EndChangeCheck())
            {
                if (!this.folded)
                {
                    if (this.inlineEditor != null)
                    {
                        Editor.DestroyImmediate(inlineEditor);
                        this.inlineEditor = null;
                    }
                }
            }

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

                if (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;
                                }
                            }
                        }
                    }
                }
            }

            EditorGUILayout.EndVertical();
            EditorGUI.EndProperty();
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }