| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using BansheeEngine;
- namespace BansheeEditor
- {
- public class InspectableObject : InspectableObjectBase
- {
- private const int IndentAmount = 15;
- private object propertyValue;
- private GUILayoutX guiChildLayout;
- private GUILayoutX guiTitleLayout;
- private bool isExpanded;
- private bool forceUpdate = true;
- public InspectableObject(string title, InspectableFieldLayout layout, SerializableProperty property)
- : base(title, layout, property)
- {
-
- }
- public override GUILayoutX GetTitleLayout()
- {
- return guiTitleLayout;
- }
- protected override bool IsModified()
- {
- if (forceUpdate)
- return true;
- object newPropertyValue = property.GetValue<object>();
- if (propertyValue == null)
- return newPropertyValue != null;
-
- if (newPropertyValue == null)
- return propertyValue != null;
-
- return base.IsModified();
- }
- protected override void Update(int index)
- {
- base.Update(index);
- forceUpdate = false;
- guiTitleLayout = null;
- if (property.Type != SerializableProperty.FieldType.Object)
- return;
- layout.DestroyElements();
- propertyValue = property.GetValue<object>();
- if (propertyValue == null)
- {
- guiChildLayout = null;
- guiTitleLayout = layout.AddLayoutX(index);
- guiTitleLayout.AddElement(new GUILabel(title, GUIOption.FixedWidth(100)));
- guiTitleLayout.AddElement(new GUILabel("Empty"));
- if (!property.IsValueType)
- {
- GUIButton createBtn = new GUIButton("Cr", GUIOption.FixedWidth(20));
- createBtn.OnClick += OnCreateButtonClicked;
- guiTitleLayout.AddFlexibleSpace();
- guiTitleLayout.AddElement(createBtn);
- }
- }
- else
- {
- guiTitleLayout = layout.AddLayoutX(index);
- GUIFoldout guiFoldout = new GUIFoldout(title, GUIOption.FixedWidth(100));
- guiFoldout.SetExpanded(isExpanded);
- guiFoldout.OnToggled += OnFoldoutToggled;
- guiTitleLayout.AddElement(guiFoldout);
- GUIButton clearBtn = new GUIButton("Cl", GUIOption.FixedWidth(20));
- clearBtn.OnClick += OnClearButtonClicked;
- guiTitleLayout.AddFlexibleSpace();
- guiTitleLayout.AddElement(clearBtn);
- if (isExpanded)
- {
- guiChildLayout = layout.AddLayoutX(index);
- guiChildLayout.AddSpace(IndentAmount);
- GUILayoutY guiContentLayout = guiChildLayout.AddLayoutY();
- SerializableObject serializableObject = property.GetObject();
- foreach (var field in serializableObject.fields)
- {
- if (!field.Inspectable)
- continue;
- if (field.HasCustomInspector)
- AddChild(CreateCustomInspectable(field.CustomInspectorType, field.Name, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
- else
- AddChild(CreateDefaultInspectable(field.Name, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
- }
- }
- else
- guiChildLayout = null;
- }
- }
- private void OnFoldoutToggled(bool expanded)
- {
- isExpanded = expanded;
- forceUpdate = true;
- }
- private void OnCreateButtonClicked()
- {
- property.SetValue(property.CreateObjectInstance<object>());
- }
- private void OnClearButtonClicked()
- {
- property.SetValue<object>(null);
- }
- }
- }
|