private void EditSkills() { EditorGUILayout.Space(); EditorGUILayout.LabelField("Skills"); EditorGUILayout.LabelField("To give a skill a higher chance of being"); EditorGUILayout.LabelField("used add it in multiple times."); EditorGUILayout.Space(); SerializedObject skills = new SerializedObject(Selection.activeGameObject.GetComponent <EnemySkills>()); SerializedProperty skillList = skills.FindProperty("skillNames"); if (!SkillDatabase.isLoaded) { SkillDatabase.LoadSkills(); } int skillCount = skillList.arraySize; int deleteTarget = -1; for (int i = 0; i < skillCount; i++) { SerializedProperty currentSkillName = skillList.GetArrayElementAtIndex(i); SkillDescriptor currentSkill = SkillDatabase.GetSkill(currentSkillName.stringValue); GUILayout.BeginHorizontal(); GUILayout.Label(currentSkill.displayText); if (GUILayout.Button("Remove")) { deleteTarget = i; } GUILayout.EndHorizontal(); } if (deleteTarget > -1) { skillList.DeleteArrayElementAtIndex(deleteTarget); } //put all skills into a combo box for selection List <SkillDescriptor> allSkills = SkillDatabase.GetAllSkills(); string[] skillDisplay = new string[allSkills.Count]; for (int i = 0; i < allSkills.Count; i++) { skillDisplay[i] = allSkills[i].displayText; } GUILayout.BeginHorizontal(); currentSelectedPopUpSkill = EditorGUILayout.Popup(currentSelectedPopUpSkill, skillDisplay); if (GUILayout.Button("Add")) { int targetIndex = skillList.arraySize; skillList.InsertArrayElementAtIndex(targetIndex); SerializedProperty newSkill = skillList.GetArrayElementAtIndex(targetIndex); newSkill.stringValue = allSkills[currentSelectedPopUpSkill].name; } skills.ApplyModifiedProperties(); }
// Use this for initialization void Start() { if (!SkillDatabase.isLoaded) { SkillDatabase.LoadSkills(); } skills = new SkillDescriptor[skillNames.Length]; for (int i = 0; i < skillNames.Length; i++) { skills[i] = SkillDatabase.GetSkill(skillNames[i]); } }
private void OnGUI() { // Display items /* * "Skills" label at top left * Search text box * Results box with selectable items, vertical scrolling * Right panel * "Name" label and text box * "Display" label and text box * "Delay" label and text box * "Targets" label and enumeration multi-select * "Start Target" label and enumeration single-select * "Retargetable" label and checkbox * "Effects" label * Vertical scrolling area with effect controls * New Effect button * Create button, creates a new skill * When a change has been made, a Save and Revert button are shown as enabled */ listItemStyle.normal.background = Texture2D.blackTexture; // Not that it shows up, awesome listItemStyle.normal.textColor = Color.white; selectedItemStyle.normal.background = Texture2D.whiteTexture; selectedItemStyle.normal.textColor = Color.blue; bool newSkillClicked = false; string newSkillName = string.Empty; if (GUI.Button(new Rect(30, 370, 100, 20), "New Skill")) { SkillDescriptor newSkill = new SkillDescriptor(); newSkillName = newSkill.name; SkillDatabase.UpdateSkill(newSkill); newSkillClicked = true; } GUI.Box(new Rect(10, 50, 140, 300), string.Empty); GUI.Label(new Rect(10, 10, 40, 15), "Skills"); GUI.SetNextControlName("txtSearch"); if (newSkillClicked) { searchText = string.Empty; } searchText = GUI.TextField(new Rect(10, 30, 90, 15), searchText); if (GUI.GetNameOfFocusedControl() != "txtSearch" && searchText.Length == 0) { GUI.Label(new Rect(10, 30, 90, 15), "(Search)"); } List <string> skillNames = SkillDatabase.FindSkills(searchText); skillListScrollPosition = GUI.BeginScrollView(new Rect(10, 50, 140, 300), skillListScrollPosition, new Rect(0, 0, 120, skillNames.Count * 20)); if (newSkillClicked) { selectedSkillName = newSkillName; } string startSelectionName = selectedSkillName; int yButton = 10, skillIndex = 0; foreach (string skillName in skillNames) { if (GUI.Button(new Rect(5, yButton, 130, 15), skillName, selectedSkillName == skillName ? selectedItemStyle : listItemStyle)) { selectedSkillName = skillName; } yButton += 20; skillIndex++; } if (startSelectionName != selectedSkillName) { EditorGUI.FocusTextInControl(null); Repaint(); } selectedSkill = SkillDatabase.GetSkill(selectedSkillName); GUI.EndScrollView(); GUI.Box(new Rect(160, 10, 700, 400), string.Empty); if (selectedSkill != null) { mainControlRectY = 20; // TODO: Set up the skill display itself, and wire up components to variables. // Then, create the save/load function. Going to be cool! string originalName = selectedSkill.name; selectedSkill.name = EditorGUI.TextField(MainControlRect(), "Name", selectedSkill.name); if (originalName != selectedSkill.name) { SkillDatabase.RenameSkill(originalName, selectedSkill); selectedSkillName = selectedSkill.name; } selectedSkill.displayText = EditorGUI.TextField(MainControlRect(), "Display Text", selectedSkill.displayText); selectedSkill.delay = EditorGUI.FloatField(MainControlRect(), "Action Delay", selectedSkill.delay); //EditorGUI.LabelField(new Rect(130, y, 100, 15), "Targets"); // The dance of the target options. // First, figure out what our default selection is - because it might forcibly change right after this. // Get the list of currently available flags, and use the selectedDefaultIndex value to figure out // which one is selected in the editor. List <CommandBase.Target> flags = new List <CommandBase.Target>(); foreach (CommandBase.Target target in (CommandBase.Target[])System.Enum.GetValues(typeof(CommandBase.Target))) { if ((selectedSkill.targets & target) > 0) { flags.Add(target); } } CommandBase.Target selectedDefaultTarget = CommandBase.Target.NONE; if (selectedDefaultIndex < flags.Count) { selectedDefaultTarget = flags[selectedDefaultIndex]; } // Now show the targets enum flags field to pick up changes. selectedSkill.targets = (CommandBase.Target)(EditorGUI.EnumFlagsField(MainControlRect(), "Targets", selectedSkill.targets)); // Now, re-fetch the list of available targets. flags.Clear(); foreach (CommandBase.Target target in (CommandBase.Target[])System.Enum.GetValues(typeof(CommandBase.Target))) { if ((selectedSkill.targets & target) > 0) { flags.Add(target); } } if (flags.Count > 0) { // Is our selected default value still in here? If so, make sure we're still pointing at it; otherwise, point at the first item in the list. if (flags.Contains(selectedDefaultTarget)) { selectedDefaultIndex = flags.IndexOf(selectedDefaultTarget); } else { selectedDefaultIndex = 0; } // Now convert the flags to strings so we can display them in a popup. List <string> flagStrings = new List <string>(); foreach (CommandBase.Target flag in flags) { flagStrings.Add(flag.ToString()); } selectedDefaultIndex = EditorGUI.Popup(MainControlRect(), "Default target", selectedDefaultIndex, flagStrings.ToArray()); if (selectedDefaultIndex < flags.Count) { selectedDefaultTarget = flags[selectedDefaultIndex]; } } selectedSkill.isRetargetable = EditorGUI.Toggle(MainControlRect(), "Retargetable", selectedSkill.isRetargetable); mainControlRectY += 40; EditorGUI.LabelField(MainControlRect(), "Effects"); EffectDescriptor killed = null; if (selectedSkill.effects != null) { foreach (EffectDescriptor effect in selectedSkill.effects) { if (RenderEffectFieldWithDelete(effect)) { // Deleted killed = effect; } } if (killed != null) { selectedSkill.RemoveEffect(killed); } } EditorGUI.LabelField(new Rect(170, mainControlRectY, 100, 15), "Add effect type"); List <string> effectNames = new List <string>(); foreach (string key in effectsByName.Keys) { effectNames.Add(key); } selectedNewEffectType = EditorGUI.Popup(new Rect(280, mainControlRectY, 100, 15), selectedNewEffectType, effectNames.ToArray()); if (GUI.Button(new Rect(390, mainControlRectY, 70, 15), "Add")) { EffectDescriptor newDescriptor = new EffectDescriptor(); newDescriptor.effectType = effectsByName[effectNames[selectedNewEffectType]]; newDescriptor.effectExpression = string.Empty; selectedSkill.AddEffect(newDescriptor); } SkillDatabase.SaveSkills(); } }