/// <summary> /// Recreates all the GUI elements used by this inspector. /// </summary> private void BuildGUI() { Layout.Clear(); Animation animation = InspectedObject as Animation; if (animation == null) { return; } animationClipField.OnChanged += x => { AnimationClip clip = Resources.Load <AnimationClip>(x.UUID); animation.DefaultClip = clip; MarkAsModified(); ConfirmModify(); }; wrapModeField.OnSelectionChanged += x => { animation.WrapMode = (AnimWrapMode)x; MarkAsModified(); ConfirmModify(); }; speedField.OnChanged += x => { animation.Speed = x; MarkAsModified(); }; speedField.OnConfirmed += ConfirmModify; speedField.OnFocusLost += ConfirmModify; cullingField.OnChanged += x => { animation.Cull = x; MarkAsModified(); ConfirmModify(); }; overrideBoundsField.OnChanged += x => { animation.UseBounds = x; MarkAsModified(); ConfirmModify(); }; centerField.OnChanged += x => { AABox bounds = animation.Bounds; Vector3 min = x - bounds.Size * 0.5f; Vector3 max = x + bounds.Size * 0.5f; animation.Bounds = new AABox(min, max); MarkAsModified(); }; centerField.OnConfirmed += ConfirmModify; centerField.OnFocusLost += ConfirmModify; sizeField.OnChanged += x => { AABox bounds = animation.Bounds; Vector3 min = bounds.Center - x * 0.5f; Vector3 max = bounds.Center + x * 0.5f; animation.Bounds = new AABox(min, max); MarkAsModified(); }; sizeField.OnConfirmed += ConfirmModify; sizeField.OnFocusLost += ConfirmModify; Layout.AddElement(animationClipField); Layout.AddElement(wrapModeField); Layout.AddElement(speedField); Layout.AddElement(cullingField); Layout.AddElement(overrideBoundsField); GUILayoutX boundsLayout = Layout.AddLayoutX(); boundsLayout.AddElement(new GUILabel(new LocEdString("Bounds"), GUIOption.FixedWidth(100))); GUILayoutY boundsContent = boundsLayout.AddLayoutY(); boundsContent.AddElement(centerField); boundsContent.AddElement(sizeField); // Morph shapes Renderable renderable = animation.SceneObject.GetComponent <Renderable>(); MorphShapes morphShapes = renderable?.Mesh.Value?.MorphShapes; if (morphShapes != null) { GUIToggle morphShapesToggle = new GUIToggle(new LocEdString("Morph shapes"), EditorStyles.Foldout); Layout.AddElement(morphShapesToggle); GUILayoutY channelsLayout = Layout.AddLayoutY(); morphShapesToggle.OnToggled += x => { channelsLayout.Active = x; Persistent.SetBool("Channels_Expanded", x); }; channelsLayout.Active = Persistent.GetBool("Channels_Expanded"); MorphChannel[] channels = morphShapes.Channels; for (int i = 0; i < channels.Length; i++) { GUILayoutY channelLayout = channelsLayout.AddLayoutY(); GUILayoutX channelTitleLayout = channelLayout.AddLayoutX(); channelLayout.AddSpace(5); GUILayoutY channelContentLayout = channelLayout.AddLayoutY(); string channelName = channels[i].Name; GUIToggle channelNameField = new GUIToggle(channelName, EditorStyles.Expand, GUIOption.FlexibleWidth()); channelTitleLayout.AddSpace(15); // Indent channelTitleLayout.AddElement(channelNameField); channelTitleLayout.AddFlexibleSpace(); channelNameField.OnToggled += x => { channelContentLayout.Active = x; Persistent.SetBool(channelName + "_Expanded", x); }; channelContentLayout.Active = Persistent.GetBool(channelName + "_Expanded"); MorphShape[] shapes = channels[i].Shapes; for (int j = 0; j < shapes.Length; j++) { GUILayoutX shapeLayout = channelContentLayout.AddLayoutX(); channelContentLayout.AddSpace(5); LocString nameString = new LocString("[{0}]. {1}"); nameString.SetParameter(0, j.ToString()); nameString.SetParameter(1, shapes[j].Name); GUILabel shapeNameField = new GUILabel(shapes[j].Name); LocString weightString = new LocEdString("Weight: {0}"); weightString.SetParameter(0, shapes[j].Weight.ToString()); GUILabel weightField = new GUILabel(weightString); shapeLayout.AddSpace(30); // Indent shapeLayout.AddElement(shapeNameField); shapeLayout.AddFlexibleSpace(); shapeLayout.AddElement(weightField); } } } }
/// <summary> /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before /// use. /// </summary> /// <param name="animEvent">Event whose properties to edit.</param> /// <param name="componentNames">List of component names that the user can select from.</param> /// <param name="updateCallback">Callback triggered when event values change.</param> internal void Initialize(AnimationEvent animEvent, string[] componentNames, Action updateCallback) { int selectedIndex = -1; string methodName = ""; if (!string.IsNullOrEmpty(animEvent.Name)) { string[] nameEntries = animEvent.Name.Split('/'); if (nameEntries.Length > 1) { string typeName = nameEntries[0]; for (int i = 0; i < componentNames.Length; i++) { if (componentNames[i] == typeName) { selectedIndex = i; break; } } methodName = nameEntries[nameEntries.Length - 1]; } } GUIFloatField timeField = new GUIFloatField(new LocEdString("Time"), 40, ""); timeField.Value = animEvent.Time; timeField.OnChanged += x => { animEvent.Time = x; updateCallback(); }; // TODO UNDOREDO GUIListBoxField componentField = new GUIListBoxField(componentNames, new LocEdString("Component"), 40); if (selectedIndex != -1) { componentField.Index = selectedIndex; } componentField.OnSelectionChanged += x => { string compName = ""; if (x != -1) { compName = componentNames[x] + "/"; } animEvent.Name = compName + x; updateCallback(); };// TODO UNDOREDO GUITextField methodField = new GUITextField(new LocEdString("Method"), 40, false, "", GUIOption.FixedWidth(190)); methodField.Value = methodName; methodField.OnChanged += x => { string compName = ""; if (componentField.Index != -1) { compName = componentNames[componentField.Index] + "/"; } animEvent.Name = compName + x; updateCallback(); }; // TODO UNDOREDO GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX horzLayout = vertLayout.AddLayoutX(); horzLayout.AddFlexibleSpace(); GUILayout contentLayout = horzLayout.AddLayoutY(); GUILayout timeLayout = contentLayout.AddLayoutX(); timeLayout.AddSpace(5); timeLayout.AddElement(timeField); timeLayout.AddFlexibleSpace(); GUILayout componentLayout = contentLayout.AddLayoutX(); componentLayout.AddSpace(5); componentLayout.AddElement(componentField); componentLayout.AddFlexibleSpace(); GUILayout methodLayout = contentLayout.AddLayoutX(); methodLayout.AddSpace(5); methodLayout.AddElement(methodField); methodLayout.AddFlexibleSpace(); horzLayout.AddFlexibleSpace(); vertLayout.AddFlexibleSpace(); }
/// <summary> /// Creates a new rectangle offset GUI. /// </summary> /// <param name="title">Text to display on the title bar.</param> /// <param name="layout">Layout to append the GUI elements to.</param> public RectOffsetGUI(LocString title, GUILayout layout) { GUILayoutX rectLayout = layout.AddLayoutX(); rectLayout.AddElement(new GUILabel(title, GUIOption.FixedWidth(100))); GUILayoutY rectContentLayout = rectLayout.AddLayoutY(); GUILayoutX rectTopRow = rectContentLayout.AddLayoutX(); GUILayoutX rectBotRow = rectContentLayout.AddLayoutX(); offsetLeftField = new GUIIntField(new LocEdString("Left"), 40); offsetRightField = new GUIIntField(new LocEdString("Right"), 40); offsetTopField = new GUIIntField(new LocEdString("Top"), 40); offsetBottomField = new GUIIntField(new LocEdString("Bottom"), 40); rectTopRow.AddElement(offsetLeftField); rectTopRow.AddElement(offsetRightField); rectBotRow.AddElement(offsetTopField); rectBotRow.AddElement(offsetBottomField); offsetLeftField.OnChanged += x => { offset.left = x; if (OnChanged != null) { OnChanged(offset); } }; offsetRightField.OnChanged += x => { offset.right = x; if (OnChanged != null) { OnChanged(offset); } }; offsetTopField.OnChanged += x => { offset.top = x; if (OnChanged != null) { OnChanged(offset); } }; offsetBottomField.OnChanged += x => { offset.bottom = x; if (OnChanged != null) { OnChanged(offset); } }; Action DoOnConfirmed = () => { if (OnConfirmed != null) { OnConfirmed(); } }; offsetLeftField.OnConfirmed += DoOnConfirmed; offsetLeftField.OnFocusLost += DoOnConfirmed; offsetRightField.OnConfirmed += DoOnConfirmed; offsetRightField.OnFocusLost += DoOnConfirmed; offsetTopField.OnConfirmed += DoOnConfirmed; offsetTopField.OnFocusLost += DoOnConfirmed; offsetBottomField.OnConfirmed += DoOnConfirmed; offsetBottomField.OnFocusLost += DoOnConfirmed; }
/// <summary> /// Sets a resource whose GUI is to be displayed in the inspector. Clears any previous contents of the window. /// </summary> /// <param name="resourcePath">Resource path relative to the project of the resource to inspect.</param> private void SetObjectToInspect(String resourcePath) { activeResourcePath = resourcePath; if (!ProjectLibrary.Exists(resourcePath)) { return; } ResourceMeta meta = ProjectLibrary.GetMeta(resourcePath); if (meta == null) { return; } Type resourceType = meta.Type; currentType = InspectorType.Resource; inspectorScrollArea = new GUIScrollArea(); GUI.AddElement(inspectorScrollArea); inspectorLayout = inspectorScrollArea.Layout; GUIPanel titlePanel = inspectorLayout.AddPanel(); titlePanel.SetHeight(RESOURCE_TITLE_HEIGHT); GUILayoutY titleLayout = titlePanel.AddLayoutY(); titleLayout.SetPosition(PADDING, PADDING); string name = Path.GetFileNameWithoutExtension(resourcePath); string type = resourceType.Name; LocString title = new LocEdString(name + " (" + type + ")"); GUILabel titleLabel = new GUILabel(title); titleLayout.AddFlexibleSpace(); GUILayoutX titleLabelLayout = titleLayout.AddLayoutX(); titleLabelLayout.AddElement(titleLabel); titleLayout.AddFlexibleSpace(); GUIPanel titleBgPanel = titlePanel.AddPanel(1); GUITexture titleBg = new GUITexture(null, EditorStylesInternal.InspectorTitleBg); titleBgPanel.AddElement(titleBg); inspectorLayout.AddSpace(COMPONENT_SPACING); inspectorResource = new InspectorResource(); inspectorResource.panel = inspectorLayout.AddPanel(); var persistentProperties = persistentData.GetProperties(meta.UUID.ToString()); inspectorResource.inspector = InspectorUtility.GetInspector(resourceType); inspectorResource.inspector.Initialize(inspectorResource.panel, activeResourcePath, persistentProperties); inspectorLayout.AddFlexibleSpace(); }
private void OnInitialize() { mainLayout = GUI.AddLayoutY(); GUIContent viewIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.View), new LocEdString("View")); GUIContent moveIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Move), new LocEdString("Move")); GUIContent rotateIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Rotate), new LocEdString("Rotate")); GUIContent scaleIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Scale), new LocEdString("Scale")); GUIContent localIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Local), new LocEdString("Local")); GUIContent worldIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.World), new LocEdString("World")); GUIContent pivotIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Pivot), new LocEdString("Pivot")); GUIContent centerIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Center), new LocEdString("Center")); GUIContent moveSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.MoveSnap), new LocEdString("Move snap")); GUIContent rotateSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.RotateSnap), new LocEdString("Rotate snap")); GUIToggleGroup handlesTG = new GUIToggleGroup(); viewButton = new GUIToggle(viewIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); moveButton = new GUIToggle(moveIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); rotateButton = new GUIToggle(rotateIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); scaleButton = new GUIToggle(scaleIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); GUIToggleGroup coordModeTG = new GUIToggleGroup(); localCoordButton = new GUIToggle(localIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75)); worldCoordButton = new GUIToggle(worldIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75)); GUIToggleGroup pivotModeTG = new GUIToggleGroup(); pivotButton = new GUIToggle(pivotIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); centerButton = new GUIToggle(centerIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); moveSnapButton = new GUIToggle(moveSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35)); moveSnapInput = new GUIFloatField("", GUIOption.FlexibleWidth(35)); rotateSnapButton = new GUIToggle(rotateSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35)); rotateSnapInput = new GUIFloatField("", GUIOption.FlexibleWidth(35)); viewButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.View); moveButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Move); rotateButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Rotate); scaleButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Scale); localCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.Local); worldCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.World); pivotButton.OnClick += () => OnPivotModeButtonClicked(HandlePivotMode.Pivot); centerButton.OnClick += () => OnPivotModeButtonClicked(HandlePivotMode.Center); moveSnapButton.OnToggled += (bool active) => OnMoveSnapToggled(active); moveSnapInput.OnChanged += (float value) => OnMoveSnapValueChanged(value); rotateSnapButton.OnToggled += (bool active) => OnRotateSnapToggled(active); rotateSnapInput.OnChanged += (float value) => OnRotateSnapValueChanged(value); GUILayout handlesLayout = mainLayout.AddLayoutX(); handlesLayout.AddElement(viewButton); handlesLayout.AddElement(moveButton); handlesLayout.AddElement(rotateButton); handlesLayout.AddElement(scaleButton); handlesLayout.AddSpace(10); handlesLayout.AddElement(localCoordButton); handlesLayout.AddElement(worldCoordButton); handlesLayout.AddSpace(10); handlesLayout.AddElement(pivotButton); handlesLayout.AddElement(centerButton); handlesLayout.AddFlexibleSpace(); handlesLayout.AddElement(moveSnapButton); handlesLayout.AddElement(moveSnapInput); handlesLayout.AddSpace(10); handlesLayout.AddElement(rotateSnapButton); handlesLayout.AddElement(rotateSnapInput); GUIPanel mainPanel = mainLayout.AddPanel(); rtPanel = mainPanel.AddPanel(); selectionPanel = mainPanel.AddPanel(-1); GUIPanel sceneAxesPanel = mainPanel.AddPanel(-1); sceneAxesGUI = new SceneAxesGUI(this, sceneAxesPanel, HandleAxesGUISize, HandleAxesGUISize, ProjectionType.Perspective); focusCatcher = new GUIButton("", EditorStyles.Blank); focusCatcher.OnFocusGained += () => hasContentFocus = true; focusCatcher.OnFocusLost += () => hasContentFocus = false; GUIPanel focusPanel = GUI.AddPanel(-2); focusPanel.AddElement(focusCatcher); toggleProfilerOverlayKey = new VirtualButton(ToggleProfilerOverlayBinding); viewToolKey = new VirtualButton(ViewToolBinding); moveToolKey = new VirtualButton(MoveToolBinding); rotateToolKey = new VirtualButton(RotateToolBinding); scaleToolKey = new VirtualButton(ScaleToolBinding); frameKey = new VirtualButton(FrameBinding); UpdateRenderTexture(Width, Height - HeaderHeight); UpdateProfilerOverlay(); }
/// <summary> /// Rebuilds the GUI dictionary header if needed. /// </summary> protected void UpdateHeaderGUI() { Action BuildEmptyGUI = () => { guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0); guiInternalTitleLayout.AddElement(new GUILabel(title)); guiInternalTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100))); GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create), new LocEdString("Create")); GUIButton createBtn = new GUIButton(createIcon, GUIOption.FixedWidth(30)); createBtn.OnClick += OnCreateButtonClicked; guiInternalTitleLayout.AddElement(createBtn); }; Action BuildFilledGUI = () => { guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0); guiFoldout = new GUIToggle(title, EditorStyles.Foldout); guiFoldout.Value = isExpanded; guiFoldout.AcceptsKeyFocus = false; guiFoldout.OnToggled += x => ToggleFoldout(x, false); GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear), new LocEdString("Clear")); GUIButton guiClearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(30)); guiClearBtn.OnClick += OnClearButtonClicked; GUIContent addIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Add), new LocEdString("Add")); GUIButton guiAddBtn = new GUIButton(addIcon, GUIOption.FixedWidth(30)); guiAddBtn.OnClick += OnAddButtonClicked; guiInternalTitleLayout.AddElement(guiFoldout); guiInternalTitleLayout.AddElement(guiAddBtn); guiInternalTitleLayout.AddElement(guiClearBtn); guiChildLayout = guiLayout.AddLayoutX(); guiChildLayout.AddSpace(IndentAmount); GUIPanel guiContentPanel = guiChildLayout.AddPanel(); GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX(); guiIndentLayoutX.AddSpace(IndentAmount); GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); guiContentLayout = guiIndentLayoutY.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); guiIndentLayoutX.AddSpace(IndentAmount); guiChildLayout.AddSpace(IndentAmount); short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1); string bgPanelStyle = depth % 2 == 0 ? EditorStylesInternal.InspectorContentBgAlternate : EditorStylesInternal.InspectorContentBg; GUIPanel backgroundPanel = guiContentPanel.AddPanel(backgroundDepth); GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle); backgroundPanel.AddElement(inspectorContentBg); ToggleFoldout(isExpanded, false); }; if (state == State.None) { if (!IsNull()) { BuildFilledGUI(); state = State.Filled; } else { BuildEmptyGUI(); state = State.Empty; } } else if (state == State.Empty) { if (!IsNull()) { guiInternalTitleLayout.Destroy(); BuildFilledGUI(); state = State.Filled; } } else if (state == State.Filled) { if (IsNull()) { guiInternalTitleLayout.Destroy(); guiChildLayout.Destroy(); BuildEmptyGUI(); state = State.Empty; } } }
/// <summary> /// Creates GUI elements specific to type in the key portion of a dictionary entry. /// </summary> /// <param name="layout">Layout to insert the row GUI elements to.</param> protected abstract void CreateValueGUI(GUILayoutY layout);
/// <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> /// Updates the contents of the details panel according to the currently selected element. /// </summary> private void RefreshDetailsPanel() { detailsArea.Layout.Clear(); if (sSelectedElementIdx != -1) { GUILayoutX paddingX = detailsArea.Layout.AddLayoutX(); paddingX.AddSpace(5); GUILayoutY paddingY = paddingX.AddLayoutY(); paddingX.AddSpace(5); paddingY.AddSpace(5); GUILayoutY mainLayout = paddingY.AddLayoutY(); paddingY.AddSpace(5); ConsoleEntryData entry = filteredEntries[sSelectedElementIdx]; LocString message = new LocEdString(entry.message); GUILabel messageLabel = new GUILabel(message, EditorStyles.MultiLineLabel, GUIOption.FlexibleHeight()); mainLayout.AddElement(messageLabel); mainLayout.AddSpace(10); if (entry.callstack != null) { foreach (var call in entry.callstack) { string fileName = Path.GetFileName(call.file); string callMessage; if (string.IsNullOrEmpty(call.method)) { callMessage = "\tin " + fileName + ":" + call.line; } else { callMessage = "\t" + call.method + " in " + fileName + ":" + call.line; } GUIButton callBtn = new GUIButton(new LocEdString(callMessage)); mainLayout.AddElement(callBtn); CallStackEntry hoistedCall = call; callBtn.OnClick += () => { CodeEditor.OpenFile(hoistedCall.file, hoistedCall.line); }; } } mainLayout.AddFlexibleSpace(); } else { GUILayoutX centerX = detailsArea.Layout.AddLayoutX(); centerX.AddFlexibleSpace(); GUILayoutY centerY = centerX.AddLayoutY(); centerX.AddFlexibleSpace(); centerY.AddFlexibleSpace(); GUILabel nothingSelectedLbl = new GUILabel(new LocEdString("(No entry selected)")); centerY.AddElement(nothingSelectedLbl); centerY.AddFlexibleSpace(); } }
private void RebuildGUI() { GUI.Clear(); guiCurveEditor = null; guiFieldDisplay = null; if (selectedSO == null) { GUILabel warningLbl = new GUILabel(new LocEdString("Select an object to animate in the Hierarchy or Scene windows.")); GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX horzLayout = vertLayout.AddLayoutX(); vertLayout.AddFlexibleSpace(); horzLayout.AddFlexibleSpace(); horzLayout.AddElement(warningLbl); horzLayout.AddFlexibleSpace(); return; } // Top button row GUIContent playIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Play), new LocEdString("Play")); GUIContent recordIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Record), new LocEdString("Record")); GUIContent prevFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameBack), new LocEdString("Previous frame")); GUIContent nextFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameForward), new LocEdString("Next frame")); GUIContent addKeyframeIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddKeyframe), new LocEdString("Add keyframe")); GUIContent addEventIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddEvent), new LocEdString("Add event")); GUIContent optionsIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Options), new LocEdString("Options")); playButton = new GUIButton(playIcon); recordButton = new GUIButton(recordIcon); prevFrameButton = new GUIButton(prevFrameIcon); frameInputField = new GUIIntField(); nextFrameButton = new GUIButton(nextFrameIcon); addKeyframeButton = new GUIButton(addKeyframeIcon); addEventButton = new GUIButton(addEventIcon); optionsButton = new GUIButton(optionsIcon); playButton.OnClick += () => { // TODO // - Record current state of the scene object hierarchy // - Evaluate all curves manually and update them // - On end, restore original values of the scene object hierarchy }; recordButton.OnClick += () => { // TODO // - Every frame read back current values of all the current curve's properties and assign it to the current frame }; prevFrameButton.OnClick += () => { SetCurrentFrame(currentFrameIdx - 1); }; frameInputField.OnChanged += SetCurrentFrame; nextFrameButton.OnClick += () => { SetCurrentFrame(currentFrameIdx + 1); }; addKeyframeButton.OnClick += () => { guiCurveEditor.AddKeyFrameAtMarker(); }; addEventButton.OnClick += () => { guiCurveEditor.AddEventAtMarker(); }; optionsButton.OnClick += () => { Vector2I openPosition = ScreenToWindowPos(Input.PointerPosition); AnimationOptions dropDown = DropDownWindow.Open <AnimationOptions>(this, openPosition); dropDown.Initialize(this); }; // Property buttons addPropertyBtn = new GUIButton(new LocEdString("Add property")); delPropertyBtn = new GUIButton(new LocEdString("Delete selected")); addPropertyBtn.OnClick += () => { Action openPropertyWindow = () => { Vector2I windowPos = ScreenToWindowPos(Input.PointerPosition); FieldSelectionWindow fieldSelection = DropDownWindow.Open <FieldSelectionWindow>(this, windowPos); fieldSelection.OnFieldSelected += OnFieldAdded; }; if (clipInfo.clip == null) { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("Selected object doesn't have an animation clip assigned. Would you like to create" + " a new animation clip?"); DialogBox.Open(title, message, DialogBox.Type.YesNoCancel, type => { if (type == DialogBox.ResultType.Yes) { string clipSavePath; if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.asset", out clipSavePath)) { clipSavePath = Path.ChangeExtension(clipSavePath, ".asset"); AnimationClip newClip = new AnimationClip(); ProjectLibrary.Create(newClip, clipSavePath); LoadAnimClip(newClip); Animation animation = selectedSO.GetComponent <Animation>(); if (animation == null) { animation = selectedSO.AddComponent <Animation>(); } animation.DefaultClip = newClip; EditorApplication.SetSceneDirty(); openPropertyWindow(); } } }); } else { if (clipInfo.isImported) { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("You cannot add/edit/remove curves from animation clips that" + " are imported from an external file."); DialogBox.Open(title, message, DialogBox.Type.OK); } else { openPropertyWindow(); } } }; delPropertyBtn.OnClick += () => { if (clipInfo.clip == null) { return; } if (clipInfo.isImported) { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("You cannot add/edit/remove curves from animation clips that" + " are imported from an external file."); DialogBox.Open(title, message, DialogBox.Type.OK); } else { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("Are you sure you want to remove all selected fields?"); DialogBox.Open(title, message, DialogBox.Type.YesNo, x => { if (x == DialogBox.ResultType.Yes) { RemoveSelectedFields(); } }); } }; GUIPanel mainPanel = GUI.AddPanel(); GUIPanel backgroundPanel = GUI.AddPanel(1); GUILayout mainLayout = mainPanel.AddLayoutY(); buttonLayout = mainLayout.AddLayoutX(); buttonLayout.AddSpace(5); buttonLayout.AddElement(playButton); buttonLayout.AddElement(recordButton); buttonLayout.AddSpace(5); buttonLayout.AddElement(prevFrameButton); buttonLayout.AddElement(frameInputField); buttonLayout.AddElement(nextFrameButton); buttonLayout.AddSpace(5); buttonLayout.AddElement(addKeyframeButton); buttonLayout.AddElement(addEventButton); buttonLayout.AddSpace(5); buttonLayout.AddElement(optionsButton); buttonLayout.AddFlexibleSpace(); buttonLayoutHeight = playButton.Bounds.height; GUITexture buttonBackground = new GUITexture(null, EditorStyles.HeaderBackground); buttonBackground.Bounds = new Rect2I(0, 0, Width, buttonLayoutHeight); backgroundPanel.AddElement(buttonBackground); GUILayout contentLayout = mainLayout.AddLayoutX(); GUILayout fieldDisplayLayout = contentLayout.AddLayoutY(GUIOption.FixedWidth(FIELD_DISPLAY_WIDTH)); guiFieldDisplay = new GUIAnimFieldDisplay(fieldDisplayLayout, FIELD_DISPLAY_WIDTH, Height - buttonLayoutHeight * 2, selectedSO); guiFieldDisplay.OnEntrySelected += OnFieldSelected; GUILayout bottomButtonLayout = fieldDisplayLayout.AddLayoutX(); bottomButtonLayout.AddElement(addPropertyBtn); bottomButtonLayout.AddElement(delPropertyBtn); horzScrollBar = new GUIResizeableScrollBarH(); horzScrollBar.OnScrollOrResize += OnHorzScrollOrResize; vertScrollBar = new GUIResizeableScrollBarV(); vertScrollBar.OnScrollOrResize += OnVertScrollOrResize; GUITexture separator = new GUITexture(null, EditorStyles.Separator, GUIOption.FixedWidth(3)); contentLayout.AddElement(separator); GUILayout curveLayout = contentLayout.AddLayoutY(); GUILayout curveLayoutHorz = curveLayout.AddLayoutX(); GUILayout horzScrollBarLayout = curveLayout.AddLayoutX(); horzScrollBarLayout.AddElement(horzScrollBar); horzScrollBarLayout.AddFlexibleSpace(); editorPanel = curveLayoutHorz.AddPanel(); curveLayoutHorz.AddElement(vertScrollBar); curveLayoutHorz.AddFlexibleSpace(); scrollBarHeight = horzScrollBar.Bounds.height; scrollBarWidth = vertScrollBar.Bounds.width; Vector2I curveEditorSize = GetCurveEditorSize(); guiCurveEditor = new GUICurveEditor(this, editorPanel, curveEditorSize.x, curveEditorSize.y); guiCurveEditor.OnFrameSelected += OnFrameSelected; guiCurveEditor.OnEventAdded += OnEventsChanged; guiCurveEditor.OnEventModified += EditorApplication.SetProjectDirty; guiCurveEditor.OnEventDeleted += OnEventsChanged; guiCurveEditor.OnCurveModified += EditorApplication.SetProjectDirty; guiCurveEditor.Redraw(); horzScrollBar.SetWidth(curveEditorSize.x); vertScrollBar.SetHeight(curveEditorSize.y); UpdateScrollBarSize(); }
/// <summary> /// Recreates all the GUI elements used by this inspector. /// </summary> private void BuildGUI() { if (InspectedObject != null) { Camera camera = (Camera)InspectedObject; projectionTypeField.OnSelectionChanged += x => { camera.ProjectionType = (ProjectionType)x; MarkAsModified(); ConfirmModify(); ToggleTypeSpecificFields((ProjectionType)x); }; fieldOfView.OnChanged += x => { camera.FieldOfView = x; MarkAsModified(); }; fieldOfView.OnFocusLost += ConfirmModify; orthoHeight.OnChanged += x => { camera.OrthoHeight = x; MarkAsModified(); }; orthoHeight.OnConfirmed += ConfirmModify; orthoHeight.OnFocusLost += ConfirmModify; aspectField.OnChanged += x => { camera.AspectRatio = x; MarkAsModified(); }; aspectField.OnConfirmed += ConfirmModify; aspectField.OnFocusLost += ConfirmModify; nearPlaneField.OnChanged += x => { camera.NearClipPlane = x; MarkAsModified(); }; nearPlaneField.OnConfirmed += ConfirmModify; nearPlaneField.OnFocusLost += ConfirmModify; farPlaneField.OnChanged += x => { camera.FarClipPlane = x; MarkAsModified(); }; farPlaneField.OnConfirmed += ConfirmModify; farPlaneField.OnFocusLost += ConfirmModify; viewportXField.OnChanged += x => { Rect2 rect = camera.ViewportRect; rect.x = x; camera.ViewportRect = rect; MarkAsModified(); }; viewportXField.OnConfirmed += ConfirmModify; viewportXField.OnFocusLost += ConfirmModify; viewportYField.OnChanged += x => { Rect2 rect = camera.ViewportRect; rect.y = x; camera.ViewportRect = rect; MarkAsModified(); }; viewportYField.OnConfirmed += ConfirmModify; viewportYField.OnFocusLost += ConfirmModify; viewportWidthField.OnChanged += x => { Rect2 rect = camera.ViewportRect; rect.width = x; camera.ViewportRect = rect; MarkAsModified(); }; viewportWidthField.OnConfirmed += ConfirmModify; viewportWidthField.OnFocusLost += ConfirmModify; viewportHeightField.OnChanged += x => { Rect2 rect = camera.ViewportRect; rect.height = x; camera.ViewportRect = rect; MarkAsModified(); }; viewportHeightField.OnConfirmed += ConfirmModify; viewportHeightField.OnFocusLost += ConfirmModify; clearFlagsFields.OnSelectionChanged += x => { camera.ClearFlags = (ClearFlags)x; MarkAsModified(); ConfirmModify(); }; clearStencilField.OnChanged += x => { camera.ClearStencil = (ushort)x; }; clearStencilField.OnConfirmed += ConfirmModify; clearStencilField.OnFocusLost += ConfirmModify; clearDepthField.OnChanged += x => { camera.ClearDepth = x; }; clearDepthField.OnConfirmed += ConfirmModify; clearDepthField.OnFocusLost += ConfirmModify; clearColorField.OnChanged += x => { camera.ClearColor = x; MarkAsModified(); ConfirmModify(); }; priorityField.OnChanged += x => { camera.Priority = x; MarkAsModified(); }; priorityField.OnConfirmed += ConfirmModify; priorityField.OnFocusLost += ConfirmModify; layersField.OnSelectionChanged += x => { ulong layers = 0; bool[] states = layersField.States; for (int i = 0; i < states.Length; i++) { layers |= states[i] ? Layers.Values[i] : 0; } layersValue = layers; camera.Layers = layers; MarkAsModified(); ConfirmModify(); }; mainField.OnChanged += x => { camera.Main = x; MarkAsModified(); ConfirmModify(); }; Layout.AddElement(projectionTypeField); Layout.AddElement(fieldOfView); Layout.AddElement(orthoHeight); Layout.AddElement(aspectField); Layout.AddElement(nearPlaneField); Layout.AddElement(farPlaneField); GUILayoutX viewportTopLayout = Layout.AddLayoutX(); viewportTopLayout.AddElement(new GUILabel(new LocEdString("Viewport"), GUIOption.FixedWidth(100))); GUILayoutY viewportContentLayout = viewportTopLayout.AddLayoutY(); GUILayoutX viewportTopRow = viewportContentLayout.AddLayoutX(); viewportTopRow.AddElement(viewportXField); viewportTopRow.AddElement(viewportWidthField); GUILayoutX viewportBotRow = viewportContentLayout.AddLayoutX(); viewportBotRow.AddElement(viewportYField); viewportBotRow.AddElement(viewportHeightField); Layout.AddElement(clearFlagsFields); Layout.AddElement(clearColorField); Layout.AddElement(clearDepthField); Layout.AddElement(clearStencilField); Layout.AddElement(priorityField); Layout.AddElement(layersField); Layout.AddElement(mainField); ToggleTypeSpecificFields(camera.ProjectionType); } }
/// <summary> /// Creates GUI elements required for displaying <see cref="SceneObject"/> fields like name, prefab data and /// transform (position, rotation, scale). Assumes that necessary inspector scroll area layout has already been /// created. /// </summary> private void CreateSceneObjectFields() { GUIPanel sceneObjectPanel = inspectorLayout.AddPanel(); sceneObjectPanel.SetHeight(GetTitleBounds().height); GUILayoutY sceneObjectLayout = sceneObjectPanel.AddLayoutY(); sceneObjectLayout.SetPosition(PADDING, PADDING); GUIPanel sceneObjectBgPanel = sceneObjectPanel.AddPanel(1); GUILayoutX nameLayout = sceneObjectLayout.AddLayoutX(); soActiveToggle = new GUIToggle(""); soActiveToggle.OnToggled += OnSceneObjectActiveStateToggled; GUILabel nameLbl = new GUILabel(new LocEdString("Name"), GUIOption.FixedWidth(50)); soNameInput = new GUITextBox(false, GUIOption.FlexibleWidth(180)); soNameInput.Text = activeSO.Name; soNameInput.OnChanged += OnSceneObjectRename; soNameInput.OnConfirmed += OnModifyConfirm; soNameInput.OnFocusLost += OnModifyConfirm; nameLayout.AddElement(soActiveToggle); nameLayout.AddSpace(3); nameLayout.AddElement(nameLbl); nameLayout.AddElement(soNameInput); nameLayout.AddFlexibleSpace(); GUILayoutX mobilityLayout = sceneObjectLayout.AddLayoutX(); GUILabel mobilityLbl = new GUILabel(new LocEdString("Mobility"), GUIOption.FixedWidth(50)); soMobility = new GUIEnumField(typeof(ObjectMobility), "", 0, GUIOption.FixedWidth(85)); soMobility.Value = (ulong)activeSO.Mobility; soMobility.OnSelectionChanged += value => activeSO.Mobility = (ObjectMobility)value; mobilityLayout.AddElement(mobilityLbl); mobilityLayout.AddElement(soMobility); soPrefabLayout = sceneObjectLayout.AddLayoutX(); soPos = new GUIVector3Field(new LocEdString("Position"), 50); sceneObjectLayout.AddElement(soPos); soPos.OnChanged += OnPositionChanged; soPos.OnConfirmed += OnModifyConfirm; soPos.OnFocusLost += OnModifyConfirm; soRot = new GUIVector3Field(new LocEdString("Rotation"), 50); sceneObjectLayout.AddElement(soRot); soRot.OnChanged += OnRotationChanged; soRot.OnConfirmed += OnModifyConfirm; soRot.OnFocusLost += OnModifyConfirm; soScale = new GUIVector3Field(new LocEdString("Scale"), 50); sceneObjectLayout.AddElement(soScale); soScale.OnChanged += OnScaleChanged; soScale.OnConfirmed += OnModifyConfirm; soScale.OnFocusLost += OnModifyConfirm; sceneObjectLayout.AddFlexibleSpace(); GUITexture titleBg = new GUITexture(null, EditorStylesInternal.InspectorTitleBg); sceneObjectBgPanel.AddElement(titleBg); }
/// <inheritdoc/> protected override GUILayoutX CreateGUI(GUILayoutY layout) { AnimationSplitInfo rowSplitInfo = GetValue <AnimationSplitInfo>(); if (rowSplitInfo == null) { rowSplitInfo = new AnimationSplitInfo(); SetValue(rowSplitInfo); } GUILayoutX titleLayout = layout.AddLayoutX(); GUILayoutX contentLayout = layout.AddLayoutX(); GUILabel title = new GUILabel(new LocEdString(SeqIndex + ". ")); nameField = new GUITextField(new LocEdString("Name"), 40, false, "", GUIOption.FixedWidth(160)); startFrameField = new GUIIntField(new LocEdString("Start"), 40, "", GUIOption.FixedWidth(80)); endFrameField = new GUIIntField(new LocEdString("End"), 40, "", GUIOption.FixedWidth(80)); isAdditiveField = new GUIToggleField(new LocEdString("Is additive"), 50, "", GUIOption.FixedWidth(80)); startFrameField.SetRange(0, int.MaxValue); endFrameField.SetRange(0, int.MaxValue); titleLayout.AddElement(title); titleLayout.AddElement(nameField); titleLayout.AddFlexibleSpace(); contentLayout.AddSpace(10); contentLayout.AddElement(startFrameField); contentLayout.AddSpace(5); contentLayout.AddElement(endFrameField); contentLayout.AddSpace(5); contentLayout.AddElement(isAdditiveField); nameField.OnChanged += x => { AnimationSplitInfo splitInfo = GetValue <AnimationSplitInfo>(); splitInfo.Name = x; MarkAsModified(); }; nameField.OnFocusLost += ConfirmModify; nameField.OnConfirmed += ConfirmModify; startFrameField.OnChanged += x => { AnimationSplitInfo splitInfo = GetValue <AnimationSplitInfo>(); splitInfo.StartFrame = x; MarkAsModified(); }; startFrameField.OnFocusLost += ConfirmModify; startFrameField.OnConfirmed += ConfirmModify; endFrameField.OnChanged += x => { AnimationSplitInfo splitInfo = GetValue <AnimationSplitInfo>(); splitInfo.EndFrame = x; MarkAsModified(); }; endFrameField.OnFocusLost += ConfirmModify; endFrameField.OnConfirmed += ConfirmModify; isAdditiveField.OnChanged += x => { AnimationSplitInfo splitInfo = GetValue <AnimationSplitInfo>(); splitInfo.IsAdditive = x; MarkAsModified(); ConfirmModify(); }; return(titleLayout); }
/// <summary> /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before /// use. /// </summary> /// <param name="parent">Libary window that this drop down window is a part of.</param> internal void Initialize(LibraryWindow parent) { this.parent = parent; GUIToggleGroup group = new GUIToggleGroup(); GUIToggle list16 = new GUIToggle(new LocEdString("16"), group, EditorStyles.Button, GUIOption.FixedWidth(30)); GUIToggle grid32 = new GUIToggle(new LocEdString("32"), group, EditorStyles.Button, GUIOption.FixedWidth(30)); GUIToggle grid48 = new GUIToggle(new LocEdString("48"), group, EditorStyles.Button, GUIOption.FixedWidth(30)); GUIToggle grid64 = new GUIToggle(new LocEdString("64"), group, EditorStyles.Button, GUIOption.FixedWidth(30)); ProjectViewType activeType = parent.ViewType; switch (activeType) { case ProjectViewType.List16: list16.Value = true; break; case ProjectViewType.Grid32: grid32.Value = true; break; case ProjectViewType.Grid48: grid48.Value = true; break; case ProjectViewType.Grid64: grid64.Value = true; break; } list16.OnToggled += (active) => { if (active) { ChangeViewType(ProjectViewType.List16); } }; grid32.OnToggled += (active) => { if (active) { ChangeViewType(ProjectViewType.Grid32); } }; grid48.OnToggled += (active) => { if (active) { ChangeViewType(ProjectViewType.Grid48); } }; grid64.OnToggled += (active) => { if (active) { ChangeViewType(ProjectViewType.Grid64); } }; GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX contentLayout = vertLayout.AddLayoutX(); contentLayout.AddFlexibleSpace(); contentLayout.AddElement(list16); contentLayout.AddElement(grid32); contentLayout.AddElement(grid48); contentLayout.AddElement(grid64); contentLayout.AddFlexibleSpace(); vertLayout.AddFlexibleSpace(); }
/// <summary> /// Rebuilds the GUI object header if needed. /// </summary> /// <param name="layoutIndex">Index at which to insert the GUI elements.</param> protected void BuildGUI(int layoutIndex) { Action BuildEmptyGUI = () => { if (isInline) { return; } guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0); guiInternalTitleLayout.AddElement(new GUILabel(title)); guiInternalTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100))); if (!property.IsValueType) { GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create), new LocEdString("Create")); guiCreateBtn = new GUIButton(createIcon, GUIOption.FixedWidth(30)); guiCreateBtn.OnClick += OnCreateButtonClicked; guiInternalTitleLayout.AddElement(guiCreateBtn); } }; Action BuildFilledGUI = () => { if (!isInline) { guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0); GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout); guiFoldout.Value = isExpanded; guiFoldout.AcceptsKeyFocus = false; guiFoldout.OnToggled += OnFoldoutToggled; guiInternalTitleLayout.AddElement(guiFoldout); if (!property.IsValueType && (style == null || !style.StyleFlags.HasFlag(InspectableFieldStyleFlags.NotNull))) { GUIContent clearIcon = new GUIContent( EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear), new LocEdString("Clear")); GUIButton clearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(20)); clearBtn.OnClick += OnClearButtonClicked; guiInternalTitleLayout.AddElement(clearBtn); } } if (isExpanded || isInline) { SerializableObject serializableObject = property.GetObject(); SerializableField[] fields = serializableObject.Fields; if (fields.Length > 0) { GUILayoutY guiContentLayout; if (!isInline) { guiChildLayout = guiLayout.AddLayoutX(); guiChildLayout.AddSpace(IndentAmount); GUIPanel guiContentPanel = guiChildLayout.AddPanel(); GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX(); guiIndentLayoutX.AddSpace(IndentAmount); GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); guiContentLayout = guiIndentLayoutY.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); guiIndentLayoutX.AddSpace(IndentAmount); guiChildLayout.AddSpace(IndentAmount); short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1); string bgPanelStyle = depth % 2 == 0 ? EditorStylesInternal.InspectorContentBgAlternate : EditorStylesInternal.InspectorContentBg; GUIPanel backgroundPanel = guiContentPanel.AddPanel(backgroundDepth); GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle); backgroundPanel.AddElement(inspectorContentBg); } else { guiContentLayout = guiLayout; } drawer = new InspectorFieldDrawer(context, guiContentLayout, path, depth + 1); drawer.AddDefault(serializableObject); if (!active) { foreach (var field in drawer.Fields) { field.Active = false; } } } } else { guiChildLayout = null; } }; if (state == State.None) { if (propertyValue != null) { BuildFilledGUI(); state = State.Filled; } else { BuildEmptyGUI(); state = State.Empty; } } else if (state == State.Empty) { if (propertyValue != null) { guiInternalTitleLayout?.Destroy(); guiInternalTitleLayout = null; guiCreateBtn = null; BuildFilledGUI(); state = State.Filled; } } else if (state == State.Filled) { drawer?.Clear(); guiInternalTitleLayout?.Destroy(); guiInternalTitleLayout = null; guiCreateBtn = null; if (guiChildLayout != null) { guiChildLayout.Destroy(); guiChildLayout = null; } if (propertyValue == null) { BuildEmptyGUI(); state = State.Empty; } else { BuildFilledGUI(); } } }
private void OnInitialize() { GUILayoutY layout = GUI.AddLayoutY(); GUILayoutX titleLayout = layout.AddLayoutX(); GUIContentImages infoImages = new GUIContentImages( EditorBuiltin.GetLogIcon(LogIcon.Info, 16, false), EditorBuiltin.GetLogIcon(LogIcon.Info, 16, true)); GUIContentImages warningImages = new GUIContentImages( EditorBuiltin.GetLogIcon(LogIcon.Warning, 16, false), EditorBuiltin.GetLogIcon(LogIcon.Warning, 16, true)); GUIContentImages errorImages = new GUIContentImages( EditorBuiltin.GetLogIcon(LogIcon.Error, 16, false), EditorBuiltin.GetLogIcon(LogIcon.Error, 16, true)); GUIToggle infoBtn = new GUIToggle(new GUIContent(infoImages), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); GUIToggle warningBtn = new GUIToggle(new GUIContent(warningImages), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); GUIToggle errorBtn = new GUIToggle(new GUIContent(errorImages), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); GUIToggle detailsBtn = new GUIToggle(new LocEdString("Show details"), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); GUIButton clearBtn = new GUIButton(new LocEdString("Clear"), GUIOption.FixedHeight(TITLE_HEIGHT)); GUIToggle clearOnPlayBtn = new GUIToggle(new LocEdString("Clear on play"), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); titleLayout.AddElement(infoBtn); titleLayout.AddElement(warningBtn); titleLayout.AddElement(errorBtn); titleLayout.AddFlexibleSpace(); titleLayout.AddElement(detailsBtn); titleLayout.AddElement(clearBtn); titleLayout.AddElement(clearOnPlayBtn); infoBtn.Value = filter.HasFlag(EntryFilter.Info); warningBtn.Value = filter.HasFlag(EntryFilter.Warning); errorBtn.Value = filter.HasFlag(EntryFilter.Error); clearOnPlayBtn.Value = EditorSettings.GetBool(CLEAR_ON_PLAY_KEY, true); infoBtn.OnToggled += x => { if (x) { SetFilter(filter | EntryFilter.Info); } else { SetFilter(filter & ~EntryFilter.Info); } }; warningBtn.OnToggled += x => { if (x) { SetFilter(filter | EntryFilter.Warning); } else { SetFilter(filter & ~EntryFilter.Warning); } }; errorBtn.OnToggled += x => { if (x) { SetFilter(filter | EntryFilter.Error); } else { SetFilter(filter & ~EntryFilter.Error); } }; detailsBtn.OnToggled += ToggleDetailsPanel; clearBtn.OnClick += ClearLog; clearOnPlayBtn.OnToggled += ToggleClearOnPlay; GUILayoutX mainLayout = layout.AddLayoutX(); listView = new GUIListView <ConsoleGUIEntry, ConsoleEntryData>(Width, ListHeight, ENTRY_HEIGHT, mainLayout); detailsSeparator = new GUITexture(Builtin.WhiteTexture, GUIOption.FixedWidth(SEPARATOR_WIDTH)); detailsArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow); mainLayout.AddElement(detailsSeparator); mainLayout.AddElement(detailsArea); detailsSeparator.Active = false; detailsArea.Active = false; detailsSeparator.SetTint(SEPARATOR_COLOR); Refresh(); Debug.OnAdded += OnEntryAdded; }
private void OnInitialize() { GUILayoutX splitLayout = GUI.AddLayoutX(); GUIPanel platformPanel = splitLayout.AddPanel(); GUIPanel platformForeground = platformPanel.AddPanel(); GUILayoutY platformLayout = platformForeground.AddLayoutY(); GUIPanel platformBackground = platformPanel.AddPanel(1); GUITexture background = new GUITexture(Builtin.WhiteTexture); background.SetTint(PLATFORM_BG_COLOR); splitLayout.AddSpace(5); GUILayoutY optionsLayout = splitLayout.AddLayoutY(); GUILabel platformsLabel = new GUILabel(new LocEdString("Platforms"), EditorStyles.LabelCentered); platformLayout.AddSpace(5); platformLayout.AddElement(platformsLabel); platformLayout.AddSpace(5); GUIToggleGroup platformToggleGroup = new GUIToggleGroup(); PlatformType[] availablePlatforms = BuildManager.AvailablePlatforms; platformButtons = new GUIToggle[availablePlatforms.Length]; for (int i = 0; i < availablePlatforms.Length; i++) { PlatformType currentPlatform = availablePlatforms[i]; bool isActive = currentPlatform == BuildManager.ActivePlatform; string platformName = Enum.GetName(typeof(PlatformType), currentPlatform); if (isActive) { platformName += " (Active)"; } GUIToggle platformToggle = new GUIToggle(new LocEdString(platformName), platformToggleGroup, EditorStyles.Button); platformToggle.OnToggled += x => OnSelectedPlatformChanged(currentPlatform, x); platformLayout.AddElement(platformToggle); platformButtons[i] = platformToggle; if (isActive) { platformToggle.Value = true; selectedPlatform = currentPlatform; } } platformLayout.AddFlexibleSpace(); GUIButton changePlatformBtn = new GUIButton(new LocEdString("Set active")); platformLayout.AddElement(changePlatformBtn); changePlatformBtn.OnClick += ChangeActivePlatform; platformBackground.AddElement(background); optionsScrollArea = new GUIScrollArea(); optionsLayout.AddElement(optionsScrollArea); GUIButton buildButton = new GUIButton(new LocEdString("Build")); optionsLayout.AddFlexibleSpace(); optionsLayout.AddElement(buildButton); buildButton.OnClick += TryStartBuild; BuildPlatformOptionsGUI(); }
/// <summary> /// Creates all of the GUI elements required for the specified type of dialog box. /// </summary> private void SetupGUI() { messageLabel = new GUILabel("", EditorStyles.MultiLineLabel, GUIOption.FixedWidth(260), GUIOption.FlexibleHeight(0, 600)); GUILayoutY layoutY = GUI.AddLayoutY(); layoutY.AddSpace(10); GUILayoutX messageLayout = layoutY.AddLayoutX(); messageLayout.AddFlexibleSpace(); messageLayout.AddElement(messageLabel); messageLayout.AddFlexibleSpace(); layoutY.AddSpace(10); GUILayoutX btnLayout = layoutY.AddLayoutX(); btnLayout.AddFlexibleSpace(); switch (type) { case Type.OK: { GUIButton okBtn = new GUIButton(new LocEdString("OK")); okBtn.OnClick += () => ButtonClicked(ResultType.OK); btnLayout.AddElement(okBtn); } break; case Type.OKCancel: { GUIButton okBtn = new GUIButton(new LocEdString("OK")); okBtn.OnClick += () => ButtonClicked(ResultType.OK); GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel")); cancelBtn.OnClick += () => ButtonClicked(ResultType.Cancel); btnLayout.AddElement(okBtn); btnLayout.AddSpace(20); btnLayout.AddElement(cancelBtn); } break; case Type.RetryAbortIgnore: { GUIButton retryBtn = new GUIButton(new LocEdString("Retry")); retryBtn.OnClick += () => ButtonClicked(ResultType.Retry); GUIButton abortBtn = new GUIButton(new LocEdString("Abort")); abortBtn.OnClick += () => ButtonClicked(ResultType.Abort); GUIButton ignoreBtn = new GUIButton(new LocEdString("Ignore")); ignoreBtn.OnClick += () => ButtonClicked(ResultType.Ignore); btnLayout.AddElement(retryBtn); btnLayout.AddSpace(20); btnLayout.AddElement(abortBtn); btnLayout.AddSpace(20); btnLayout.AddElement(ignoreBtn); } break; case Type.RetryCancel: { GUIButton retryBtn = new GUIButton(new LocEdString("Retry")); retryBtn.OnClick += () => ButtonClicked(ResultType.Retry); GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel")); cancelBtn.OnClick += () => ButtonClicked(ResultType.Cancel); btnLayout.AddElement(retryBtn); btnLayout.AddSpace(20); btnLayout.AddElement(cancelBtn); } break; case Type.TryCancelContinue: { GUIButton tryBtn = new GUIButton(new LocEdString("Try")); tryBtn.OnClick += () => ButtonClicked(ResultType.Try); GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel")); cancelBtn.OnClick += () => ButtonClicked(ResultType.Cancel); GUIButton continueBtn = new GUIButton(new LocEdString("Continue")); continueBtn.OnClick += () => ButtonClicked(ResultType.Continue); btnLayout.AddElement(tryBtn); btnLayout.AddSpace(20); btnLayout.AddElement(cancelBtn); btnLayout.AddSpace(20); btnLayout.AddElement(continueBtn); } break; case Type.YesNo: { GUIButton yesBtn = new GUIButton(new LocEdString("Yes")); yesBtn.OnClick += () => ButtonClicked(ResultType.Yes); GUIButton noBtn = new GUIButton(new LocEdString("No")); noBtn.OnClick += () => ButtonClicked(ResultType.No); btnLayout.AddElement(yesBtn); btnLayout.AddSpace(20); btnLayout.AddElement(noBtn); } break; case Type.YesNoCancel: { GUIButton yesBtn = new GUIButton(new LocEdString("Yes")); yesBtn.OnClick += () => ButtonClicked(ResultType.Yes); GUIButton noBtn = new GUIButton(new LocEdString("No")); noBtn.OnClick += () => ButtonClicked(ResultType.No); GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel")); cancelBtn.OnClick += () => ButtonClicked(ResultType.Cancel); btnLayout.AddElement(yesBtn); btnLayout.AddSpace(20); btnLayout.AddElement(noBtn); btnLayout.AddSpace(20); btnLayout.AddElement(cancelBtn); } break; } btnLayout.AddFlexibleSpace(); layoutY.AddFlexibleSpace(); }
/// <summary> /// Creates GUI elements specific to type in the key portion of a dictionary entry. /// </summary> /// <param name="layout">Layout to insert the row GUI elements to.</param> /// <returns>An optional title bar layout that the standard dictionary buttons will be appended to.</returns> protected abstract GUILayoutX CreateKeyGUI(GUILayoutY layout);
private void OnInitialize() { Title = "Project Manager"; Width = 500; Height = 290; GUILayout vertLayout = GUI.AddLayoutY(); vertLayout.AddSpace(5); GUILayout firstRow = vertLayout.AddLayoutX(); vertLayout.AddFlexibleSpace(); GUILayout secondRow = vertLayout.AddLayoutX(); vertLayout.AddSpace(5); GUILayout thirdRow = vertLayout.AddLayoutX(); vertLayout.AddFlexibleSpace(); GUILayout fourthRow = vertLayout.AddLayoutX(); vertLayout.AddSpace(5); projectInputBox = new GUITextField(new LocEdString("Project path"), 70, false, "", GUIOption.FixedWidth(398)); projectInputBox.Value = EditorSettings.LastOpenProject; GUIButton openBtn = new GUIButton(new LocEdString("Open"), GUIOption.FixedWidth(75)); openBtn.OnClick += OpenProject; firstRow.AddSpace(5); firstRow.AddElement(projectInputBox); firstRow.AddSpace(15); firstRow.AddElement(openBtn); firstRow.AddSpace(5); GUILabel recentProjectsLabel = new GUILabel(new LocEdString("Recent projects:")); secondRow.AddSpace(5); secondRow.AddElement(recentProjectsLabel); secondRow.AddFlexibleSpace(); GUIButton browseBtn = new GUIButton(new LocEdString("Browse"), GUIOption.FixedWidth(75)); browseBtn.OnClick += BrowseClicked; secondRow.AddElement(browseBtn); secondRow.AddSpace(5); thirdRow.AddSpace(5); GUIPanel recentProjectsPanel = thirdRow.AddPanel(); thirdRow.AddSpace(15); GUILayoutY thirdRowVertical = thirdRow.AddLayoutY(); GUIButton createBtn = new GUIButton(new LocEdString("Create new"), GUIOption.FixedWidth(75)); createBtn.OnClick += CreateClicked; thirdRowVertical.AddElement(createBtn); thirdRowVertical.AddFlexibleSpace(); thirdRow.AddSpace(5); recentProjectsArea = new GUIScrollArea(GUIOption.FixedWidth(385), GUIOption.FixedHeight(170)); GUILayoutX recentProjectsLayout = recentProjectsPanel.AddLayoutX(); recentProjectsLayout.AddSpace(10); GUILayoutY recentProjectsPanelY = recentProjectsLayout.AddLayoutY(); recentProjectsPanelY.AddSpace(5); recentProjectsPanelY.AddElement(recentProjectsArea); recentProjectsPanelY.AddSpace(5); recentProjectsLayout.AddFlexibleSpace(); GUIPanel scrollAreaBgPanel = recentProjectsPanel.AddPanel(1); GUITexture scrollAreaBgTex = new GUITexture(null, true, EditorStylesInternal.ScrollAreaBg); scrollAreaBgPanel.AddElement(scrollAreaBgTex); autoLoadToggle = new GUIToggle(""); autoLoadToggle.Value = EditorSettings.AutoLoadLastProject; GUILabel autoLoadLabel = new GUILabel(new LocEdString("Automatically load last open project")); GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel"), GUIOption.FixedWidth(75)); cancelBtn.OnClick += CancelClicked; fourthRow.AddSpace(5); fourthRow.AddElement(autoLoadToggle); fourthRow.AddElement(autoLoadLabel); fourthRow.AddFlexibleSpace(); fourthRow.AddElement(cancelBtn); fourthRow.AddSpace(5); RefreshRecentProjects(); }
/// <summary> /// Rebuilds the entire GUI based on the current field list and their properties. /// </summary> private void Rebuild() { scrollArea.Layout.Clear(); fields = null; if (fieldInfos == null || root == null) { return; } GUILabel header = new GUILabel(new LocEdString("Properties"), EditorStyles.Header); scrollArea.Layout.AddElement(header); layouts = new GUIAnimFieldLayouts(); GUIPanel rootPanel = scrollArea.Layout.AddPanel(); GUIPanel mainPanel = rootPanel.AddPanel(); GUIPanel underlayPanel = rootPanel.AddPanel(1); GUIPanel overlayPanel = rootPanel.AddPanel(-1); GUIPanel backgroundPanel = rootPanel.AddPanel(2); layouts.main = mainPanel.AddLayoutY(); layouts.underlay = underlayPanel.AddLayoutY(); layouts.overlay = overlayPanel.AddLayoutY(); layouts.background = backgroundPanel.AddLayoutY(); GUIButton catchAll = new GUIButton("", EditorStyles.Blank); catchAll.Bounds = new Rect2I(0, 0, width, height - header.Bounds.height); catchAll.OnClick += () => OnEntrySelected(null); underlayPanel.AddElement(catchAll); layouts.main.AddSpace(5); layouts.underlay.AddSpace(5); layouts.overlay.AddSpace(5); layouts.background.AddSpace(3); // Minor hack: Background starts heigher to get it to center better fields = new GUIAnimFieldEntry[fieldInfos.Count]; for (int i = 0; i < fieldInfos.Count; i++) { if (string.IsNullOrEmpty(fieldInfos[i].path)) { continue; } bool entryIsMissing; if (fieldInfos[i].curveGroup.isPropertyCurve) { string pathSuffix; SerializableProperty property = Animation.FindProperty(root, fieldInfos[i].path, out pathSuffix); entryIsMissing = property == null; } else { entryIsMissing = false; } if (!entryIsMissing) { Color[] colors = new Color[fieldInfos[i].curveGroup.curveInfos.Length]; for (int j = 0; j < fieldInfos[i].curveGroup.curveInfos.Length; j++) { colors[j] = fieldInfos[i].curveGroup.curveInfos[j].color; } switch (fieldInfos[i].curveGroup.type) { case SerializableProperty.FieldType.Vector2: fields[i] = new GUIAnimVec2Entry(layouts, fieldInfos[i].path, colors); break; case SerializableProperty.FieldType.Vector3: fields[i] = new GUIAnimVec3Entry(layouts, fieldInfos[i].path, colors); break; case SerializableProperty.FieldType.Vector4: fields[i] = new GUIAnimVec4Entry(layouts, fieldInfos[i].path, colors); break; case SerializableProperty.FieldType.Color: fields[i] = new GUIAnimColorEntry(layouts, fieldInfos[i].path, colors); break; case SerializableProperty.FieldType.Bool: case SerializableProperty.FieldType.Int: case SerializableProperty.FieldType.Float: { Color color; if (colors.Length > 0) { color = colors[0]; } else { color = Color.White; } fields[i] = new GUIAnimSimpleEntry(layouts, fieldInfos[i].path, color); break; } } } else { fields[i] = new GUIAnimMissingEntry(layouts, fieldInfos[i].path); } if (fields[i] != null) { fields[i].OnEntrySelected += OnEntrySelected; } } if (fieldInfos.Count == 0) { GUILabel warningLbl = new GUILabel(new LocEdString("No properties. Add a new property to begin animating.")); GUILayoutY vertLayout = layouts.main.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX horzLayout = vertLayout.AddLayoutX(); vertLayout.AddFlexibleSpace(); horzLayout.AddFlexibleSpace(); horzLayout.AddElement(warningLbl); horzLayout.AddFlexibleSpace(); } layouts.main.AddSpace(5); layouts.underlay.AddSpace(5); layouts.overlay.AddSpace(5); layouts.background.AddSpace(5); layouts.main.AddFlexibleSpace(); layouts.underlay.AddFlexibleSpace(); layouts.overlay.AddFlexibleSpace(); layouts.background.AddFlexibleSpace(); }
/// <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; } } }
/// <summary> /// Creates GUI elements required for displaying <see cref="SceneObject"/> fields like name, prefab data and /// transform (position, rotation, scale). Assumes that necessary inspector scroll area layout has already been /// created. /// </summary> private void CreateSceneObjectFields() { GUIPanel sceneObjectPanel = inspectorLayout.AddPanel(); sceneObjectPanel.SetHeight(GetTitleBounds().height); GUILayoutY sceneObjectLayout = sceneObjectPanel.AddLayoutY(); sceneObjectLayout.SetPosition(PADDING, PADDING); GUIPanel sceneObjectBgPanel = sceneObjectPanel.AddPanel(1); GUILayoutX nameLayout = sceneObjectLayout.AddLayoutX(); soActiveToggle = new GUIToggle(""); soActiveToggle.OnToggled += OnSceneObjectActiveStateToggled; GUILabel nameLbl = new GUILabel(new LocEdString("Name"), GUIOption.FixedWidth(50)); soNameInput = new GUITextBox(false, GUIOption.FlexibleWidth(180)); soNameInput.Text = activeSO.Name; soNameInput.OnChanged += OnSceneObjectRename; soNameInput.OnConfirmed += OnModifyConfirm; soNameInput.OnFocusLost += OnModifyConfirm; nameLayout.AddElement(soActiveToggle); nameLayout.AddSpace(3); nameLayout.AddElement(nameLbl); nameLayout.AddElement(soNameInput); nameLayout.AddFlexibleSpace(); GUILayoutX mobilityLayout = sceneObjectLayout.AddLayoutX(); GUILabel mobilityLbl = new GUILabel(new LocEdString("Mobility"), GUIOption.FixedWidth(50)); soMobility = new GUIEnumField(typeof(ObjectMobility), "", 0, GUIOption.FixedWidth(85)); soMobility.Value = (ulong)activeSO.Mobility; soMobility.OnSelectionChanged += value => activeSO.Mobility = (ObjectMobility)value; mobilityLayout.AddElement(mobilityLbl); mobilityLayout.AddElement(soMobility); soPrefabLayout = sceneObjectLayout.AddLayoutX(); GUILayoutX positionLayout = sceneObjectLayout.AddLayoutX(); GUILabel positionLbl = new GUILabel(new LocEdString("Position"), GUIOption.FixedWidth(50)); soPosX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60)); soPosY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60)); soPosZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60)); soPosX.OnChanged += (x) => OnPositionChanged(0, x); soPosY.OnChanged += (y) => OnPositionChanged(1, y); soPosZ.OnChanged += (z) => OnPositionChanged(2, z); soPosX.OnConfirmed += OnModifyConfirm; soPosY.OnConfirmed += OnModifyConfirm; soPosZ.OnConfirmed += OnModifyConfirm; soPosX.OnFocusLost += OnModifyConfirm; soPosY.OnFocusLost += OnModifyConfirm; soPosZ.OnFocusLost += OnModifyConfirm; positionLayout.AddElement(positionLbl); positionLayout.AddElement(soPosX); positionLayout.AddSpace(10); positionLayout.AddFlexibleSpace(); positionLayout.AddElement(soPosY); positionLayout.AddSpace(10); positionLayout.AddFlexibleSpace(); positionLayout.AddElement(soPosZ); positionLayout.AddFlexibleSpace(); GUILayoutX rotationLayout = sceneObjectLayout.AddLayoutX(); GUILabel rotationLbl = new GUILabel(new LocEdString("Rotation"), GUIOption.FixedWidth(50)); soRotX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60)); soRotY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60)); soRotZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60)); soRotX.OnChanged += (x) => OnRotationChanged(0, x); soRotY.OnChanged += (y) => OnRotationChanged(1, y); soRotZ.OnChanged += (z) => OnRotationChanged(2, z); soRotX.OnConfirmed += OnModifyConfirm; soRotY.OnConfirmed += OnModifyConfirm; soRotZ.OnConfirmed += OnModifyConfirm; soRotX.OnFocusLost += OnModifyConfirm; soRotY.OnFocusLost += OnModifyConfirm; soRotZ.OnFocusLost += OnModifyConfirm; rotationLayout.AddElement(rotationLbl); rotationLayout.AddElement(soRotX); rotationLayout.AddSpace(10); rotationLayout.AddFlexibleSpace(); rotationLayout.AddElement(soRotY); rotationLayout.AddSpace(10); rotationLayout.AddFlexibleSpace(); rotationLayout.AddElement(soRotZ); rotationLayout.AddFlexibleSpace(); GUILayoutX scaleLayout = sceneObjectLayout.AddLayoutX(); GUILabel scaleLbl = new GUILabel(new LocEdString("Scale"), GUIOption.FixedWidth(50)); soScaleX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60)); soScaleY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60)); soScaleZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60)); soScaleX.OnChanged += (x) => OnScaleChanged(0, x); soScaleY.OnChanged += (y) => OnScaleChanged(1, y); soScaleZ.OnChanged += (z) => OnScaleChanged(2, z); soScaleX.OnConfirmed += OnModifyConfirm; soScaleY.OnConfirmed += OnModifyConfirm; soScaleZ.OnConfirmed += OnModifyConfirm; soScaleX.OnFocusLost += OnModifyConfirm; soScaleY.OnFocusLost += OnModifyConfirm; soScaleZ.OnFocusLost += OnModifyConfirm; scaleLayout.AddElement(scaleLbl); scaleLayout.AddElement(soScaleX); scaleLayout.AddSpace(10); scaleLayout.AddFlexibleSpace(); scaleLayout.AddElement(soScaleY); scaleLayout.AddSpace(10); scaleLayout.AddFlexibleSpace(); scaleLayout.AddElement(soScaleZ); scaleLayout.AddFlexibleSpace(); sceneObjectLayout.AddFlexibleSpace(); GUITexture titleBg = new GUITexture(null, EditorStylesInternal.InspectorTitleBg); sceneObjectBgPanel.AddElement(titleBg); }
/// <summary> /// Builds GUI for the specified GUI element style. /// </summary> /// <param name="layout">Layout to append the GUI elements to.</param> /// <param name="depth">Determines the depth at which the element is rendered.</param> public void BuildGUI(GUILayout layout, int depth) { short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1); string bgPanelStyle = depth % 2 == 0 ? EditorStylesInternal.InspectorContentBgAlternate : EditorStylesInternal.InspectorContentBg; GUIToggle foldout = new GUIToggle(new LocEdString("Style"), EditorStyles.Foldout); foldout.AcceptsKeyFocus = false; GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle); layout.AddElement(foldout); GUIPanel panel = layout.AddPanel(); GUIPanel backgroundPanel = panel.AddPanel(backgroundDepth); backgroundPanel.AddElement(inspectorContentBg); GUILayoutX guiIndentLayoutX = panel.AddLayoutX(); guiIndentLayoutX.AddSpace(IndentAmount); GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); GUILayoutY contentLayout = guiIndentLayoutY.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); guiIndentLayoutX.AddSpace(IndentAmount); fontField = new GUIResourceField(typeof(Font), new LocEdString("Font")); fontSizeField = new GUIIntField(new LocEdString("Font size")); horzAlignField = new GUIEnumField(typeof(TextHorzAlign), new LocEdString("Horizontal alignment")); vertAlignField = new GUIEnumField(typeof(TextVertAlign), new LocEdString("Vertical alignment")); imagePositionField = new GUIEnumField(typeof(GUIImagePosition), new LocEdString("Image position")); wordWrapField = new GUIToggleField(new LocEdString("Word wrap")); contentLayout.AddElement(fontField); contentLayout.AddElement(fontSizeField); contentLayout.AddElement(horzAlignField); contentLayout.AddElement(vertAlignField); contentLayout.AddElement(imagePositionField); contentLayout.AddElement(wordWrapField); normalGUI.BuildGUI(new LocEdString("Normal"), contentLayout); hoverGUI.BuildGUI(new LocEdString("Hover"), contentLayout); activeGUI.BuildGUI(new LocEdString("Active"), contentLayout); focusedGUI.BuildGUI(new LocEdString("Focused"), contentLayout); normalOnGUI.BuildGUI(new LocEdString("NormalOn"), contentLayout); hoverOnGUI.BuildGUI(new LocEdString("HoverOn"), contentLayout); activeOnGUI.BuildGUI(new LocEdString("ActiveOn"), contentLayout); focusedOnGUI.BuildGUI(new LocEdString("FocusedOn"), contentLayout); borderGUI = new RectOffsetGUI(new LocEdString("Border"), contentLayout); marginsGUI = new RectOffsetGUI(new LocEdString("Margins"), contentLayout); contentOffsetGUI = new RectOffsetGUI(new LocEdString("Content offset"), contentLayout); fixedWidthField = new GUIToggleField(new LocEdString("Fixed width")); widthField = new GUIIntField(new LocEdString("Width")); minWidthField = new GUIIntField(new LocEdString("Min. width")); maxWidthField = new GUIIntField(new LocEdString("Max. width")); fixedHeightField = new GUIToggleField(new LocEdString("Fixed height")); heightField = new GUIIntField(new LocEdString("Height")); minHeightField = new GUIIntField(new LocEdString("Min. height")); maxHeightField = new GUIIntField(new LocEdString("Max. height")); contentLayout.AddElement(fixedWidthField); contentLayout.AddElement(widthField); contentLayout.AddElement(minWidthField); contentLayout.AddElement(maxWidthField); contentLayout.AddElement(fixedHeightField); contentLayout.AddElement(heightField); contentLayout.AddElement(minHeightField); contentLayout.AddElement(maxHeightField); foldout.OnToggled += x => { panel.Active = x; isExpanded = x; }; fontField.OnChanged += x => { Font font = Resources.Load <Font>(x.UUID); GetStyle().Font = font; MarkAsModified(); ConfirmModify(); }; fontSizeField.OnChanged += x => { GetStyle().FontSize = x; MarkAsModified(); }; fontSizeField.OnFocusLost += ConfirmModify; fontSizeField.OnConfirmed += ConfirmModify; horzAlignField.OnSelectionChanged += x => { GetStyle().TextHorzAlign = (TextHorzAlign)x; MarkAsModified(); ConfirmModify(); }; vertAlignField.OnSelectionChanged += x => { GetStyle().TextVertAlign = (TextVertAlign)x; MarkAsModified(); ConfirmModify(); }; imagePositionField.OnSelectionChanged += x => { GetStyle().ImagePosition = (GUIImagePosition)x; MarkAsModified(); ConfirmModify(); }; wordWrapField.OnChanged += x => { GetStyle().WordWrap = x; MarkAsModified(); ConfirmModify(); }; normalGUI.OnChanged += x => { GetStyle().Normal = x; MarkAsModified(); ConfirmModify(); }; hoverGUI.OnChanged += x => { GetStyle().Hover = x; MarkAsModified(); ConfirmModify(); }; activeGUI.OnChanged += x => { GetStyle().Active = x; MarkAsModified(); ConfirmModify(); }; focusedGUI.OnChanged += x => { GetStyle().Focused = x; MarkAsModified(); ConfirmModify(); }; normalOnGUI.OnChanged += x => { GetStyle().NormalOn = x; MarkAsModified(); ConfirmModify(); }; hoverOnGUI.OnChanged += x => { GetStyle().HoverOn = x; MarkAsModified(); ConfirmModify(); }; activeOnGUI.OnChanged += x => { GetStyle().ActiveOn = x; MarkAsModified(); ConfirmModify(); }; focusedOnGUI.OnChanged += x => { GetStyle().FocusedOn = x; MarkAsModified(); ConfirmModify(); }; borderGUI.OnChanged += x => { GetStyle().Border = x; MarkAsModified(); }; marginsGUI.OnChanged += x => { GetStyle().Margins = x; MarkAsModified(); }; contentOffsetGUI.OnChanged += x => { GetStyle().ContentOffset = x; MarkAsModified(); }; borderGUI.OnConfirmed += ConfirmModify; marginsGUI.OnConfirmed += ConfirmModify; contentOffsetGUI.OnConfirmed += ConfirmModify; fixedWidthField.OnChanged += x => { GetStyle().FixedWidth = x; MarkAsModified(); ConfirmModify(); }; widthField.OnChanged += x => GetStyle().Width = x; widthField.OnFocusLost += ConfirmModify; widthField.OnConfirmed += ConfirmModify; minWidthField.OnChanged += x => GetStyle().MinWidth = x; minWidthField.OnFocusLost += ConfirmModify; minWidthField.OnConfirmed += ConfirmModify; maxWidthField.OnChanged += x => GetStyle().MaxWidth = x; maxWidthField.OnFocusLost += ConfirmModify; maxWidthField.OnConfirmed += ConfirmModify; fixedHeightField.OnChanged += x => { GetStyle().FixedHeight = x; MarkAsModified(); ConfirmModify(); }; heightField.OnChanged += x => GetStyle().Height = x; heightField.OnFocusLost += ConfirmModify; heightField.OnConfirmed += ConfirmModify; minHeightField.OnChanged += x => GetStyle().MinHeight = x; minHeightField.OnFocusLost += ConfirmModify; minHeightField.OnConfirmed += ConfirmModify; maxHeightField.OnChanged += x => GetStyle().MaxHeight = x; maxHeightField.OnFocusLost += ConfirmModify; maxHeightField.OnConfirmed += ConfirmModify; foldout.Value = isExpanded; panel.Active = isExpanded; }
/// <summary> /// Rebuilds the GUI object header if needed. /// </summary> /// <param name="layoutIndex">Index at which to insert the GUI elements.</param> protected void BuildGUI(int layoutIndex) { Action BuildEmptyGUI = () => { guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0); guiInternalTitleLayout.AddElement(new GUILabel(title)); guiInternalTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100))); if (!property.IsValueType) { GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create), new LocEdString("Create")); GUIButton createBtn = new GUIButton(createIcon, GUIOption.FixedWidth(30)); createBtn.OnClick += OnCreateButtonClicked; guiInternalTitleLayout.AddElement(createBtn); } }; Action BuildFilledGUI = () => { guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0); GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout); guiFoldout.Value = isExpanded; guiFoldout.AcceptsKeyFocus = false; guiFoldout.OnToggled += OnFoldoutToggled; guiInternalTitleLayout.AddElement(guiFoldout); GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear), new LocEdString("Clear")); GUIButton clearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(20)); clearBtn.OnClick += OnClearButtonClicked; guiInternalTitleLayout.AddElement(clearBtn); if (isExpanded) { SerializableObject serializableObject = property.GetObject(); SerializableField[] fields = serializableObject.Fields; if (fields.Length > 0) { guiChildLayout = guiLayout.AddLayoutX(); guiChildLayout.AddSpace(IndentAmount); GUIPanel guiContentPanel = guiChildLayout.AddPanel(); GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX(); guiIndentLayoutX.AddSpace(IndentAmount); GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); guiIndentLayoutX.AddSpace(IndentAmount); guiChildLayout.AddSpace(IndentAmount); short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1); string bgPanelStyle = depth % 2 == 0 ? EditorStylesInternal.InspectorContentBgAlternate : EditorStylesInternal.InspectorContentBg; GUIPanel backgroundPanel = guiContentPanel.AddPanel(backgroundDepth); GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle); backgroundPanel.AddElement(inspectorContentBg); int currentIndex = 0; foreach (var field in fields) { if (!field.Inspectable) { continue; } string childPath = path + "/" + field.Name; InspectableField inspectable = CreateInspectable(parent, field.Name, childPath, currentIndex, depth + 1, new InspectableFieldLayout(guiContentLayout), field.GetProperty(), InspectableFieldStyle.Create(field)); children.Add(inspectable); currentIndex += inspectable.GetNumLayoutElements(); } } } else { guiChildLayout = null; } }; if (state == State.None) { if (propertyValue != null) { BuildFilledGUI(); state = State.Filled; } else { BuildEmptyGUI(); state = State.Empty; } } else if (state == State.Empty) { if (propertyValue != null) { guiInternalTitleLayout.Destroy(); BuildFilledGUI(); state = State.Filled; } } else if (state == State.Filled) { foreach (var child in children) { child.Destroy(); } children.Clear(); guiInternalTitleLayout.Destroy(); if (guiChildLayout != null) { guiChildLayout.Destroy(); guiChildLayout = null; } if (propertyValue == null) { BuildEmptyGUI(); state = State.Empty; } else { BuildFilledGUI(); } } }
/// <inheritdoc/> protected internal override void Initialize() { Animation animation = (Animation)InspectedObject; drawer.AddDefault(animation); // Morph shapes Renderable renderable = animation.SceneObject.GetComponent <Renderable>(); MorphShapes morphShapes = renderable?.Mesh.Value?.MorphShapes; if (morphShapes != null) { GUIToggle morphShapesToggle = new GUIToggle(new LocEdString("Morph shapes"), EditorStyles.Foldout); Layout.AddElement(morphShapesToggle); GUILayoutY channelsLayout = Layout.AddLayoutY(); morphShapesToggle.OnToggled += x => { channelsLayout.Active = x; Persistent.SetBool("Channels_Expanded", x); }; channelsLayout.Active = Persistent.GetBool("Channels_Expanded"); MorphChannel[] channels = morphShapes.Channels; for (int i = 0; i < channels.Length; i++) { GUILayoutY channelLayout = channelsLayout.AddLayoutY(); GUILayoutX channelTitleLayout = channelLayout.AddLayoutX(); channelLayout.AddSpace(5); GUILayoutY channelContentLayout = channelLayout.AddLayoutY(); string channelName = channels[i].Name; GUIToggle channelNameField = new GUIToggle(channelName, EditorStyles.Expand, GUIOption.FlexibleWidth()); channelTitleLayout.AddSpace(15); // Indent channelTitleLayout.AddElement(channelNameField); channelTitleLayout.AddFlexibleSpace(); channelNameField.OnToggled += x => { channelContentLayout.Active = x; Persistent.SetBool(channelName + "_Expanded", x); }; channelContentLayout.Active = Persistent.GetBool(channelName + "_Expanded"); MorphShape[] shapes = channels[i].Shapes; for (int j = 0; j < shapes.Length; j++) { GUILayoutX shapeLayout = channelContentLayout.AddLayoutX(); channelContentLayout.AddSpace(5); LocString nameString = new LocString("[{0}]. {1}"); nameString.SetParameter(0, j.ToString()); nameString.SetParameter(1, shapes[j].Name); GUILabel shapeNameField = new GUILabel(shapes[j].Name); LocString weightString = new LocEdString("Weight: {0}"); weightString.SetParameter(0, shapes[j].Weight.ToString()); GUILabel weightField = new GUILabel(weightString); shapeLayout.AddSpace(30); // Indent shapeLayout.AddElement(shapeNameField); shapeLayout.AddFlexibleSpace(); shapeLayout.AddElement(weightField); } } } }