public void InitEditorData(int instanceIndex) { if (this.GameDesignerEditorProfile == null) { var GameDesignerEditorProfiles = AssetFinder.SafeAssetFind <GameDesignerEditorProfile>("t:" + typeof(GameDesignerEditorProfile).Name); foreach (var GameDesignerEditorProfile in GameDesignerEditorProfiles) { if (GameDesignerEditorProfile.GameDesignerProfileInstanceIndex == instanceIndex) { this.GameDesignerEditorProfile = GameDesignerEditorProfile; break; } } if (this.GameDesignerEditorProfile == null) { var CreatedGameDesignerEditorProfile = (GameDesignerEditorProfile)GameDesignerEditorProfile.CreateInstance(typeof(GameDesignerEditorProfile)); CreatedGameDesignerEditorProfile.GameDesignerProfileInstanceIndex = instanceIndex; AssetDatabase.CreateAsset(CreatedGameDesignerEditorProfile, GameDesignerProfilePath + "/GameDesignerEditorProfile_" + instanceIndex + ".asset"); this.GameDesignerEditorProfile = CreatedGameDesignerEditorProfile; } } if (this.GameDesignerEditorProfile != null) { if (this.ChoiceTree == null) { this.ChoiceTree = new GameDesignerChoiceTree(this.GameDesignerEditorProfile); } } }
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; } }
public static int GetGameDesignerEditorInstance() { if (gameDesignerEditors == null) { gameDesignerEditors = new Dictionary <int, GameDesignerEditor>(); var GameDesignerEditorProfiles = AssetFinder.SafeAssetFind <GameDesignerEditorProfile>("t:" + typeof(GameDesignerEditorProfile).Name); foreach (var GameDesignerEditorProfile in GameDesignerEditorProfiles) { gameDesignerEditors[GameDesignerEditorProfile.GameDesignerProfileInstanceIndex] = null; } } int pickedIndex = 0; if (gameDesignerEditors.Count > 0) { var maxIndex = gameDesignerEditors.Keys.ToList().Max(); bool hasFoundPick = false; for (var i = 0; i < maxIndex; i++) { if (!gameDesignerEditors.ContainsKey(i) || gameDesignerEditors[i] == null) { pickedIndex = i; hasFoundPick = true; break; } } if (!hasFoundPick) { pickedIndex = maxIndex + 1; } } gameDesignerEditors[pickedIndex] = (GameDesignerEditor)EditorWindow.CreateInstance(typeof(GameDesignerEditor)); return(pickedIndex); }
public static void InitProperties(ref CommonGameConfigurations CommonGameConfigurations) { #region Puzzle Common Prefabs AssetFinder.SafeSingleAssetFind(ref CommonGameConfigurations.PuzzleLevelCommonPrefabs.GameManagerPersistanceInstance, "_GameManagers_Persistance_Instanciater"); AssetFinder.SafeSingleAssetFind(ref CommonGameConfigurations.PuzzleLevelCommonPrefabs.CorePuzzleSceneElements, "CorePuzzleSceneElements"); AssetFinder.SafeSingleAssetFind(ref CommonGameConfigurations.PuzzleLevelCommonPrefabs.BasePuzzleLevelDynamics, "BasePuzzleLevelDynamics"); AssetFinder.SafeSingleAssetFind(ref CommonGameConfigurations.PuzzleLevelCommonPrefabs.BaseLevelChunkPrefab, "BaseLevelprefab"); #endregion //TODO configuration initialization if (CommonGameConfigurations.Configurations.Count == 0) { foreach (var configurationType in TypeHelper.GetAllGameConfigurationTypes()) { CommonGameConfigurations.Configurations.Add(configurationType, (IConfigurationSerialization)AssetFinder.SafeAssetFind("t:" + configurationType.Name)[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(); } }