| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- using BansheeEngine;
- namespace BansheeEditor
- {
- internal sealed class InspectorWindow : EditorWindow
- {
- private class InspectorData
- {
- public GUIComponentFoldout foldout;
- public GUIPanelContainer container;
- public Inspector inspector;
- public bool expanded = true;
- }
- private List<InspectorData> inspectorData = new List<InspectorData>();
- private GUIScrollArea inspectorScrollArea;
- private GUILayout inspectorLayout;
- internal void SetObjectToInspect(SceneObject so)
- {
- Clear();
- // TODO - Create SceneObject gui elements (name + transform)
- inspectorScrollArea = new GUIScrollArea();
- GUI.layout.AddElement(inspectorScrollArea);
- inspectorLayout = inspectorScrollArea.layout;
- Component[] allComponents = so.GetComponents();
- for (int i = 0; i < allComponents.Length; i++)
- {
- InspectorData data = new InspectorData();
- GUIPanel inspectorPanel = CreatePanel(0, 0, 0, 0);
- data.foldout = new GUIComponentFoldout(allComponents[i].GetType().Name);
- inspectorLayout.AddElement(data.foldout);
- data.container = new GUIPanelContainer(inspectorPanel);
- inspectorLayout.AddElement(data.container);
- data.inspector = GetInspector(allComponents[i].GetType());
- data.inspector.Initialize(inspectorPanel, allComponents[i]);
- data.foldout.SetExpanded(true);
- data.foldout.OnToggled += (bool expanded) => Foldout_OnToggled(data, expanded);
- inspectorData.Add(data);
- inspectorData[i].inspector.Refresh();
- }
- inspectorLayout.AddFlexibleSpace();
- RepositionInspectors();
- }
- void Foldout_OnToggled(InspectorData inspectorData, bool expanded)
- {
- inspectorData.expanded = expanded;
- inspectorData.inspector.SetVisible(expanded);
- RepositionInspectors();
- }
- internal void Refresh()
- {
- bool anythingModified = false;
- for (int i = 0; i < inspectorData.Count; i++)
- {
- anythingModified |= inspectorData[i].inspector.Refresh();
- }
- if (anythingModified)
- RepositionInspectors();
- }
- internal void Destroy()
- {
- // TODO - Destroy SceneObject GUI elements
- Clear();
- }
- internal void Clear()
- {
- for (int i = 0; i < inspectorData.Count; i++)
- {
- inspectorData[i].foldout.Destroy();
- inspectorData[i].inspector.Destroy();
- }
- inspectorData.Clear();
- if (inspectorScrollArea != null)
- {
- inspectorScrollArea.Destroy();
- inspectorScrollArea = null;
- }
- }
- protected override void WindowResized(int width, int height)
- {
- base.WindowResized(width, height);
- RepositionInspectors();
- }
- private void RepositionInspectors()
- {
- int curPosition = 0;
- for (int i = 0; i < inspectorData.Count; i++)
- {
- int inspectorHeight = inspectorData[i].inspector.GetOptimalHeight();
- if (!inspectorData[i].expanded)
- inspectorHeight = 0;
- inspectorData[i].inspector.SetArea(0, curPosition, width, inspectorHeight);
- inspectorData[i].container.SetLayoutOptions(GUIOption.FixedHeight(inspectorHeight));
- curPosition += inspectorHeight;
- }
- }
- private Inspector GetInspector(Type type)
- {
- // TODO - Check if type has a custom inspector
- // and return the custom inspector, otherwise create a generic one
- return new GenericInspector();
- }
- }
- }
|