/// <summary> /// Common code called by both Initialize() overloads. /// </summary> /// <param name="mainGui">Primary GUI panel to add the GUI elements to.</param> /// <param name="previewGui">Secondary GUI panel located at the bottom of the inspector window, aimed primarily for /// resource previews, but can be used for any purpose.</param> /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even /// after the inspector is closed and restored when it is re-opened.</param> private void InitializeBase(GUIPanel mainGui, GUIPanel previewGui, SerializableProperties persistent) { rootGUI = mainGui; this.persistent = persistent; GUILayout contentLayoutX = mainGui.AddLayoutX(); contentLayoutX.AddSpace(5); GUILayout contentLayoutY = contentLayoutX.AddLayoutY(); contentLayoutY.AddSpace(5); GUIPanel contentPanel = contentLayoutY.AddPanel(); contentLayoutY.AddSpace(5); contentLayoutX.AddSpace(5); GUIPanel backgroundPanel = mainGui.AddPanel(START_BACKGROUND_DEPTH); GUITexture inspectorContentBg = new GUITexture(null, EditorStylesInternal.InspectorContentBg); backgroundPanel.AddElement(inspectorContentBg); mainPanel = contentPanel; previewPanel = previewGui; layout = GUI.AddLayoutY(); }
/// <summary> /// Initializes the inspector using an object instance. Must be called after construction. /// </summary> /// <param name="gui">GUI panel to add the GUI elements to.</param> /// <param name="instance">Instance of the object whose fields to display GUI for.</param> /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even /// after the inspector is closed and restored when it is re-opened.</param> internal virtual void Initialize(GUIPanel gui, object instance, SerializableProperties persistent) { InitializeBase(gui, null, persistent); inspectedObject = instance; Initialize(); Refresh(); }
/// <summary> /// Initializes the inspector using a resource path. Must be called after construction. /// </summary> /// <param name="gui">GUI panel to add the GUI elements to.</param> /// <param name="path">Path to the resource for which to display GUI for.</param> /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even /// after the inspector is closed and restored when it is re-opened.</param> internal virtual void Initialize(GUIPanel gui, string path, SerializableProperties persistent) { InitializeBase(gui, persistent); inspectedResourcePath = path; Initialize(); Refresh(); }
/// <summary> /// Initializes the inspector using an object instance. Must be called after construction. /// </summary> /// <param name="gui">GUI panel to add the GUI elements to.</param> /// <param name="instance">Instance of the object whose fields to display GUI for.</param> /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even /// after the inspector is closed and restored when it is re-opened.</param> internal virtual void Initialize(GUIPanel gui, object instance, SerializableProperties persistent) { InitializeBase(gui, null, persistent); drawer = new InspectorFieldDrawer(new InspectableContext(Persistent, instance as Component), Layout); inspectedObject = instance; Initialize(); Refresh(); }
/// <summary> /// Initializes the inspector using a resource path. Must be called after construction. /// </summary> /// <param name="mainGui">Primary GUI panel to add the GUI elements to.</param> /// <param name="previewGui">Secondary GUI panel located at the bottom of the inspector window, aimed primarily for /// resource previews, but can be used for any purpose.</param> /// <param name="path">Path to the resource for which to display GUI for.</param> /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even /// after the inspector is closed and restored when it is re-opened.</param> internal virtual void Initialize(GUIPanel mainGui, GUIPanel previewGui, string path, SerializableProperties persistent) { InitializeBase(mainGui, previewGui, persistent); drawer = new InspectorFieldDrawer(new InspectableContext(Persistent), Layout); inspectedResourcePath = path; Initialize(); Refresh(); }
/// <summary> /// Constructs a new set of GUI elements for inspecting the limit object. /// </summary> /// <param name="limit">Initial values to assign to the GUI elements.</param> /// <param name="layout">Layout to append the GUI elements to.</param> /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state. /// </param> public LimitLinearGUI(LimitLinear limit, GUILayout layout, SerializableProperties properties) { limitData = limit; limitExtentField.OnChanged += x => { limitData.extent = x; MarkAsModified(); }; limitExtentField.OnFocusLost += ConfirmModify; layout.AddElement(limitExtentField); limitCommonGUI = new LimitCommonGUI("linear", limit.GetBase(), layout, properties); limitCommonGUI.OnChanged += x => MarkAsModified(); limitCommonGUI.OnConfirmed += ConfirmModify; }
/// <summary> /// Returns existing, or creates new properties for a component with the specified id. /// </summary> /// <param name="componentId">Internal ID of the component to retrieve properties for.</param> /// <returns>A set of key value pairs representing persistent properties of an inspectable component.</returns> public SerializableProperties GetProperties(ulong componentId) { SerializableProperties output; if (!componentProperties.TryGetValue(componentId, out output)) { output = new SerializableProperties(); componentProperties[componentId] = output; } return(output); }
/// <summary> /// Returns existing, or creates new properties for a resource with the specified UUID. /// </summary> /// <param name="uuid">Unique identifier of the resource to retrieve properties for.</param> /// <returns>A set of key value pairs representing persistent properties of an inspectable resource.</returns> public SerializableProperties GetProperties(string uuid) { SerializableProperties output; if (!resourceProperties.TryGetValue(uuid, out output)) { output = new SerializableProperties(); resourceProperties[uuid] = output; } return(output); }
/// <summary> /// Constructs a new set of GUI elements for inspecting the limit object. /// </summary> /// <param name="limit">Initial values to assign to the GUI elements.</param> /// <param name="layout">Layout to append the GUI elements to.</param> /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state. /// </param> public LimitConeRangeGUI(LimitConeRange limit, GUILayout layout, SerializableProperties properties) { this.limitData = limit; yLimitAngleField.OnChanged += x => { limitData.yLimitAngle = new Degree(x); MarkAsModified(); }; yLimitAngleField.OnFocusLost += ConfirmModify; zLimitAngleField.OnChanged += x => { limitData.zLimitAngle = new Degree(x); MarkAsModified(); }; zLimitAngleField.OnFocusLost += ConfirmModify; layout.AddElement(yLimitAngleField); layout.AddElement(zLimitAngleField); limitCommonGUI = new LimitCommonGUI("coneRange", limit.GetBase(), layout, properties); limitCommonGUI.OnChanged += x => MarkAsModified(); limitCommonGUI.OnConfirmed += ConfirmModify; }
/// <summary> /// Constructs a new set of GUI elements for inspecting the limit object. /// </summary> /// <param name="limit">Initial values to assign to the GUI elements.</param> /// <param name="layout">Layout to append the GUI elements to.</param> /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state. /// </param> public LimitAngularRangeGUI(LimitAngularRange limit, GUILayout layout, SerializableProperties properties) { this.limitData = limit; limitLowerField.OnChanged += x => { limitData.lower = new Degree(x); MarkAsModified(); }; limitLowerField.OnFocusLost += ConfirmModify; limitUpperField.OnChanged += x => { limitData.upper = new Degree(x); MarkAsModified(); }; limitUpperField.OnFocusLost += ConfirmModify; layout.AddElement(limitLowerField); layout.AddElement(limitUpperField); limitCommonGUI = new LimitCommonGUI("angularRange", limit.GetBase(), layout, properties); limitCommonGUI.OnChanged += x => MarkAsModified(); limitCommonGUI.OnConfirmed += ConfirmModify; }
/// <summary> /// Constructs a new set of GUI elements for inspecting the post process settings object. /// </summary> /// <param name="settings">Initial values to assign to the GUI elements.</param> /// <param name="layout">Layout to append the GUI elements to.</param> /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state. /// </param> public RenderSettingsGUI(RenderSettings settings, GUILayout layout, SerializableProperties properties) { this.settings = settings; this.properties = properties; // Enable HDR enableHDRField.OnChanged += x => { this.settings.EnableHDR = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableHDRField); // Enable lighting enableLightingField.OnChanged += x => { this.settings.EnableLighting = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableLightingField); // Enable indirect lighting enableIndirectLightingField.OnChanged += x => { this.settings.EnableIndirectLighting = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableIndirectLightingField); // Overlay only overlayOnlyField.OnChanged += x => { this.settings.OverlayOnly = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(overlayOnlyField); // Shadows enableShadowsField.OnChanged += x => { this.settings.EnableShadows = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableShadowsField); shadowsFoldout.AcceptsKeyFocus = false; shadowsFoldout.OnToggled += x => { properties.SetBool("shadows_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(shadowsFoldout); shadowsLayout = layout.AddLayoutX(); { shadowsLayout.AddSpace(10); GUILayoutY contentsLayout = shadowsLayout.AddLayoutY(); shadowsGUI = new ShadowSettingsGUI(settings.ShadowSettings, contentsLayout); shadowsGUI.OnChanged += x => { this.settings.ShadowSettings = x; MarkAsModified(); }; shadowsGUI.OnConfirmed += ConfirmModify; } // Auto exposure enableAutoExposureField.OnChanged += x => { this.settings.EnableAutoExposure = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableAutoExposureField); autoExposureFoldout.AcceptsKeyFocus = false; autoExposureFoldout.OnToggled += x => { properties.SetBool("autoExposure_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(autoExposureFoldout); autoExposureLayout = layout.AddLayoutX(); { autoExposureLayout.AddSpace(10); GUILayoutY contentsLayout = autoExposureLayout.AddLayoutY(); autoExposureGUI = new AutoExposureSettingsGUI(settings.AutoExposure, contentsLayout); autoExposureGUI.OnChanged += x => { this.settings.AutoExposure = x; MarkAsModified(); }; autoExposureGUI.OnConfirmed += ConfirmModify; } // Tonemapping enableToneMappingField.OnChanged += x => { this.settings.EnableTonemapping = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableToneMappingField); //// Tonemapping settings toneMappingFoldout.AcceptsKeyFocus = false; toneMappingFoldout.OnToggled += x => { properties.SetBool("toneMapping_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(toneMappingFoldout); toneMappingLayout = layout.AddLayoutX(); { toneMappingLayout.AddSpace(10); GUILayoutY contentsLayout = toneMappingLayout.AddLayoutY(); toneMappingGUI = new TonemappingSettingsGUI(settings.Tonemapping, contentsLayout); toneMappingGUI.OnChanged += x => { this.settings.Tonemapping = x; MarkAsModified(); }; toneMappingGUI.OnConfirmed += ConfirmModify; } //// White balance settings whiteBalanceFoldout.AcceptsKeyFocus = false; whiteBalanceFoldout.OnToggled += x => { properties.SetBool("whiteBalance_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(whiteBalanceFoldout); whiteBalanceLayout = layout.AddLayoutX(); { whiteBalanceLayout.AddSpace(10); GUILayoutY contentsLayout = whiteBalanceLayout.AddLayoutY(); whiteBalanceGUI = new WhiteBalanceSettingsGUI(settings.WhiteBalance, contentsLayout); whiteBalanceGUI.OnChanged += x => { this.settings.WhiteBalance = x; MarkAsModified(); }; whiteBalanceGUI.OnConfirmed += ConfirmModify; } //// Color grading settings colorGradingFoldout.AcceptsKeyFocus = false; colorGradingFoldout.OnToggled += x => { properties.SetBool("colorGrading_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(colorGradingFoldout); colorGradingLayout = layout.AddLayoutX(); { colorGradingLayout.AddSpace(10); GUILayoutY contentsLayout = colorGradingLayout.AddLayoutY(); colorGradingGUI = new ColorGradingSettingsGUI(settings.ColorGrading, contentsLayout); colorGradingGUI.OnChanged += x => { this.settings.ColorGrading = x; MarkAsModified(); }; colorGradingGUI.OnConfirmed += ConfirmModify; } // Gamma gammaField.OnChanged += x => { this.settings.Gamma = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(gammaField); // Exposure scale exposureScaleField.OnChanged += x => { this.settings.ExposureScale = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(exposureScaleField); //// Depth of field settings depthOfFieldFoldout.AcceptsKeyFocus = false; depthOfFieldFoldout.OnToggled += x => { properties.SetBool("depthOfField_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(depthOfFieldFoldout); depthOfFieldLayout = layout.AddLayoutX(); { depthOfFieldLayout.AddSpace(10); GUILayoutY contentsLayout = depthOfFieldLayout.AddLayoutY(); depthOfFieldGUI = new DepthOfFieldSettingsGUI(settings.DepthOfField, contentsLayout); depthOfFieldGUI.OnChanged += x => { this.settings.DepthOfField = x; MarkAsModified(); }; depthOfFieldGUI.OnConfirmed += ConfirmModify; } //// Ambient occlusion settings ambientOcclusionFoldout.AcceptsKeyFocus = false; ambientOcclusionFoldout.OnToggled += x => { properties.SetBool("ambientOcclusion_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(ambientOcclusionFoldout); ambientOcclusionLayout = layout.AddLayoutX(); { ambientOcclusionLayout.AddSpace(10); GUILayoutY contentsLayout = ambientOcclusionLayout.AddLayoutY(); ambientOcclusionGUI = new AmbientOcclusionSettingsGUI(settings.AmbientOcclusion, contentsLayout); ambientOcclusionGUI.OnChanged += x => { this.settings.AmbientOcclusion = x; MarkAsModified(); }; ambientOcclusionGUI.OnConfirmed += ConfirmModify; } //// Screen space reflections settings screenSpaceReflectionsFoldout.AcceptsKeyFocus = false; screenSpaceReflectionsFoldout.OnToggled += x => { properties.SetBool("screenSpaceReflections_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(screenSpaceReflectionsFoldout); screenSpaceReflectionsLayout = layout.AddLayoutX(); { screenSpaceReflectionsLayout.AddSpace(10); GUILayoutY contentsLayout = screenSpaceReflectionsLayout.AddLayoutY(); screenSpaceReflectionsGUI = new ScreenSpaceReflectionsSettingsGUI(settings.ScreenSpaceReflections, contentsLayout); screenSpaceReflectionsGUI.OnChanged += x => { this.settings.ScreenSpaceReflections = x; MarkAsModified(); }; screenSpaceReflectionsGUI.OnConfirmed += ConfirmModify; } // FXAA enableFXAAField.OnChanged += x => { this.settings.EnableFXAA = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableFXAAField); ToggleFoldoutFields(); }
/// <summary> /// Creates a new context with user-provided peristent property storage. /// </summary> /// <param name="persistent">Existing object into which to inspectable fields can store persistent data.</param> public InspectableContext(SerializableProperties persistent) { Persistent = persistent; }
/// <summary> /// Creates a new context. /// </summary> public InspectableContext() { Persistent = new SerializableProperties(); }
/// <summary> /// Creates a new context with user-provided persistent property storage. /// </summary> /// <param name="persistent">Existing object into which to inspectable fields can store persistent data.</param> /// <param name="component"> /// Component object that inspector fields are editing. Can be null if the object being edited is not a component. /// </param> public InspectableContext(SerializableProperties persistent, Component component = null) { Persistent = persistent; Component = component; }
private void OnInitialize() { EditorApplication.OnProjectSave += SaveSettings; SceneWindow sceneWindow = SceneWindow.GetWindow <SceneWindow>(); if (sceneWindow != null) { viewSettings = sceneWindow.Camera.ViewSettings; moveSettings = sceneWindow.Camera.MoveSettings; renderSettings = sceneWindow.Camera.RenderSettings; gizmoSettings = sceneWindow.GizmoDrawSettings; } else { viewSettings = ProjectSettings.GetObject <SceneCameraViewSettings>(SceneCamera.ViewSettingsKey); moveSettings = ProjectSettings.GetObject <SceneCameraMoveSettings>(SceneCamera.MoveSettingsKey); renderSettings = ProjectSettings.GetObject <RenderSettings>(SceneCamera.RenderSettingsKey); if (ProjectSettings.HasKey(SceneWindow.GizmoDrawSettingsKey)) { gizmoSettings = ProjectSettings.GetObject <GizmoDrawSettings>(SceneWindow.GizmoDrawSettingsKey); } else { gizmoSettings = GizmoDrawSettings.Default(); } } expandStates = ProjectSettings.GetObject <SerializableProperties>(ExpandStatesKey); InspectableContext inspectableContext = new InspectableContext(expandStates); GUILayout mainLayout = GUI.AddLayoutY(); GUIScrollArea scrollArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow); mainLayout.AddElement(scrollArea); GUILayoutX horzPadLayout = scrollArea.Layout.AddLayoutX(GUIOption.FlexibleWidth(100, 400)); horzPadLayout.AddSpace(5); GUILayout vertLayout = horzPadLayout.AddLayoutY(); horzPadLayout.AddSpace(5); vertLayout.AddSpace(5); vertLayout.AddElement(new GUILabel(new LocEdString("View Settings"), EditorStyles.LabelBold)); GUILayoutY viewSettingsLayout = vertLayout.AddLayoutY(); vertLayout.AddSpace(10); vertLayout.AddElement(new GUILabel(new LocEdString("Gizmo Settings"), EditorStyles.LabelBold)); GUILayoutY gizmoSettingsLayout = vertLayout.AddLayoutY(); vertLayout.AddSpace(10); vertLayout.AddElement(new GUILabel(new LocEdString("Move Settings"), EditorStyles.LabelBold)); GUILayoutY moveSettingsLayout = vertLayout.AddLayoutY(); vertLayout.AddSpace(10); vertLayout.AddElement(new GUILabel(new LocEdString("Render Settings"), EditorStyles.LabelBold)); GUILayoutY renderSettingsLayout = vertLayout.AddLayoutY(); guiViewSettings = new InspectorFieldDrawer(inspectableContext, viewSettingsLayout); guiGizmoSettings = new InspectorFieldDrawer(inspectableContext, gizmoSettingsLayout); guiMovementSettings = new InspectorFieldDrawer(inspectableContext, moveSettingsLayout); guiRenderSettings = new InspectorFieldDrawer(inspectableContext, renderSettingsLayout); objGizmoSettings = gizmoSettings; guiViewSettings.AddDefault(viewSettings); guiGizmoSettings.AddDefault(objGizmoSettings); guiMovementSettings.AddDefault(moveSettings); guiRenderSettings.AddDefault(renderSettings); mainLayout.AddSpace(5); GUILayout buttonCenterLayout = mainLayout.AddLayoutX(); mainLayout.AddSpace(5); GUIButton resetToDefaultBtn = new GUIButton(new LocEdString("Reset to defaults")); resetToDefaultBtn.OnClick += () => ConfirmResetToDefault(ResetToDefault, null); buttonCenterLayout.AddFlexibleSpace(); buttonCenterLayout.AddElement(resetToDefaultBtn); buttonCenterLayout.AddFlexibleSpace(); }
/// <summary> /// Creates a new context. /// </summary> /// <param name="component"> /// Component object that inspector fields are editing. Can be null if the object being edited is not a component. /// </param> public InspectableContext(Component component = null) { Persistent = new SerializableProperties(); Component = component; }
/// <summary> /// Constructs a new set of GUI elements for inspecting the limit object. /// </summary> /// <param name="prefix">Prefix that identifies the exact type of the limit type.</param> /// <param name="limitData">Initial values to assign to the GUI elements.</param> /// <param name="layout">Layout to append the GUI elements to.</param> /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state. /// </param> public LimitCommonGUI(string prefix, LimitCommon limitData, GUILayout layout, SerializableProperties properties) { this.limitData = limitData; this.properties = properties; this.prefix = prefix; hardFoldout.AcceptsKeyFocus = false; hardFoldout.OnToggled += x => { properties.SetBool(prefix + "_hardLimit_Expanded", x); ToggleLimitFields(); }; contactDistanceField.OnChanged += x => { this.limitData.contactDist = x; MarkAsModified(); }; contactDistanceField.OnFocusLost += ConfirmModify; contactDistanceField.OnConfirmed += ConfirmModify; softFoldout.AcceptsKeyFocus = false; softFoldout.OnToggled += x => { properties.SetBool(prefix + "_softLimit_Expanded", x); ToggleLimitFields(); }; restitutionField.OnChanged += x => { this.limitData.restitution = x; MarkAsModified(); }; restitutionField.OnFocusLost += ConfirmModify; springFoldout.AcceptsKeyFocus = false; springFoldout.OnToggled += x => { properties.SetBool(prefix + "_spring_Expanded", x); ToggleLimitFields(); }; hardLimitLayout = layout.AddLayoutX(); { hardLimitLayout.AddSpace(10); GUILayoutY hardLimitContentsLayout = hardLimitLayout.AddLayoutY(); hardLimitContentsLayout.AddElement(contactDistanceField); } softLimitLayout = layout.AddLayoutX(); layout.AddElement(softFoldout); { softLimitLayout.AddSpace(10); GUILayoutY softLimitContentsLayout = softLimitLayout.AddLayoutY(); softLimitContentsLayout.AddElement(restitutionField); softLimitContentsLayout.AddElement(springFoldout); springLayout = softLimitContentsLayout.AddLayoutX(); { springLayout.AddSpace(10); GUILayoutY springContentsLayout = springLayout.AddLayoutY(); springGUI = new SpringGUI(limitData.spring, springContentsLayout); springGUI.OnChanged += x => { this.limitData.spring = x; MarkAsModified(); }; springGUI.OnConfirmed += ConfirmModify; } } }