Tanoda
pb_ICollectionInspector.cs
Go to the documentation of this file.
1using UnityEngine;
2using System.Collections;
3using System.Reflection;
4using System.Linq;
5
6namespace GILES.Interface
7{
11 [pb_TypeInspector(typeof(ICollection))]
12 public class pb_ICollectionInspector : pb_TypeInspector
13 {
15 const int MAX_COLLECTION_LENGTH = 32;
16
17 ICollection value;
18 object[] array;
19
20 public UnityEngine.UI.Text title;
21 public Transform collection;
22
23 void OnGUIChanged()
24 {
25 SetValue(value);
26 }
27
28 public override void InitializeGUI()
29 {
30 title.text = GetName().SplitCamelCase();
31
32 value = GetValue<ICollection>();
33
34 if(value != null)
35 {
36 // much boxing
37 array = value.Cast<object>().ToArray();
38
39 if(array.Length < 1 || array.Length > 32)
40 return;
41
42 if(declaringType == null || declaringType.GetElementType() == null)
43 return;
44
45 System.Type elementType = declaringType.GetElementType();
46
47 string typeName = elementType.ToString().Substring(elementType.ToString().LastIndexOf('.') + 1);
48
49 for(int i = 0; i < array.Length; i++)
50 {
51 pb_TypeInspector inspector = pb_InspectorResolver.GetInspector(elementType);
52 inspector.SetIndexInCollection(i);
53 inspector.Initialize( typeName,
54 (int index) => { return array[index]; },
55 SetValueAtIndex );
56 inspector.transform.SetParent(collection);
57 }
58 }
59 }
60
61 private void SetValueAtIndex(int index, object val)
62 {
64 Debug.LogWarning("Setting values in a collection is not supported yet!");
65 array[index] = val;
66 }
67
68 protected override void OnUpdateGUI()
69 {
70 value = GetValue<ICollection>();
71
72 if(value == null)
73 return;
74
75 int prev_length = array.Length;
76
77 array = value.Cast<object>().ToArray();
78
79 if(array.Length < 1 || array.Length > 32)
80 return;
81
82 if(prev_length != array.Length)
83 {
84 foreach(Transform t in transform)
85 pb_ObjectUtility.Destroy(t.gameObject);
86
88 }
89 }
90 }
91}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19