public static void ConditionSelector(this Mission mission, string label, ref bool fold, ref MissionCondition cond, ref MissionCondition.ConditionType type) { bool foldChanged = false; EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); fold = EditorGUILayout.Foldout(fold, new GUIContent(label)); if (EditorGUI.EndChangeCheck()) { foldChanged = true; } EditorGUI.BeginChangeCheck(); type = (MissionCondition.ConditionType)EditorGUILayout.EnumPopup(type); if (EditorGUI.EndChangeCheck()) { if (cond != null) { if (AssetDatabase.GetAssetPath(cond) == AssetDatabase.GetAssetPath(mission)) { GameObject.DestroyImmediate(cond, true); } cond = null; fold = false; } switch (type) { case MissionCondition.ConditionType.TeamsDead: cond = TeamsDeadCondition.CreateInstance <TeamsDeadCondition>(); break; case MissionCondition.ConditionType.UnitsDead: cond = UnitsDeadCondition.CreateInstance <UnitsDeadCondition>(); break; case MissionCondition.ConditionType.UnitsDeadAmount: cond = UnitsAliveCondition.CreateInstance <UnitsAliveCondition>(); break; case MissionCondition.ConditionType.PointReached: cond = PointReachedCondition.CreateInstance <PointReachedCondition>(); break; case MissionCondition.ConditionType.Custom: break; case MissionCondition.ConditionType.TurnsPassed: cond = TurnsPassedCondition.CreateInstance <TurnsPassedCondition>(); break; default: break; } if (cond) { fold = true; cond.conditionType = type; cond.name = cond.GetType().ToString(); //Hide the file cond.hideFlags = HideFlags.HideInHierarchy; //Attatch file to the Mission ScriptableObject AssetDatabase.AddObjectToAsset(cond, mission); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(cond)); } AssetDatabase.SaveAssets(); } EditorGUILayout.EndHorizontal(); MissionCondition condition = cond; if (fold) { if (cond != null) { if (MissionConditionEditor.cachedEditors.ContainsKey(cond) && MissionConditionEditor.cachedEditors[cond] != null) { MissionConditionEditor.cachedEditors[cond].OnInspectorGUI(); } else { //Create editor for the condition Editor ConditionEditor = Editor.CreateEditor(condition); //See if the Inpector can be casted to MissionConditionEditor if (ConditionEditor as MissionConditionEditor != null) { //Initialize custom condition editor ((MissionConditionEditor)ConditionEditor).Init(mission); } //Draw the editor ConditionEditor.OnInspectorGUI(); } } else { EditorGUI.indentLevel++; cond = EditorGUILayout.ObjectField("Custom Condition", cond, typeof(MissionCondition), false) as MissionCondition; EditorGUI.indentLevel--; } } if (foldChanged && cond != null && MissionConditionEditor.cachedEditors.ContainsKey(cond) && MissionConditionEditor.cachedEditors[cond] != null) { if (MissionConditionEditor.cachedEditors[cond] as MissionConditionEditor != null) { if (fold) { MissionConditionEditor.cachedEditors[cond].Show(); } else { MissionConditionEditor.cachedEditors[cond].Hide(); } } } }
public static void OnGUI(this MissionEventContainer cont, Dictionary <MissionEvent, MissionEventEditor> editors, Mission miss = null) { EditorGUILayout.BeginHorizontal(); cont.MainFold = EditorGUILayout.Foldout(cont.MainFold, cont.editorName, true); EditorGUI.BeginChangeCheck(); if (GUILayout.Button("+", GUILayout.Width(25))) { GenericMenu CreateMenu = new GenericMenu(); CreateMenu.AddItem(new GUIContent("Kill Character"), false, AddEventMenu, new object[] { cont, typeof(ME_KillCharacter), miss }); CreateMenu.AddItem(new GUIContent("Give Item"), false, AddEventMenu, new object[] { cont, typeof(ME_GiveItem), miss }); CreateMenu.AddItem(new GUIContent("Visu 16"), false, AddEventMenu, new object[] { cont, typeof(ME_Visu16), miss }); CreateMenu.ShowAsContext(); } EditorGUILayout.EndHorizontal(); if (cont.MainFold) { EditorGUI.indentLevel++; MissionCondition.ConditionType t = cont.cond == null ? MissionCondition.ConditionType.Custom : cont.cond.conditionType; miss.ConditionSelector("Trigger when", ref cont.conditionFold, ref cont.cond, ref t); EditorGUILayout.Space(); EditorGUILayout.LabelField("Events", EditorStyles.boldLabel); for (int i = 0; i < cont.allEvents.Count; i++) { if (!cont.EditorFolds.ContainsKey(cont.allEvents[i])) { cont.UpdateDictionary(); } } int deleteIndex = -1; for (int i = 0; i < cont.allEvents.Count; i++) { if (cont.allEvents[i] != null) { EditorGUILayout.BeginHorizontal(); cont.EditorFolds[cont.allEvents[i]] = EditorGUILayout.Foldout(cont.EditorFolds[cont.allEvents[i]], cont.allEvents[i].editorName + " (" + (cont.allEvents[i]).GetType().Name + ")"); GUILayout.FlexibleSpace(); if (GUILayout.Button("X", GUILayout.Width(20))) { deleteIndex = i; } EditorGUI.BeginDisabledGroup(i == 0); if (GUILayout.Button("^", GUILayout.Width(20))) { cont.allEvents[i].listIndex--; cont.allEvents[i - 1].listIndex++; MissionEvent evt = cont.allEvents[i]; cont.allEvents[i] = cont.allEvents[i - 1]; cont.allEvents[i - 1] = evt; } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(i == cont.allEvents.Count - 1); if (GUILayout.Button("v", GUILayout.Width(20))) { cont.allEvents[i].listIndex++; cont.allEvents[i + 1].listIndex--; MissionEvent evt = cont.allEvents[i]; cont.allEvents[i] = cont.allEvents[i + 1]; cont.allEvents[i + 1] = evt; } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUI.indentLevel++; GUILayout.Space(20 * EditorGUI.indentLevel); if (cont.EditorFolds[cont.allEvents[i]]) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); editors[cont.allEvents[i]].OnGUI(); EditorGUILayout.EndVertical(); } EditorGUI.indentLevel--; EditorGUILayout.EndHorizontal(); } } if (deleteIndex != -1) { cont.EditorFolds.Remove(cont.allEvents[deleteIndex]); cont.allEvents.RemoveAt(deleteIndex); cont.Save(); } EditorGUI.indentLevel--; } }
private void initialize(MissionEvent evt, Mission miss) { this.target = evt; this.miss = miss; }
public void Init(Mission mission) { missionBeingEdited = mission; cachedEditors.Add((MissionCondition)target, this); }