public override void OnInspectorGUI() { //Update our list GetTarget.Update(); //Choose how to display the list<> Example purposes only EditorGUILayout.Space(); EditorGUILayout.Space(); DisplayFieldType = (displayFieldType)EditorGUILayout.EnumPopup("", DisplayFieldType); //Resize our list EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Define the list size with a number"); ListSize = ThisList.arraySize; ListSize = EditorGUILayout.IntField("List Size", ListSize); if (ListSize != ThisList.arraySize) { while (ListSize > ThisList.arraySize) { ThisList.InsertArrayElementAtIndex(ThisList.arraySize); } while (ListSize < ThisList.arraySize) { ThisList.DeleteArrayElementAtIndex(ThisList.arraySize - 1); } } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Or"); EditorGUILayout.Space(); EditorGUILayout.Space(); //Or add a new item to the List<> with a button EditorGUILayout.LabelField("Add a new item with a button"); if (GUILayout.Button("Add New")) { t.MyList.Add(new CustomList.MyClass()); } EditorGUILayout.Space(); EditorGUILayout.Space(); //Display our list to the inspector window for (int i = 0; i < ThisList.arraySize; i++) { SerializedProperty MyListRef = ThisList.GetArrayElementAtIndex(i); SerializedProperty MyInt = MyListRef.FindPropertyRelative("AnInt"); SerializedProperty MyFloat = MyListRef.FindPropertyRelative("AnFloat"); SerializedProperty MyVect3 = MyListRef.FindPropertyRelative("AnVector3"); SerializedProperty MyGO = MyListRef.FindPropertyRelative("AnGO"); SerializedProperty MyArray = MyListRef.FindPropertyRelative("AnIntArray"); // Display the property fields in two ways. if (DisplayFieldType == 0) {// Choose to display automatic or custom field types. This is only for example to help display automatic and custom fields. //1. Automatic, No customization <-- Choose me I'm automatic and easy to setup EditorGUILayout.LabelField("Automatic Field By Property Type"); EditorGUILayout.PropertyField(MyGO); EditorGUILayout.PropertyField(MyInt); EditorGUILayout.PropertyField(MyFloat); EditorGUILayout.PropertyField(MyVect3); // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Array Fields"); if (GUILayout.Button("Add New Index", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) { MyArray.InsertArrayElementAtIndex(MyArray.arraySize); MyArray.GetArrayElementAtIndex(MyArray.arraySize - 1).intValue = 0; } for (int a = 0; a < MyArray.arraySize; a++) { EditorGUILayout.PropertyField(MyArray.GetArrayElementAtIndex(a)); if (GUILayout.Button("Remove (" + a.ToString() + ")", GUILayout.MaxWidth(100), GUILayout.MaxHeight(15))) { MyArray.DeleteArrayElementAtIndex(a); } } } else { //Or //2 : Full custom GUI Layout <-- Choose me I can be fully customized with GUI options. EditorGUILayout.LabelField("Customizable Field With GUI"); MyGO.objectReferenceValue = EditorGUILayout.ObjectField("My Custom Go", MyGO.objectReferenceValue, typeof(GameObject), true); MyInt.intValue = EditorGUILayout.IntField("My Custom Int", MyInt.intValue); MyFloat.floatValue = EditorGUILayout.FloatField("My Custom Float", MyFloat.floatValue); MyVect3.vector3Value = EditorGUILayout.Vector3Field("My Custom Vector 3", MyVect3.vector3Value); // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Array Fields"); if (GUILayout.Button("Add New Index", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) { MyArray.InsertArrayElementAtIndex(MyArray.arraySize); MyArray.GetArrayElementAtIndex(MyArray.arraySize - 1).intValue = 0; } for (int a = 0; a < MyArray.arraySize; a++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("My Custom Int (" + a.ToString() + ")", GUILayout.MaxWidth(120)); MyArray.GetArrayElementAtIndex(a).intValue = EditorGUILayout.IntField("", MyArray.GetArrayElementAtIndex(a).intValue, GUILayout.MaxWidth(100)); if (GUILayout.Button("-", GUILayout.MaxWidth(15), GUILayout.MaxHeight(15))) { MyArray.DeleteArrayElementAtIndex(a); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.Space(); //Remove this index from the List EditorGUILayout.LabelField("Remove an index from the List<> with a button"); if (GUILayout.Button("Remove This Index (" + i.ToString() + ")")) { ThisList.DeleteArrayElementAtIndex(i); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); } //Apply the changes to our list GetTarget.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { //Update our list GetTarget.Update(); //Choose how to display the list<> Example purposes only EditorGUILayout.Space(); EditorGUILayout.Space(); DisplayFieldType = (displayFieldType)EditorGUILayout.EnumPopup("", DisplayFieldType); //Resize our list EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Define the list size with a number"); ListSize = ThisList.arraySize; ListSize = EditorGUILayout.IntField("List Size", ListSize); if (ListSize != ThisList.arraySize) { while (ListSize > ThisList.arraySize) { ThisList.InsertArrayElementAtIndex(ThisList.arraySize); } while (ListSize < ThisList.arraySize) { ThisList.DeleteArrayElementAtIndex(ThisList.arraySize - 1); } } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Or"); EditorGUILayout.Space(); EditorGUILayout.Space(); //Or add a new item to the List<> with a button EditorGUILayout.LabelField("Add a new item with a button"); //if (GUILayout.Button("Add New")) //{ // t.MyList.Add(new CustomList.MyClass()); //} EditorGUILayout.Space(); EditorGUILayout.Space(); //Display our list to the inspector window for (int i = 0; i < ThisList.arraySize; i++) { SerializedProperty MyListRef = ThisList.GetArrayElementAtIndex(i); SerializedProperty CardName = MyListRef.FindPropertyRelative("name"); SerializedProperty CardDescription = MyListRef.FindPropertyRelative("description"); SerializedProperty CardSprite = MyListRef.FindPropertyRelative("sprite"); // Display the property fields in two ways. if (DisplayFieldType == 0) {// Choose to display automatic or custom field types. This is only for example to help display automatic and custom fields. //1. Automatic, No customization <-- Choose me I'm automatic and easy to setup EditorGUILayout.LabelField("Automatic Field By Property Type"); EditorGUILayout.PropertyField(CardName); EditorGUILayout.PropertyField(CardDescription); EditorGUILayout.PropertyField(CardSprite); // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); //if (GUILayout.Button("Add New Index", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) //{ // MyArray.InsertArrayElementAtIndex(MyArray.arraySize); // MyArray.GetArrayElementAtIndex(MyArray.arraySize - 1).intValue = 0; //} //for (int a = 0; a < MyArray.arraySize; a++) //{ // EditorGUILayout.PropertyField(MyArray.GetArrayElementAtIndex(a)); // if (GUILayout.Button("Remove (" + a.ToString() + ")", GUILayout.MaxWidth(100), GUILayout.MaxHeight(15))) // { // MyArray.DeleteArrayElementAtIndex(a); // } //} } else { //Or //2 : Full custom GUI Layout <-- Choose me I can be fully customized with GUI options. EditorGUILayout.LabelField("Customizable Field With GUI"); CardName.stringValue = EditorGUILayout.TextField("Name", CardName.stringValue); CardDescription.stringValue = EditorGUILayout.TextField("Description", CardDescription.stringValue); CardSprite.stringValue = EditorGUILayout.TextField("SpriteFile", CardSprite.stringValue); // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Array Fields"); //if (GUILayout.Button("Add New Index", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) //{ // MyArray.InsertArrayElementAtIndex(MyArray.arraySize); // MyArray.GetArrayElementAtIndex(MyArray.arraySize - 1).intValue = 0; //} //for (int a = 0; a < MyArray.arraySize; a++) //{ // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("My Custom Int (" + a.ToString() + ")", GUILayout.MaxWidth(120)); // MyArray.GetArrayElementAtIndex(a).intValue = EditorGUILayout.IntField("", MyArray.GetArrayElementAtIndex(a).intValue, GUILayout.MaxWidth(100)); // if (GUILayout.Button("-", GUILayout.MaxWidth(15), GUILayout.MaxHeight(15))) // { // MyArray.DeleteArrayElementAtIndex(a); // } // EditorGUILayout.EndHorizontal(); //} } EditorGUILayout.Space(); //Remove this index from the List EditorGUILayout.LabelField("Remove an index from the List<> with a button"); if (GUILayout.Button("Remove This Index (" + i.ToString() + ")")) { ThisList.DeleteArrayElementAtIndex(i); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); } //Apply the changes to our list GetTarget.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { //Update our list GetTarget.Update(); //Choose how to display the list<> Example purposes only EditorGUILayout.Space(); EditorGUILayout.Space(); DisplayFieldType = (displayFieldType)EditorGUILayout.EnumPopup("", DisplayFieldType); //Resize our list EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Define the list size with a number"); ListSize = ThisList.arraySize; ListSize = EditorGUILayout.IntField("List Size", ListSize); if (ListSize != ThisList.arraySize) { while (ListSize > ThisList.arraySize) { ThisList.InsertArrayElementAtIndex(ThisList.arraySize); } while (ListSize < ThisList.arraySize) { ThisList.DeleteArrayElementAtIndex(ThisList.arraySize - 1); } } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Or"); EditorGUILayout.Space(); EditorGUILayout.Space(); //Or add a new item to the List<> with a button EditorGUILayout.LabelField("Add a new item with a button"); if (GUILayout.Button("Add New")) { TrackInstance.NoteList.Add(new TrackInstance.SOF()); } EditorGUILayout.Space(); EditorGUILayout.Space(); //Display our list to the inspector window for (int i = 0; i < ThisList.arraySize; i++) { SerializedProperty MyListRef = ThisList.GetArrayElementAtIndex(i); SerializedProperty MyS = MyListRef.FindPropertyRelative("S"); SerializedProperty MyO = MyListRef.FindPropertyRelative("O"); SerializedProperty MyF = MyListRef.FindPropertyRelative("F"); // Display the property fields in two ways. if (DisplayFieldType == 0) {// Choose to display automatic or custom field types. This is only for example to help display automatic and custom fields. //1. Automatic, No customization <-- Choose me I'm automatic and easy to setup EditorGUILayout.LabelField("Automatic Field By Property Type"); EditorGUILayout.PropertyField(MyS); EditorGUILayout.PropertyField(MyO); EditorGUILayout.PropertyField(MyF); } else { //Or //2 : Full custom GUI Layout <-- Choose me I can be fully customized with GUI options. EditorGUILayout.LabelField("Customizable Field With GUI"); MyS.intValue = EditorGUILayout.IntField("Step", MyS.intValue); MyO.intValue = EditorGUILayout.IntField("Octave", MyO.intValue); MyF.intValue = EditorGUILayout.IntField("Frames", MyF.intValue); } EditorGUILayout.Space(); //Remove this index from the List EditorGUILayout.LabelField("Remove an index from the List<> with a button"); if (GUILayout.Button("Remove This Index (" + i.ToString() + ")")) { ThisList.DeleteArrayElementAtIndex(i); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); } //Apply the changes to our list GetTarget.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { if (GetTarget == null) { GetTarget = new SerializedObject((SpawnController)target); } if (ThisList == null) { ThisList = GetTarget.FindProperty("minionWays"); } // Update our list GetTarget.Update(); // Choose how to display the list<> Example purposes only EditorGUILayout.Space(); EditorGUILayout.Space(); DisplayFieldType = (displayFieldType)EditorGUILayout.EnumPopup("", DisplayFieldType); // Resize our list EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Define the list size with a number"); ListSize = ThisList.arraySize; ListSize = EditorGUILayout.IntField("List Size", ListSize); if (ListSize != ThisList.arraySize) { while (ListSize > ThisList.arraySize) { ThisList.InsertArrayElementAtIndex(ThisList.arraySize); } while (ListSize < ThisList.arraySize) { ThisList.DeleteArrayElementAtIndex(ThisList.arraySize - 1); } } // EditorGUILayout.Space(); // EditorGUILayout.Space(); // EditorGUILayout.LabelField ("Or"); // EditorGUILayout.Space(); // EditorGUILayout.Space(); // // // Or add a new item to the List<> with a button // EditorGUILayout.LabelField("Add a new item with a button"); // // if (GUILayout.Button ("Add New")) { // t.minionWays.Add (new SpawnController.Waypoints ()); // } EditorGUILayout.Space(); EditorGUILayout.Space(); // Display our list to the inspector window for (int i = 0; i < ThisList.arraySize; i++) { SerializedProperty MyListRef = ThisList.GetArrayElementAtIndex(i); SerializedProperty MyPoint1 = MyListRef.FindPropertyRelative("point1"); SerializedProperty MyPoint2 = MyListRef.FindPropertyRelative("point2"); // Display the property fields in two ways if (DisplayFieldType == 0) // Choose to display automatic or custom field types. This is only for example to help display automatic and custom fields. // 1. Automatic, No customization <-- Choos me I'm automatic and easy to setup { EditorGUILayout.LabelField("Automatic Field By Property Type"); EditorGUILayout.PropertyField(MyPoint1); EditorGUILayout.PropertyField(MyPoint2); /* Array 표현예시 * // Array fileds with remove at index * EditorGUILayout.Space (); * EditorGUILayout.Space (); * EditorGUILayout.LabelField ("Array Fields"); * * if (GUILayout.Button ("Add New Index", GUILayout.MaxWidth (130), GUILayout.MaxHeight (20))) { * MyArray.InsertArrayElementAtIndex (MyArray.arraySize); * MyArray.GetArrayElementAtIndex (MyArray.arraySize - 1).intValue = 0; * } * * for (int a = 0; a < MyArray.arraySize; a++) { * EditorGUILayout.PropertyField (MyArray.GetArrayElementAtIndex (a)); * if (GUILayout.Button ("Remove (" + a.ToString () + ")", GUILayout.MaxWidth (100), GUILayout.MaxHeight (15))) { * MyArray.DeleteArrayElementAtIndex (a); * } * } */ } else // Or // 2 : Full custom GUI Layout <-- Choose me I can be fully customized with GUI options. { EditorGUILayout.LabelField("Customizable Field With GUI"); MyPoint1.objectReferenceValue = EditorGUILayout.ObjectField("My Custom Point1", MyPoint1.objectReferenceValue, typeof(Transform), true); MyPoint2.objectReferenceValue = EditorGUILayout.ObjectField("My Custom Point2", MyPoint2.objectReferenceValue, typeof(Transform), true); // MyInt.intValue = EditorGUILayout.IntField ("My Custom Int", MyInt.intValue); // MyFloat.floatValue = EditorGUILayout.FloatField("My Custom Float", MyFlaot.floatValue); // MyVector3.vector3Value = EditorGUILayout.Vector3Field("My Custom Vector 3", MyVect3.vector3Value); /* * // Array fileds with remove at index * EditorGUILayout.Space (); * EditorGUILayout.Space (); * EditorGUILayout.LabelField("Array Fields"); * * if (GUILayout.Button("Add New Index", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) { * MyArray.InsertArrayElementAtIndex(MyArray.arraySize); * MyArray.GetArrayElementAtIndex(MyArray.arraySize - 1).intValue = 0; * } * * for (int a = 0; a < MyArray.arraySize; a++) { * EditorGUILayout.BeginHorizontal(); * EditorGUILayout.LabelField("My Custom Int( " + a.ToString() + ")", GUILayout.MaxWidth(120)); * MyArray.GetArrayElementAtIndex(a).intValue = EditorGUILayout.IntField("",MyArray.GetArrayElementAtIndex(a).intValue, GUILayout.MaxWidth(100)); * if(GUILayout.Button("-",GUILayout.MaxWidth(15),GUILayout.MaxHeight(15))){ * MyArray.DeleteArrayElementAtIndex(a); * } * EditorGUILayout.EndHorizontal(); * } */ } EditorGUILayout.Space(); // Remove this index from the List EditorGUILayout.LabelField("Remove an index from the List<> with a button"); if (GUILayout.Button("Remove This Index (" + i.ToString() + ")")) { ThisList.DeleteArrayElementAtIndex(i); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); } // Apply the changes to our list GetTarget.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { base.DrawDefaultInspector(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); //Update our list GetTarget.Update(); //Choose how to display the list<> Example purposes only DisplayFieldType = displayFieldType.DisplayAsCustomizableGUIFields; /* * EditorGUILayout.LabelField("Define the list size with a number"); * ListSize = ThisList.arraySize; * ListSize = EditorGUILayout.IntField("List Size", ListSize); * * if (ListSize != ThisList.arraySize) * { * while (ListSize > ThisList.arraySize) * { * ThisList.InsertArrayElementAtIndex(ThisList.arraySize); * } * while (ListSize < ThisList.arraySize) * { * ThisList.DeleteArrayElementAtIndex(ThisList.arraySize - 1); * } * } * * EditorGUILayout.Space(); * EditorGUILayout.Space(); * EditorGUILayout.LabelField("Or"); * EditorGUILayout.Space(); * EditorGUILayout.Space(); * */ EditorGUILayout.Space(); EditorGUILayout.Space(); //Display our list to the inspector window for (int i = 0; i < rules.arraySize; i++) { SerializedProperty MyListRef = rules.GetArrayElementAtIndex(i); SerializedProperty ruleStory = MyListRef.FindPropertyRelative("ruleStory"); SerializedProperty consumedProperties = MyListRef.FindPropertyRelative("consumedProperties"); SerializedProperty producedProperties = MyListRef.FindPropertyRelative("producedProperties"); // Display the property fields in two ways. if (DisplayFieldType == 0) {// Choose to display automatic or custom field types. This is only for example to help display automatic and custom fields. //1. Automatic, No customization <-- Choose me I'm automatic and easy to setup EditorGUILayout.LabelField("Automatic Field By Property Type"); // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Array Fields"); if (GUILayout.Button("Add New Index", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) { consumedProperties.InsertArrayElementAtIndex(consumedProperties.arraySize); consumedProperties.GetArrayElementAtIndex(consumedProperties.arraySize - 1).intValue = 0; } for (int a = 0; a < consumedProperties.arraySize; a++) { EditorGUILayout.PropertyField(consumedProperties.GetArrayElementAtIndex(a)); if (GUILayout.Button("Remove (" + a.ToString() + ")", GUILayout.MaxWidth(100), GUILayout.MaxHeight(15))) { consumedProperties.DeleteArrayElementAtIndex(a); } } // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Array Fields"); if (GUILayout.Button("Add New Index", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) { producedProperties.InsertArrayElementAtIndex(producedProperties.arraySize); producedProperties.GetArrayElementAtIndex(producedProperties.arraySize - 1).intValue = 0; } for (int a = 0; a < producedProperties.arraySize; a++) { EditorGUILayout.PropertyField(producedProperties.GetArrayElementAtIndex(a)); if (GUILayout.Button("Remove (" + a.ToString() + ")", GUILayout.MaxWidth(100), GUILayout.MaxHeight(15))) { producedProperties.DeleteArrayElementAtIndex(a); } } } else { //Or //2 : Full custom GUI Layout <-- Choose me I can be fully customized with GUI options. EditorGUILayout.LabelField("Rule #" + (i).ToString()); // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Rule story", GUILayout.MaxWidth(80)); ruleStory.stringValue = EditorGUILayout.TextField("", ruleStory.stringValue); EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("Consumed Properties"); if (GUILayout.Button("Add New Consumed Property", GUILayout.MaxWidth(200), GUILayout.MaxHeight(20))) { consumedProperties.InsertArrayElementAtIndex(consumedProperties.arraySize); consumedProperties.GetArrayElementAtIndex(consumedProperties.arraySize - 1).intValue = 0; } for (int a = 0; a < consumedProperties.arraySize; a++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Actor (" + a.ToString() + ")", GUILayout.MaxWidth(80)); // consumedProperties.GetArrayElementAtIndex(a).intValue = EditorGUILayout.IntField("", consumedProperties.GetArrayElementAtIndex(a).intValue, GUILayout.MaxWidth(100)); consumedProperties.GetArrayElementAtIndex(a).intValue = EditorGUILayout.Popup("", consumedProperties.GetArrayElementAtIndex(a).intValue, t.Actors.ToArray(), GUILayout.MaxWidth(150)); if (GUILayout.Button("-", GUILayout.MaxWidth(15), GUILayout.MaxHeight(15))) { consumedProperties.DeleteArrayElementAtIndex(a); } EditorGUILayout.EndHorizontal(); } // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Produced Properties"); if (GUILayout.Button("Add New Produced Property", GUILayout.MaxWidth(200), GUILayout.MaxHeight(20))) { producedProperties.InsertArrayElementAtIndex(producedProperties.arraySize); producedProperties.GetArrayElementAtIndex(producedProperties.arraySize - 1).intValue = 0; } for (int a = 0; a < producedProperties.arraySize; a++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Actor (" + a.ToString() + ")", GUILayout.MaxWidth(80)); // consumedProperties.GetArrayElementAtIndex(a).intValue = EditorGUILayout.IntField("", consumedProperties.GetArrayElementAtIndex(a).intValue, GUILayout.MaxWidth(100)); producedProperties.GetArrayElementAtIndex(a).intValue = EditorGUILayout.Popup("", producedProperties.GetArrayElementAtIndex(a).intValue, t.Actors.ToArray(), GUILayout.MaxWidth(150)); if (GUILayout.Button("-", GUILayout.MaxWidth(15), GUILayout.MaxHeight(15))) { producedProperties.DeleteArrayElementAtIndex(a); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.Space(); //Remove this index from the List if (GUILayout.Button("Remove Rule #" + (i).ToString())) { rules.DeleteArrayElementAtIndex(i); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); } //Or add a new item to the List<> with a button EditorGUILayout.LabelField("Add a new rule with a button"); if (GUILayout.Button("Add New")) { t.Rules.Add(new LoreRule()); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Set Init list EditorGUILayout.LabelField("Initial Story State"); EditorGUILayout.Space(); EditorGUILayout.Space(); for (int i = 0; i < init.arraySize; i++) { // Display the property fields in two ways. if (DisplayFieldType == 0) {// Choose to display automatic or custom field types. This is only for example to help display automatic and custom fields. //1. Automatic, No customization <-- Choose me I'm automatic and easy to setup } else { //Or EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Actor (" + i.ToString() + ")", GUILayout.MaxWidth(80)); init.GetArrayElementAtIndex(i).intValue = EditorGUILayout.Popup("", init.GetArrayElementAtIndex(i).intValue, t.Actors.ToArray(), GUILayout.MaxWidth(150)); if (GUILayout.Button("-", GUILayout.MaxWidth(15), GUILayout.MaxHeight(15))) { init.DeleteArrayElementAtIndex(i); } EditorGUILayout.EndHorizontal(); } } //Or add a new item to the List<> with a button EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("", GUILayout.MaxWidth(80)); if (GUILayout.Button("Add new", GUILayout.MaxWidth(150))) { t.Init.Add(0); } EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); //Apply the changes to our list GetTarget.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { //Update our list GetTarget.Update(); //Choose how to display the list<> Example purposes only EditorGUILayout.Space(); EditorGUILayout.Space(); DisplayFieldType = (displayFieldType)EditorGUILayout.EnumPopup("", DisplayFieldType); //Resize our list EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Define the list size with a number"); ListSize = ThisList.arraySize; ListSize = EditorGUILayout.IntField("List Size", ListSize); if (ListSize != ThisList.arraySize) { while (ListSize > ThisList.arraySize) { ThisList.InsertArrayElementAtIndex(ThisList.arraySize); } while (ListSize < ThisList.arraySize) { ThisList.DeleteArrayElementAtIndex(ThisList.arraySize - 1); } } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Or"); EditorGUILayout.Space(); EditorGUILayout.Space(); //Or add a new item to the List<> with a button EditorGUILayout.LabelField("Add a new item with a button"); if (GUILayout.Button("Add New")) { t.lFighters.Add(new Monster()); } EditorGUILayout.Space(); EditorGUILayout.Space(); //Display our list to the inspector window for (int i = 0; i < ThisList.arraySize; i++) { SerializedProperty MyListRef = ThisList.GetArrayElementAtIndex(i); SerializedProperty nID = MyListRef.FindPropertyRelative("nID"); SerializedProperty sName = MyListRef.FindPropertyRelative("sName"); SerializedProperty nHealthMax = MyListRef.FindPropertyRelative("nHealthMax"); SerializedProperty nCurrentHealth = MyListRef.FindPropertyRelative("nCurrentHealth"); SerializedProperty nPower = MyListRef.FindPropertyRelative("nPower"); // SerializedProperty nFearPower = MyListRef.FindPropertyRelative("nFearPower"); SerializedProperty bIsImportant = MyListRef.FindPropertyRelative("bIsImportant"); // Display the property fields in two ways. if (DisplayFieldType == 0) {// Choose to display automatic or custom field types. This is only for example to help display automatic and custom fields. //1. Automatic, No customization <-- Choose me I'm automatic and easy to setup EditorGUILayout.LabelField("Automatic Field By Property Type"); EditorGUILayout.PropertyField(nID); EditorGUILayout.PropertyField(sName); EditorGUILayout.PropertyField(nHealthMax); EditorGUILayout.PropertyField(nCurrentHealth); EditorGUILayout.PropertyField(nPower); // EditorGUILayout.PropertyField(nFearPower); EditorGUILayout.PropertyField(bIsImportant); // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Array Fields"); /* * if (GUILayout.Button("Add New Index", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) * { * MyArray.InsertArrayElementAtIndex(MyArray.arraySize); * MyArray.GetArrayElementAtIndex(MyArray.arraySize - 1).intValue = 0; * } * * for (int a = 0; a < MyArray.arraySize; a++) * { * EditorGUILayout.PropertyField(MyArray.GetArrayElementAtIndex(a)); * if (GUILayout.Button("Remove (" + a.ToString() + ")", GUILayout.MaxWidth(100), GUILayout.MaxHeight(15))) * { * MyArray.DeleteArrayElementAtIndex(a); * } * } */ } else { //Or //2 : Full custom GUI Layout <-- Choose me I can be fully customized with GUI options. EditorGUILayout.LabelField("Customizable Field With GUI"); /* * MyGO.objectReferenceValue = EditorGUILayout.ObjectField("My Custom Go", MyGO.objectReferenceValue, typeof(GameObject), true); * MyInt.intValue = EditorGUILayout.IntField("My Custom Int", MyInt.intValue); * MyFloat.floatValue = EditorGUILayout.FloatField("My Custom Float", MyFloat.floatValue); * MyVect3.vector3Value = EditorGUILayout.Vector3Field("My Custom Vector 3", MyVect3.vector3Value); */ nID.intValue = EditorGUILayout.IntField("Id", nID.intValue); sName.stringValue = EditorGUILayout.TextField("Namet", sName.stringValue); nHealthMax.intValue = EditorGUILayout.IntField("HealthMax", nHealthMax.intValue); nCurrentHealth.intValue = EditorGUILayout.IntField("CurrentHealth", nCurrentHealth.intValue); nPower.intValue = EditorGUILayout.IntField("Power", nPower.intValue); //nFearPower.intValue = EditorGUILayout.IntField("FearPower", nFearPower.intValue); bIsImportant.boolValue = EditorGUILayout.Toggle("Is important", bIsImportant.boolValue); // Array fields with remove at index EditorGUILayout.Space(); EditorGUILayout.Space(); // EditorGUILayout.LabelField("Array Fields"); /* * if (GUILayout.Button("Add New Index", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) * { * MyArray.InsertArrayElementAtIndex(MyArray.arraySize); * MyArray.GetArrayElementAtIndex(MyArray.arraySize - 1).intValue = 0; * } * * for (int a = 0; a < MyArray.arraySize; a++) * { * EditorGUILayout.BeginHorizontal(); * EditorGUILayout.LabelField("My Custom Int (" + a.ToString() + ")", GUILayout.MaxWidth(120)); * MyArray.GetArrayElementAtIndex(a).intValue = EditorGUILayout.IntField("", MyArray.GetArrayElementAtIndex(a).intValue, GUILayout.MaxWidth(100)); * if (GUILayout.Button("-", GUILayout.MaxWidth(15), GUILayout.MaxHeight(15))) * { * MyArray.DeleteArrayElementAtIndex(a); * } * EditorGUILayout.EndHorizontal(); * } */ } EditorGUILayout.Space(); //Remove this index from the List EditorGUILayout.LabelField("Remove an index from the List<> with a button"); if (GUILayout.Button("Remove This Index (" + i.ToString() + ")")) { ThisList.DeleteArrayElementAtIndex(i); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); } //Apply the changes to our list GetTarget.ApplyModifiedProperties(); }