Пример #1
0
 private void OnPlayModeStateChanged(PlayModeStateChange state)
 {
     if (state == PlayModeStateChange.ExitingEditMode)
     {
         DynamicEditorCreation.ClearCreatedEditors();
     }
 }
Пример #2
0
        public void OnGui()
        {
            if (!GameConfigurationRefresherProfile.GameConfgurationsRefreshEditorProfile.ContainsKey(gameConfiguration.GetType().Name))
            {
                GameConfigurationRefresherProfile.GameConfgurationsRefreshEditorProfile.Add(gameConfiguration.GetType().Name, new SingleGameConfigurationRefresherProfile());
            }
            else
            {
                SingleGameConfigurationRefresherProfile = GameConfigurationRefresherProfile.GameConfgurationsRefreshEditorProfile[gameConfiguration.GetType().Name];
            }

            SingleGameConfigurationRefresherProfile.Folded = EditorGUILayout.Foldout(SingleGameConfigurationRefresherProfile.Folded, gameConfiguration.GetType().Name, true);
            if (SingleGameConfigurationRefresherProfile.Folded)
            {
                //ConfigurationSerialization
                if (GUILayout.Button(new GUIContent("R", "Refresh"), EditorStyles.miniButton))
                {
                    this.Refresh();
                }
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.ObjectField(this.gameConfiguration, typeof(GameConfiguration), false);
                EditorGUILayout.Separator();
                DynamicEditorCreation.Get().CreateEditor(this.gameConfiguration).OnInspectorGUI();
                EditorGUI.EndDisabledGroup();
            }
        }
Пример #3
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;
        }
    }
Пример #4
0
 public static DynamicEditorCreation Get()
 {
     if (Instance == null)
     {
         Instance = new DynamicEditorCreation();
     }
     return(Instance);
 }
Пример #5
0
 private void OnEnable()
 {
     this.SceneHandleDrawAttribute = this.target.GetType().GetCustomAttribute <SceneHandleDrawAttribute>(true);
     if (this.SceneHandleDrawAttribute != null)
     {
         DynamicEditorCreation.Get().CreatedEditors.Add(this);
         this.RegisterCallback();
     }
 }
Пример #6
0
        private void CreateEditor(C npcAIManager)
        {
            var so = scriptableObjectResolver.Invoke(npcAIManager);

            if (so != null)
            {
                this.cachedEditor = DynamicEditorCreation.Get().CreateEditor(so);
            }
        }
Пример #7
0
 public static void ClearCreatedEditors()
 {
     foreach (var createdEditor in DynamicEditorCreation.Get().CreatedEditors)
     {
         if (createdEditor != null)
         {
             Editor.DestroyImmediate(createdEditor);
         }
     }
     DynamicEditorCreation.Get().CreatedEditors.Clear();
 }
Пример #8
0
 protected void DisplayObjects <T>(string label, List <T> objs, ref Dictionary <T, Editor> cachedEditors) where T : UnityEngine.Object
 {
     if (objs != null && objs.Count > 0)
     {
         EditorGUILayout.LabelField(label);
         EditorGUI.indentLevel += 1;
         foreach (var obj in objs)
         {
             EditorGUILayout.ObjectField(obj, typeof(T), false);
             if (obj != null)
             {
                 if (!cachedEditors.ContainsKey(obj))
                 {
                     cachedEditors[obj] = DynamicEditorCreation.Get().CreateEditor(obj);
                 }
                 cachedEditors[obj].OnInspectorGUI();
                 EditorGUILayout.Separator();
             }
         }
         EditorGUI.indentLevel -= 1;
     }
 }
Пример #9
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)
        {
        }
    }
Пример #10
0
        public void GUITick(ref Dictionary <K, V> dictionaryEditorValues)
        {
            this.DoClearEditorCache();

            DoInit(ref dictionaryEditorValues);
            DoAddEntry(ref dictionaryEditorValues);

            EditorGUILayout.LabelField(typeof(V).Name + " : ", EditorStyles.boldLabel);

            DoSearchFilter(ref dictionaryEditorValues);

            var dictionaryEditorEntryValues = dictionaryEditorValues.ToList();

            if (this.alphabeticalOrder)
            {
                dictionaryEditorEntryValues = dictionaryEditorValues.OrderBy(kv => kv.Key.ToString()).ToList();
            }

            this.searchResultScrollPosition = EditorGUILayout.BeginScrollView(this.searchResultScrollPosition, GUILayout.MaxHeight(1000), GUILayout.MinHeight(100));
            EditorGUILayout.BeginVertical(EditorStyles.textField);
            EditorGUILayout.LabelField("Results : ", EditorStyles.boldLabel);
            this.DictionaryEnumGUIResultPagination.GUITick();

            int displayedCounter = 0;
            int startElementNb   = this.DictionaryEnumGUIResultPagination.StartElementNb();
            int endElementNb     = this.DictionaryEnumGUIResultPagination.EndElementNp();

            foreach (var dictionaryEditorEntry in dictionaryEditorEntryValues)
            {
                //search filter
                bool isKeyMatchingRegex = false;
                if (this.keySearchRegex != null)
                {
                    var keySearchRegexMatch = this.keySearchRegex.Matches(dictionaryEditorEntry.Key.ToString());
                    if (keySearchRegexMatch != null && keySearchRegexMatch.Count > 0)
                    {
                        isKeyMatchingRegex = true;
                    }
                }


                if ((this.keySearchString == null || this.keySearchString == "" || isKeyMatchingRegex /* dictionaryEditorEntry.Key.ToString().ToLower().Contains(keySearchString.ToLower())*/)
                    )
                {
                    if (displayedCounter >= startElementNb && displayedCounter < endElementNb)
                    {
                        DoDisplayEntry(ref dictionaryEditorValues, dictionaryEditorEntry);
                        if (this.valuesToLook.Contains(dictionaryEditorEntry.Key))
                        {
                            if (dictionaryEditorEntry.Value != null)
                            {
                                if (!this.cachedEditors.ContainsKey(dictionaryEditorEntry.Key))
                                {
                                    this.cachedEditors.Add(dictionaryEditorEntry.Key, DynamicEditorCreation.Get().CreateEditor(dictionaryEditorEntry.Value));
                                }

                                this.cachedEditors[dictionaryEditorEntry.Key].OnInspectorGUI();
                                EditorGUILayout.Space();
                            }
                        }
                    }

                    displayedCounter += 1;
                }
            }

            if (displayedCounter == 0)
            {
                EditorGUILayout.LabelField("No elements found.");
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();

            if (valuesToSet.Count > 0)
            {
                foreach (var valueToSet in valuesToSet)
                {
                    dictionaryEditorValues[valueToSet.Key] = valueToSet.Value;
                }

                valuesToSet.Clear();
            }

            if (valuesToRemove.Count > 0)
            {
                foreach (var valueToRemove in valuesToRemove)
                {
                    dictionaryEditorValues.Remove(valueToRemove.Key);
                }

                valuesToRemove.Clear();
            }
        }
Пример #11
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();
        }
    }
Пример #12
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);
        }
    }