Created
May 14, 2017 20:34
-
-
Save kubawich/1c2b4f1c8e7917c042bdf0589efe7597 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
using UnityEditorInternal; | |
using System; | |
[CustomEditor(typeof(_Quest_Manager))] | |
public class _Quest_Manager_Editor : Editor { | |
SerializedProperty _Quest_Manager; | |
SerializedProperty _Quest_Objectives; | |
_Quest_Manager db; | |
ReorderableList objectivesList; | |
_Quest_Objectives quest_objectives | |
{ | |
get | |
{ | |
return target as _Quest_Objectives; | |
} | |
} | |
void OnEnable () { | |
db = (_Quest_Manager)target; | |
_Quest_Manager = serializedObject.FindProperty("_Quest_Manager"); | |
_Quest_Objectives = serializedObject.FindProperty("_Quest_Objectives"); | |
} | |
public override void OnInspectorGUI () { | |
serializedObject.Update(); | |
//Add/remove buttons | |
GUILayout.BeginHorizontal("box"); | |
if (GUILayout.Button("Add quest")) | |
{ | |
addQuest(); | |
return; | |
} | |
if (GUILayout.Button("Remove all quests")) | |
removeQuests(); | |
GUILayout.EndHorizontal(); | |
GUILayout.Space(10f); | |
//All quests listed | |
questQueryDisplay(); | |
} | |
void newList() | |
{ | |
objectivesList = new ReorderableList(quest_objectives.objectives, typeof(_Objective_Element), true, false, true, true); | |
objectivesList.drawElementCallback += DrawElement; | |
objectivesList.onAddCallback += AddItem; | |
objectivesList.onRemoveCallback += RemoveItem; | |
objectivesList.DoLayoutList(); | |
} | |
void questQueryDisplay() | |
{ | |
for (int i = 0; i < db.QuestList.Count; i++) | |
{ | |
newList(); | |
} | |
} | |
private void DrawElement(Rect rect, int index, bool isActive, bool isFocused) | |
{ | |
_Objective_Element item = quest_objectives.objectives[index]; | |
EditorGUI.BeginChangeCheck(); | |
item._finished = EditorGUI.Toggle(new Rect(rect.x, rect.y, 18, rect.height), item._finished); | |
item.destination = EditorGUILayout.ObjectField(item.destination, typeof(UnityEngine.Object), true); | |
item.amount = EditorGUILayout.DelayedIntField(item.amount); | |
if (EditorGUI.EndChangeCheck()) | |
{ | |
EditorUtility.SetDirty(target); | |
} | |
} | |
private void AddItem(ReorderableList list) | |
{ | |
quest_objectives.objectives.Add(new _Objective_Element()); | |
EditorUtility.SetDirty(target); | |
} | |
private void RemoveItem(ReorderableList list) | |
{ | |
quest_objectives.objectives.RemoveAt(list.index); | |
EditorUtility.SetDirty(target); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment