| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using BansheeEngine;
- namespace BansheeEditor
- {
- internal sealed class InspectorWindow : EditorWindow
- {
- private class InspectorData
- {
- public GUIFoldout foldout;
- public GUIFixedSpace space;
- public Inspector inspector;
- }
- private List<InspectorData> inspectorData = new List<InspectorData>();
- private GUILayout inspectorLayout;
- internal void SetObjectToInspect(SceneObject so)
- {
- Clear();
- // TODO - Create SceneObject gui elements (name + transform)
- inspectorLayout = GUI.layout.AddLayoutY();
- Component[] allComponents = so.GetComponents();
- for (int i = 0; i < allComponents.Length; i++)
- {
- InspectorData data = new InspectorData();
- data.foldout = new GUIFoldout(allComponents[i].GetType().Name);
- inspectorLayout.AddElement(data.foldout);
- data.space = inspectorLayout.AddSpace(0);
- data.inspector = GetInspector(allComponents[i].GetType());
- data.inspector.Initialize(CreatePanel(0, 0, 0, 0), allComponents[i]);
- data.foldout.OnToggled += (bool expanded) => Foldout_OnToggled(data.inspector, expanded);
- inspectorData.Add(data);
- }
- inspectorLayout.AddFlexibleSpace();
- RepositionInspectors();
- }
- void Foldout_OnToggled(Inspector inspector, bool expanded)
- {
- inspector.SetVisible(expanded);
- }
- internal void Refresh()
- {
- for (int i = 0; i < inspectorData.Count; i++)
- inspectorData[i].inspector.Refresh();
- }
- 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 (inspectorLayout != null)
- {
- inspectorLayout.Destroy();
- inspectorLayout = 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();
- inspectorData[i].inspector.SetArea(0, curPosition, width, inspectorHeight);
- inspectorData[i].space.SetSize(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();
- }
- }
- }
|