-
Notifications
You must be signed in to change notification settings - Fork 8
/
PolymophismWindow.cs
60 lines (49 loc) · 1.37 KB
/
PolymophismWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using SerializationTest.Common;
namespace SerializationTest.Test5
{
[Serializable]
public class Zoo {
public List<Animal> animals = new List<Animal>();
}
public class PolymophismWindow : EditorWindow {
private const string WINDOW_TITLE = "Polymophism";
private Zoo zoo;
void OnEnable() {
titleContent.text = WINDOW_TITLE;
if(zoo == null) {
zoo = new Zoo();
}
}
void OnGUI() {
EditorGUILayout.LabelField("animal count", zoo.animals.Count.ToString());
for(int i = 0; i < zoo.animals.Count; i++) {
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(i.ToString(), zoo.animals[i].Species);
if(GUILayout.Button("remove", GUILayout.Width(70))) {
zoo.animals.RemoveAt(i);
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.BeginHorizontal();
if(GUILayout.Button("add Cat")) {
zoo.animals.Add(new Cat());
}
if(GUILayout.Button("add Dog")) {
zoo.animals.Add(new Dog());
}
if(GUILayout.Button("add Giraffe")) {
zoo.animals.Add(new Giraffe());
}
EditorGUILayout.EndHorizontal();
}
[MenuItem ("Window/Serialization Test/Test 5 - " + WINDOW_TITLE)]
public static void ShowWindow()
{
EditorWindow.GetWindow<PolymophismWindow>();
}
} // class TestWindow5
} // namespace SerializationTest.Test5