public ContractContent() { Tier = 1; Title = ""; Description = ""; Objectives = new Objective[2]; //Default objectives to kill target Objectives[0] = new ObjectiveKillTarget(); Objectives[1] = new ObjectiveTurnInContract(); }
protected void ObjectivesArea(ref List <Objective> list) { Type[] ObjectiveTypes = GetAllObjectiveTypes(); string[] ObjectiveStrings = GetAllObjectiveStrings(); List <string> ObjectiveStringList = ObjectiveStrings.ToList(); int listCount = list.Count; int newCount = EditorGUILayout.IntField("Objective Count", listCount); Objective[] array = new Objective[newCount]; if (listCount != newCount) { if (listCount < newCount) { for (int i = 0; i < listCount; i++) { array[i] = list[i]; } } } for (int i = 0; i < newCount; i++) { EditorGUILayout.BeginHorizontal(); Objective objective = list.ElementAtOrDefault(i); if (objective == null) { objective = new ObjectiveTurnInContract(); } //Dropdown for the objective type Type objectiveType = objective.GetType(); int currentTypeIndex = ObjectiveStringList.IndexOf(objectiveType.ToString()); int newIndex = EditorGUILayout.Popup(currentTypeIndex, ObjectiveStrings, GUILayout.Width(150)); if (newIndex != currentTypeIndex) { objectiveType = (ObjectiveTypes[newIndex]); objective = (Objective)Activator.CreateInstance(objectiveType); } ObjectiveArea(ref objective, objectiveType); array[i] = objective; EditorGUILayout.EndHorizontal(); } list = array.ToList(); }
protected void ObjectivesArea(ref List<Objective> list) { Type[] ObjectiveTypes = GetAllObjectiveTypes(); string[] ObjectiveStrings = GetAllObjectiveStrings(); List<string> ObjectiveStringList = ObjectiveStrings.ToList(); int listCount = list.Count; int newCount = EditorGUILayout.IntField("Objective Count", listCount); Objective[] array = new Objective[newCount]; if (listCount != newCount) { if (listCount < newCount) for (int i = 0; i < listCount; i++) array[i] = list[i]; } for (int i = 0; i < newCount; i++) { EditorGUILayout.BeginHorizontal(); Objective objective = list.ElementAtOrDefault(i); if (objective == null) objective = new ObjectiveTurnInContract(); //Dropdown for the objective type Type objectiveType = objective.GetType(); int currentTypeIndex = ObjectiveStringList.IndexOf(objectiveType.ToString()); int newIndex = EditorGUILayout.Popup(currentTypeIndex, ObjectiveStrings, GUILayout.Width(150)); if (newIndex != currentTypeIndex) { objectiveType = (ObjectiveTypes[newIndex]); objective = (Objective)Activator.CreateInstance(objectiveType); } ObjectiveArea(ref objective, objectiveType); array[i] = objective; EditorGUILayout.EndHorizontal(); } list = array.ToList(); }