protected virtual void refresh() { this.panel.clearElements(); for (int i = 0; i < this.array.Length; i++) { Type type = this.array.GetValue(i).GetType(); Sleek2TypeInspector sleek2TypeInspector = TypeInspectorRegistry.inspect(type); if (sleek2TypeInspector != null) { sleek2TypeInspector.inspect(new ObjectInspectableArray(this.parentInfo, this.rootInspector.instance as IDirtyable, this.array, this.arrayType, i, new TranslationReference("#SDG::Array_" + i), TranslationReference.invalid)); this.panel.addElement(sleek2TypeInspector); } else { Sleek2InspectorFoldout sleek2InspectorFoldout = new Sleek2InspectorFoldout(); sleek2InspectorFoldout.transform.anchorMin = new Vector2(0f, 1f); sleek2InspectorFoldout.transform.anchorMax = new Vector2(1f, 1f); sleek2InspectorFoldout.transform.pivot = new Vector2(0.5f, 1f); sleek2InspectorFoldout.transform.sizeDelta = new Vector2(0f, (float)Sleek2Config.bodyHeight); sleek2InspectorFoldout.label.translation = new TranslatedTextFallback('[' + i.ToString() + ']'); sleek2InspectorFoldout.label.translation.format(); this.panel.addElement(sleek2InspectorFoldout); this.rootInspector.reflect(new ObjectInspectableArray(this.parentInfo, this.rootInspector.instance as IDirtyable, this.array, this.arrayType, i, new TranslationReference("#SDG::Array_" + i), TranslationReference.invalid), this.array.GetValue(i), sleek2InspectorFoldout.contents); } } }
public void reflect(ObjectInspectableInfo parent, object instance, Sleek2Element panel) { if (instance == null) { panel.addElement(new Sleek2Label { transform = { anchorMin = new Vector2(0f, 1f), anchorMax = new Vector2(1f, 1f), pivot = new Vector2(0f, 1f), sizeDelta = new Vector2(0f, 30f) }, textComponent = { text = "null" } }); return; } Type type = instance.GetType(); if (type.IsArray) { Array newArray = instance as Array; Type elementType = type.GetElementType(); Sleek2InspectorArray element = new Sleek2InspectorArray(this, parent, newArray, elementType); panel.addElement(element); } else if (type.IsGenericType && typeof(IList).IsAssignableFrom(type)) { IList newList = instance as IList; Type newListType = type.GetGenericArguments()[0]; IInspectableList newInspectable = instance as IInspectableList; Sleek2InspectorList element2 = new Sleek2InspectorList(this, parent, newList, newListType, newInspectable); panel.addElement(element2); } foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Instance | BindingFlags.Public)) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(InspectableAttribute), false); if (customAttributes.Length > 0) { InspectableAttribute inspectableAttribute = customAttributes[0] as InspectableAttribute; Sleek2TypeInspector sleek2TypeInspector = TypeInspectorRegistry.inspect(fieldInfo.FieldType); if (sleek2TypeInspector != null) { sleek2TypeInspector.inspect(new ObjectInspectableField(parent, fieldInfo, this.instance as IDirtyable, instance, inspectableAttribute.name, inspectableAttribute.tooltip)); panel.addElement(sleek2TypeInspector); } else { Sleek2InspectorFoldout sleek2InspectorFoldout = new Sleek2InspectorFoldout(); sleek2InspectorFoldout.transform.anchorMin = new Vector2(0f, 1f); sleek2InspectorFoldout.transform.anchorMax = new Vector2(1f, 1f); sleek2InspectorFoldout.transform.pivot = new Vector2(0.5f, 1f); sleek2InspectorFoldout.transform.sizeDelta = new Vector2(0f, (float)Sleek2Config.bodyHeight); sleek2InspectorFoldout.label.translation = new TranslatedText(inspectableAttribute.name); sleek2InspectorFoldout.label.translation.format(); sleek2InspectorFoldout.label.tooltip = new TranslatedText(inspectableAttribute.tooltip); sleek2InspectorFoldout.label.tooltip.format(); panel.addElement(sleek2InspectorFoldout); this.reflect(new ObjectInspectableField(parent, fieldInfo, this.instance as IDirtyable, instance, TranslationReference.invalid, TranslationReference.invalid), fieldInfo.GetValue(instance), sleek2InspectorFoldout.contents); if (this.collapseFoldoutsByDefault) { sleek2InspectorFoldout.isOpen = false; } } } } foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { object[] customAttributes2 = propertyInfo.GetCustomAttributes(typeof(InspectableAttribute), false); if (customAttributes2.Length > 0) { InspectableAttribute inspectableAttribute2 = customAttributes2[0] as InspectableAttribute; Sleek2TypeInspector sleek2TypeInspector2 = TypeInspectorRegistry.inspect(propertyInfo.PropertyType); if (sleek2TypeInspector2 != null) { sleek2TypeInspector2.inspect(new ObjectInspectableProperty(parent, propertyInfo, this.instance as IDirtyable, instance, inspectableAttribute2.name, inspectableAttribute2.tooltip)); panel.addElement(sleek2TypeInspector2); } else { Sleek2InspectorFoldout sleek2InspectorFoldout2 = new Sleek2InspectorFoldout(); sleek2InspectorFoldout2.transform.anchorMin = new Vector2(0f, 1f); sleek2InspectorFoldout2.transform.anchorMax = new Vector2(1f, 1f); sleek2InspectorFoldout2.transform.pivot = new Vector2(0.5f, 1f); sleek2InspectorFoldout2.transform.sizeDelta = new Vector2(0f, (float)Sleek2Config.bodyHeight); sleek2InspectorFoldout2.label.translation = new TranslatedText(inspectableAttribute2.name); sleek2InspectorFoldout2.label.translation.format(); sleek2InspectorFoldout2.label.tooltip = new TranslatedText(inspectableAttribute2.tooltip); sleek2InspectorFoldout2.label.tooltip.format(); panel.addElement(sleek2InspectorFoldout2); this.reflect(new ObjectInspectableProperty(parent, propertyInfo, this.instance as IDirtyable, instance, TranslationReference.invalid, TranslationReference.invalid), propertyInfo.GetValue(instance, null), sleek2InspectorFoldout2.contents); if (this.collapseFoldoutsByDefault) { sleek2InspectorFoldout2.isOpen = false; } } } } }