/// <summary> /// Triggered when the user closes or expands a component foldout, making the component fields visible or hidden. /// </summary> /// <param name="inspectorData">Contains GUI data for the component that was toggled.</param> /// <param name="expanded">Determines whether to display or hide component contents.</param> private void OnComponentFoldoutToggled(InspectorComponent inspectorData, bool expanded) { inspectorData.inspector.Persistent.SetBool(inspectorData.instanceId + "_Expanded", expanded); inspectorData.inspector.SetVisible(expanded); inspectorData.folded = !expanded; UpdateDropAreas(); }
/// <summary> /// Sets a scene object whose GUI is to be displayed in the inspector. Clears any previous contents of the window. /// </summary> /// <param name="so">Scene object to inspect.</param> private void SetObjectToInspect(SceneObject so) { if (so == null) return; currentType = InspectorType.SceneObject; activeSO = so; inspectorScrollArea = new GUIScrollArea(); scrollAreaHighlight = new GUITexture(Builtin.WhiteTexture); scrollAreaHighlight.SetTint(HIGHLIGHT_COLOR); scrollAreaHighlight.Active = false; GUI.AddElement(inspectorScrollArea); GUIPanel inspectorPanel = inspectorScrollArea.Layout.AddPanel(); inspectorLayout = inspectorPanel.AddLayoutY(); highlightPanel = inspectorPanel.AddPanel(-1); highlightPanel.AddElement(scrollAreaHighlight); // SceneObject fields CreateSceneObjectFields(); RefreshSceneObjectFields(true); // Components Component[] allComponents = so.GetComponents(); for (int i = 0; i < allComponents.Length; i++) { inspectorLayout.AddSpace(COMPONENT_SPACING); InspectorComponent data = new InspectorComponent(); data.instanceId = allComponents[i].InstanceId; data.foldout = new GUIToggle(allComponents[i].GetType().Name, EditorStyles.Foldout); data.removeBtn = new GUIButton(new GUIContent(EditorBuiltin.XBtnIcon), GUIOption.FixedWidth(30)); data.title = inspectorLayout.AddLayoutX(); data.title.AddElement(data.foldout); data.title.AddElement(data.removeBtn); data.panel = inspectorLayout.AddPanel(); var persistentProperties = persistentData.GetProperties(allComponents[i].InstanceId); data.inspector = InspectorUtility.GetInspector(allComponents[i].GetType()); data.inspector.Initialize(data.panel, allComponents[i], persistentProperties); bool isExpanded = data.inspector.Persistent.GetBool(data.instanceId + "_Expanded", true); data.foldout.Value = isExpanded; if (!isExpanded) data.inspector.SetVisible(false); Type curComponentType = allComponents[i].GetType(); data.foldout.OnToggled += (bool expanded) => OnComponentFoldoutToggled(data, expanded); data.removeBtn.OnClick += () => OnComponentRemoveClicked(curComponentType); inspectorComponents.Add(data); } inspectorLayout.AddFlexibleSpace(); UpdateDropAreas(); }
/// <summary> /// Sets a scene object whose GUI is to be displayed in the inspector. Clears any previous contents of the window. /// </summary> /// <param name="so">Scene object to inspect.</param> private void SetObjectToInspect(SceneObject so) { if (so == null) { return; } currentType = InspectorType.SceneObject; activeSO = so; inspectorScrollArea = new GUIScrollArea(); scrollAreaHighlight = new GUITexture(Builtin.WhiteTexture); scrollAreaHighlight.SetTint(HIGHLIGHT_COLOR); scrollAreaHighlight.Active = false; GUI.AddElement(inspectorScrollArea); GUIPanel inspectorPanel = inspectorScrollArea.Layout.AddPanel(); inspectorLayout = inspectorPanel.AddLayoutY(); highlightPanel = inspectorPanel.AddPanel(-1); highlightPanel.AddElement(scrollAreaHighlight); // SceneObject fields CreateSceneObjectFields(); RefreshSceneObjectFields(true); // Components Component[] allComponents = so.GetComponents(); for (int i = 0; i < allComponents.Length; i++) { inspectorLayout.AddSpace(COMPONENT_SPACING); InspectorComponent data = new InspectorComponent(); data.instanceId = allComponents[i].InstanceId; data.folded = false; data.foldout = new GUIToggle(allComponents[i].GetType().Name, EditorStyles.Foldout); data.foldout.AcceptsKeyFocus = false; SpriteTexture xBtnIcon = EditorBuiltin.GetEditorIcon(EditorIcon.X); data.removeBtn = new GUIButton(new GUIContent(xBtnIcon), GUIOption.FixedWidth(30)); data.title = inspectorLayout.AddLayoutX(); data.title.AddElement(data.foldout); data.title.AddElement(data.removeBtn); data.panel = inspectorLayout.AddPanel(); var persistentProperties = persistentData.GetProperties(allComponents[i].InstanceId); data.inspector = InspectorUtility.GetInspector(allComponents[i].GetType()); data.inspector.Initialize(data.panel, allComponents[i], persistentProperties); bool isExpanded = data.inspector.Persistent.GetBool(data.instanceId + "_Expanded", true); data.foldout.Value = isExpanded; if (!isExpanded) { data.inspector.SetVisible(false); } Type curComponentType = allComponents[i].GetType(); data.foldout.OnToggled += (bool expanded) => OnComponentFoldoutToggled(data, expanded); data.removeBtn.OnClick += () => OnComponentRemoveClicked(curComponentType); inspectorComponents.Add(data); } inspectorLayout.AddFlexibleSpace(); UpdateDropAreas(); }
/// <summary> /// Triggered when the user closes or expands a component foldout, making the component fields visible or hidden. /// </summary> /// <param name="inspectorData">Contains GUI data for the component that was toggled.</param> /// <param name="expanded">Determines whether to display or hide component contents.</param> private void OnComponentFoldoutToggled(InspectorComponent inspectorData, bool expanded) { inspectorData.inspector.Persistent.SetBool(inspectorData.instanceId + "_Expanded", expanded); inspectorData.inspector.SetVisible(expanded); }