private void BuildGUI() { progressBar = new GUIProgressBar(); messageLabel = new GUILabel(""); GUILayoutY layoutY = GUI.AddLayoutY(); layoutY.AddFlexibleSpace(); GUILayoutX messageLayout = layoutY.AddLayoutX(); messageLayout.AddFlexibleSpace(); messageLayout.AddElement(messageLabel); messageLayout.AddFlexibleSpace(); layoutY.AddSpace(10); GUILayoutX barLayout = layoutY.AddLayoutX(); barLayout.AddSpace(30); barLayout.AddElement(progressBar); barLayout.AddSpace(30); layoutY.AddFlexibleSpace(); Percent = percent; messageLabel.SetContent(message); }
/// <summary> /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before /// use. /// </summary> /// <param name="parent">Scene window that this drop down window is a part of.</param> /// <param name="cameraOptions">Reference to the current scene camera options.</param> internal void Initialize(SceneWindow parent) { this.Parent = parent; GUIEnumField cameraProjectionTypeField = new GUIEnumField(typeof(ProjectionType), new LocEdString("Projection type")); cameraProjectionTypeField.Value = (ulong)Parent.ProjectionType; cameraProjectionTypeField.OnSelectionChanged += SetCameraProjectionType; nearClipPlaneInput = new GUIFloatField(new LocEdString("Near plane")); nearClipPlaneInput.Value = Parent.NearClipPlane; nearClipPlaneInput.OnChanged += OnNearClipPlaneChanged; nearClipPlaneInput.SetRange(SceneCameraOptions.MinNearClipPlane, SceneCameraOptions.MaxNearClipPlane); farClipPlaneInput = new GUIFloatField(new LocEdString("Far plane")); farClipPlaneInput.Value = Parent.FarClipPlane; farClipPlaneInput.OnChanged += OnFarClipPlaneChanged; farClipPlaneInput.SetRange(SceneCameraOptions.MinFarClipPlane, SceneCameraOptions.MaxFarClipPlane); cameraFieldOfView = new GUISliderField(1, 360, new LocEdString("Field of view")); cameraFieldOfView.Value = Parent.FieldOfView.Degrees; cameraFieldOfView.OnChanged += SetFieldOfView; cameraOrthographicSize = new GUIFloatField(new LocEdString("Orthographic size")); cameraOrthographicSize.Value = Parent.OrthographicSize; cameraOrthographicSize.OnChanged += SetOrthographicSize; GUISliderField cameraScrollSpeed = new GUISliderField(SceneCameraOptions.MinScrollSpeed, SceneCameraOptions.MaxScrollSpeed, new LocEdString("Scroll speed")); cameraScrollSpeed.Value = Parent.ScrollSpeed; cameraScrollSpeed.OnChanged += SetScrollSpeed; GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddSpace(10); GUILayoutX cameraOptionsLayoutX = vertLayout.AddLayoutX(); cameraOptionsLayoutX.AddSpace(10); GUILayoutY cameraOptionsLayoutY = cameraOptionsLayoutX.AddLayoutY(); cameraOptionsLayoutY.AddElement(cameraProjectionTypeField); cameraOptionsLayoutY.AddElement(nearClipPlaneInput); cameraOptionsLayoutY.AddElement(farClipPlaneInput); cameraOptionsLayoutY.AddElement(cameraFieldOfView); cameraOptionsLayoutY.AddElement(cameraOrthographicSize); cameraOptionsLayoutY.AddElement(cameraScrollSpeed); cameraOptionsLayoutX.AddSpace(10); vertLayout.AddSpace(10); ToggleTypeSpecificFields((ProjectionType)cameraProjectionTypeField.Value); }
private void CreateCollaboratorGUI(GUILayoutY layout, string name, string area) { GUILabel nameLabel = new GUILabel(new LocEdString(name), GUIOption.FixedWidth(150)); GUILabel areaLabel = new GUILabel(new LocEdString(area), GUIOption.FixedWidth(220)); GUILayoutX horzLayout = layout.AddLayoutX(); horzLayout.AddSpace(10); horzLayout.AddElement(nameLabel); horzLayout.AddSpace(10); horzLayout.AddElement(areaLabel); horzLayout.AddSpace(10); }
private void CreateThirdPartyGUI(GUILayoutY layout, string name, string webURL) { GUILabel label = new GUILabel(new LocEdString(name), GUIOption.FixedWidth(150)); GUIButton linkBtn = new GUIButton(new LocEdString("Website"), GUIOption.FixedWidth(50)); GUILayoutX horzLayout = layout.AddLayoutX(); horzLayout.AddSpace(10); horzLayout.AddElement(label); horzLayout.AddSpace(10); horzLayout.AddElement(linkBtn); horzLayout.AddSpace(10); linkBtn.OnClick += () => { System.Diagnostics.Process.Start(webURL); }; }
private void CreateNameURLBtnPair(GUILayoutY layout, string name, string webURL, string btnText) { GUILabel label = new GUILabel(new LocEdString(name), GUIOption.FixedWidth(300)); GUIButton linkBtn = new GUIButton(new LocEdString(btnText), GUIOption.FixedWidth(100)); GUILayoutX horzLayout = layout.AddLayoutX(); horzLayout.AddSpace(10); horzLayout.AddElement(label); horzLayout.AddSpace(10); horzLayout.AddElement(linkBtn); horzLayout.AddSpace(10); linkBtn.OnClick += () => { System.Diagnostics.Process.Start(webURL); }; }
/// <summary> /// Creates GUI elements for fields specific to the spherical joint. /// </summary> protected void BuildGUI(SphericalJoint joint) { enableLimitField.OnChanged += x => { joint.SetFlag(SphericalJointFlag.Limit, x); MarkAsModified(); ConfirmModify(); ToggleLimitFields(x); }; Layout.AddElement(enableLimitField); limitLayout = Layout.AddLayoutX(); { limitLayout.AddSpace(10); GUILayoutY limitContentsLayout = limitLayout.AddLayoutY(); limitGUI = new LimitConeRangeGUI(joint.Limit, limitContentsLayout, Persistent); limitGUI.OnChanged += (x, y) => { joint.Limit = x; joint.Limit.SetBase(y); MarkAsModified(); }; limitGUI.OnConfirmed += ConfirmModify; } ToggleLimitFields(joint.HasFlag(SphericalJointFlag.Limit)); base.BuildGUI(joint, true); }
/// <summary> /// Registers a new row in the layout. The row cannot be selected as the output field, but rather can be expanded /// so it displays child elements. /// </summary> /// <param name="layout">Layout to append the row GUI elements to.</param> /// <param name="icon">Optional icon to display next to the name. Can be null.</param> /// <param name="name">Name of the field.</param> /// <param name="so">Parent scene object of the field.</param> /// <param name="component">Parent component of the field. Can be null if field belongs to <see cref="SceneObject"/>. /// </param> /// <param name="path">Slash separated path to the field from its parent object.</param> /// <param name="toggleCallback">Callback to trigger when the user expands or collapses the foldout.</param> /// <returns>Element object storing all information about the added field.</returns> private Element AddFoldoutRow(GUILayout layout, SpriteTexture icon, string name, SceneObject so, Component component, string path, Action <Element, bool> toggleCallback) { Element element = new Element(so, component, path); GUILayoutY elementLayout = layout.AddLayoutY(); GUILayoutX foldoutLayout = elementLayout.AddLayoutX(); element.toggle = new GUIToggle("", EditorStyles.Expand); element.toggle.OnToggled += x => toggleCallback(element, x); foldoutLayout.AddSpace(PADDING); foldoutLayout.AddElement(element.toggle); if (icon != null) { GUITexture guiIcon = new GUITexture(icon, GUIOption.FixedWidth(16), GUIOption.FixedWidth(16)); foldoutLayout.AddElement(guiIcon); } GUILabel label = new GUILabel(new LocEdString(name)); foldoutLayout.AddElement(label); foldoutLayout.AddFlexibleSpace(); element.indentLayout = elementLayout.AddLayoutX(); element.indentLayout.AddSpace(INDENT_AMOUNT); element.childLayout = element.indentLayout.AddLayoutY(); element.indentLayout.Active = false; return(element); }
/// <summary> /// Creates GUI elements for fields specific to the slider joint. /// </summary> protected void BuildGUI(SliderJoint joint) { enableLimitField.OnChanged += x => { joint.EnableLimit = x; MarkAsModified(); ConfirmModify(); ToggleLimitFields(x); }; Layout.AddElement(enableLimitField); limitLayout = Layout.AddLayoutX(); { limitLayout.AddSpace(10); GUILayoutY limitContentsLayout = limitLayout.AddLayoutY(); limitGUI = new LimitLinearRangeGUI(joint.Limit, limitContentsLayout, Persistent); limitGUI.OnChanged += (x, y) => { joint.Limit = new LimitLinearRange(x, y); MarkAsModified(); }; limitGUI.OnConfirmed += ConfirmModify; } ToggleLimitFields(joint.EnableLimit); base.BuildGUI(joint, true); }
public GUIAnimFieldEntry(GUIAnimFieldLayouts layouts, string path, bool child, int indentAmount) { this.path = path; GUILayoutX toggleLayout = layouts.main.AddLayoutX(); toggleLayout.AddSpace(indentAmount); selectionBtn = new GUIButton(GetDisplayName(path, child), EditorStyles.Label, GUIOption.FlexibleWidth()); selectionBtn.OnClick += () => { OnEntrySelected?.Invoke(path); }; toggleLayout.AddElement(selectionBtn); entryHeight = selectionBtn.Bounds.height; backgroundTexture = new GUITexture(Builtin.WhiteTexture, GUITextureScaleMode.StretchToFit, GUIOption.FlexibleWidth()); backgroundTexture.SetTint(Color.Transparent); backgroundTexture.SetHeight(entryHeight); layouts.background.AddElement(backgroundTexture); }
/// <summary> /// Creates GUI elements for fields specific to the spherical joint. /// </summary> protected void BuildGUI(SphericalJoint joint) { enableLimitField.OnChanged += x => { joint.EnableLimit = x; MarkAsModified(); ConfirmModify(); ToggleLimitFields(x); }; Layout.AddElement(enableLimitField); limitLayout = Layout.AddLayoutX(); { limitLayout.AddSpace(10); GUILayoutY limitContentsLayout = limitLayout.AddLayoutY(); limitGUI = new LimitConeRangeGUI(joint.Limit, limitContentsLayout, Persistent); limitGUI.OnChanged += (x, y) => { joint.Limit = new LimitConeRange(x, y); MarkAsModified(); }; limitGUI.OnConfirmed += ConfirmModify; } ToggleLimitFields(joint.EnableLimit); base.BuildGUI(joint, true); }
/// <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.OnToggled += x => { properties.SetBool(prefix + "_hardLimit_Expanded", x); ToggleLimitFields(); }; contactDistanceField.OnChanged += x => { this.limitData.contactDist = x; MarkAsModified(); }; contactDistanceField.OnFocusLost += ConfirmModify; contactDistanceField.OnConfirmed += ConfirmModify; softFoldout.OnToggled += x => { properties.SetBool(prefix + "_softLimit_Expanded", x); ToggleLimitFields(); }; restitutionField.OnChanged += x => { this.limitData.restitution = x; MarkAsModified(); }; restitutionField.OnFocusLost += ConfirmModify; 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; } } }
public GUIAnimSimpleEntry(GUIAnimFieldLayouts layouts, string path, Color color, bool child = false) : base(layouts, path, child, child ? 45 : 30) { valueDisplay = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight())); underlayLayout = layouts.underlay.AddLayoutX(); underlayLayout.AddSpace(child ? 30 : 15); GUITexture colorSquare = new GUITexture(Builtin.WhiteTexture, GUIOption.FixedWidth(10), GUIOption.FixedHeight(10)); colorSquare.SetTint(color); underlayLayout.AddElement(colorSquare); underlayLayout.AddFlexibleSpace(); underlayLayout.AddElement(valueDisplay); underlayLayout.AddSpace(50); overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight())); layouts.overlay.AddElement(overlaySpacing); }
private void BuildGUI() { progressBar = new GUIProgressBar(); messageLabel = new GUILabel("", EditorStyles.MultiLineLabelCentered, GUIOption.FixedHeight(60)); cancelImport = new GUIButton(new LocEdString("Cancel import")); cancelImport.OnClick += () => { ProjectLibrary.CancelImport(); cancelImport.Disabled = true; }; GUILayoutY layoutY = GUI.AddLayoutY(); layoutY.AddFlexibleSpace(); GUILayoutX messageLayout = layoutY.AddLayoutX(); messageLayout.AddSpace(15); messageLayout.AddElement(messageLabel); messageLayout.AddSpace(15); layoutY.AddSpace(10); GUILayoutX barLayout = layoutY.AddLayoutX(); barLayout.AddSpace(30); barLayout.AddElement(progressBar); barLayout.AddSpace(30); layoutY.AddSpace(20); GUILayoutX buttonLayout = layoutY.AddLayoutX(); buttonLayout.AddFlexibleSpace(); buttonLayout.AddElement(cancelImport); buttonLayout.AddFlexibleSpace(); layoutY.AddFlexibleSpace(); messageLabel.SetContent(new LocEdString("Resource import is still in progress. You can wait until it " + "finishes or cancel import. \n\nNote that even when cancelling you will need to wait for active import threads to finish.")); }
/// <inheritdoc/> public override void BuildGUI() { main = Layout.AddPanel(0, 1, 1, GUIOption.FixedHeight(ENTRY_HEIGHT)); overlay = main.AddPanel(-1, 0, 0, GUIOption.FixedHeight(ENTRY_HEIGHT)); underlay = main.AddPanel(1, 0, 0, GUIOption.FixedHeight(ENTRY_HEIGHT)); GUILayoutX mainLayout = main.AddLayoutX(); GUILayoutY overlayLayout = overlay.AddLayoutY(); GUILayoutY underlayLayout = underlay.AddLayoutY(); icon = new GUITexture(null, GUIOption.FixedWidth(32), GUIOption.FixedHeight(32)); messageLabel = new GUILabel(new LocEdString(""), EditorStyles.MultiLineLabel, GUIOption.FixedHeight(MESSAGE_HEIGHT)); functionLabel = new GUILabel(new LocEdString(""), GUIOption.FixedHeight(CALLER_LABEL_HEIGHT)); mainLayout.AddSpace(PADDING); GUILayoutY iconLayout = mainLayout.AddLayoutY(); iconLayout.AddFlexibleSpace(); iconLayout.AddElement(icon); iconLayout.AddFlexibleSpace(); mainLayout.AddSpace(PADDING); GUILayoutY messageLayout = mainLayout.AddLayoutY(); messageLayout.AddSpace(PADDING); messageLayout.AddElement(messageLabel); messageLayout.AddElement(functionLabel); messageLayout.AddSpace(PADDING); mainLayout.AddFlexibleSpace(); mainLayout.AddSpace(PADDING); background = new GUITexture(Builtin.WhiteTexture, GUIOption.FixedHeight(ENTRY_HEIGHT)); underlayLayout.AddElement(background); GUIButton button = new GUIButton(new LocEdString(""), EditorStyles.Blank, GUIOption.FixedHeight(ENTRY_HEIGHT)); overlayLayout.AddElement(button); button.OnClick += OnClicked; button.OnDoubleClick += OnDoubleClicked; }
public GUIAnimMissingEntry(GUIAnimFieldLayouts layouts, string path) : base(layouts, path, false, 15) { missingLabel = new GUILabel("Missing property!", GUIOption.FixedHeight(GetEntryHeight())); underlayLayout = layouts.underlay.AddLayoutX(); underlayLayout.AddFlexibleSpace(); underlayLayout.AddElement(missingLabel); underlayLayout.AddSpace(50); overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight())); layouts.overlay.AddElement(overlaySpacing); }
/// <inheritdoc/> protected internal override void Initialize(int index) { guiLayout = layout.AddLayoutY(index); GUILayoutX guiTitleLayout = guiLayout.AddLayoutX(); GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout); guiFoldout.Value = isExpanded; guiFoldout.AcceptsKeyFocus = false; guiFoldout.OnToggled += OnFoldoutToggled; guiTitleLayout.AddElement(guiFoldout); GUILayoutX categoryContentLayout = guiLayout.AddLayoutX(); categoryContentLayout.AddSpace(IndentAmount); guiContentPanel = categoryContentLayout.AddPanel(); GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX(); guiIndentLayoutX.AddSpace(IndentAmount); GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); ChildLayout = guiIndentLayoutY.AddLayoutY(); guiIndentLayoutY.AddSpace(IndentAmount); guiIndentLayoutX.AddSpace(IndentAmount); categoryContentLayout.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); guiContentPanel.Active = isExpanded; }
/// <summary> /// (Re)creates all row GUI elements. /// </summary> internal protected void BuildGUI() { keyLayout.Clear(); valueLayout.Clear(); GUILayoutX externalTitleLayout = CreateKeyGUI(keyLayout); CreateValueGUI(valueLayout); if (localTitleLayout || (titleLayout != null && titleLayout == externalTitleLayout)) { return; } if (externalTitleLayout != null) { localTitleLayout = false; titleLayout = externalTitleLayout; } else { GUILayoutY buttonCenter = keyRowLayout.AddLayoutY(); buttonCenter.AddFlexibleSpace(); titleLayout = buttonCenter.AddLayoutX(); buttonCenter.AddFlexibleSpace(); localTitleLayout = true; } GUIContent cloneIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clone), new LocEdString("Clone")); GUIContent deleteIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Delete), new LocEdString("Delete")); GUIContent editIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Edit), new LocEdString("Edit")); cloneBtn = new GUIButton(cloneIcon, GUIOption.FixedWidth(30)); deleteBtn = new GUIButton(deleteIcon, GUIOption.FixedWidth(30)); editBtn = new GUIButton(editIcon, GUIOption.FixedWidth(30)); cloneBtn.OnClick += () => parent.OnCloneButtonClicked(rowIdx); deleteBtn.OnClick += () => parent.OnDeleteButtonClicked(rowIdx); editBtn.OnClick += () => parent.OnEditButtonClicked(rowIdx); titleLayout.AddElement(cloneBtn); titleLayout.AddElement(deleteBtn); titleLayout.AddSpace(10); titleLayout.AddElement(editBtn); EditMode = editMode; }
/// <summary> /// Registers a new row in the layout. The row cannot have any further children and can be selected as the output /// field. /// </summary> /// <param name="layout">Layout to append the row GUI elements to.</param> /// <param name="name">Name of the field.</param> /// <param name="so">Parent scene object of the field.</param> /// <param name="component">Parent component of the field. Can be null if field belongs to <see cref="SceneObject"/>. /// </param> /// <param name="path">Slash separated path to the field from its parent object.</param> /// <param name="type">Data type stored in the field.</param> /// <returns>Element object storing all information about the added field.</returns> private Element AddFieldRow(GUILayout layout, string name, SceneObject so, Component component, string path, SerializableProperty.FieldType type) { Element element = new Element(so, component, path); GUILayoutX elementLayout = layout.AddLayoutX(); elementLayout.AddSpace(PADDING); elementLayout.AddSpace(foldoutWidth); GUILabel label = new GUILabel(new LocEdString(name)); elementLayout.AddElement(label); GUIButton selectBtn = new GUIButton(new LocEdString("Select")); selectBtn.OnClick += () => { DoOnElementSelected(element, type); }; elementLayout.AddFlexibleSpace(); elementLayout.AddElement(selectBtn); elementLayout.AddSpace(5); element.path = path; return(element); }
/// <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> /// Creates GUI elements for fields specific to the spherical joint. /// </summary> protected void BuildGUI(D6Joint joint) { for (int i = 0; i < (int)D6JointAxis.Count; i++) { D6JointAxis axis = (D6JointAxis)i; string entryName = Enum.GetName(typeof(D6JointAxis), axis); motionFields[i] = new GUIEnumField(typeof(D6JointMotion), new LocEdString(entryName)); motionFields[i].OnSelectionChanged += x => { joint.SetMotion(axis, (D6JointMotion)x); MarkAsModified(); ConfirmModify(); }; } linearLimitFoldout.AcceptsKeyFocus = false; linearLimitFoldout.OnToggled += x => { linearLimitLayout.Active = x; Persistent.SetBool("linearLimit_Expanded", x); }; twistLimitFoldout.AcceptsKeyFocus = false; twistLimitFoldout.OnToggled += x => { twistLimitLayout.Active = x; Persistent.SetBool("twistLimit_Expanded", x); }; swingLimitFoldout.AcceptsKeyFocus = false; swingLimitFoldout.OnToggled += x => { swingLimitLayout.Active = x; Persistent.SetBool("swingLimit_Expanded", x); }; driveFoldout.AcceptsKeyFocus = false; driveFoldout.OnToggled += x => { driveLayout.Active = x; Persistent.SetBool("drive_Expanded", x); }; drivePositionField.OnChanged += x => { joint.SetDriveTransform(x, joint.DriveRotation); MarkAsModified(); }; drivePositionField.OnFocusLost += ConfirmModify; drivePositionField.OnConfirmed += ConfirmModify; driveRotationField.OnChanged += x => { joint.SetDriveTransform(joint.DrivePosition, Quaternion.FromEuler(x)); MarkAsModified(); }; driveRotationField.OnFocusLost += ConfirmModify; driveRotationField.OnConfirmed += ConfirmModify; driveLinVelocityField.OnChanged += x => { joint.SetDriveVelocity(x, joint.DriveAngularVelocity); MarkAsModified(); }; driveLinVelocityField.OnFocusLost += ConfirmModify; driveLinVelocityField.OnConfirmed += ConfirmModify; driveAngVelocityField.OnChanged += x => { joint.SetDriveVelocity(joint.DriveLinearVelocity, x); MarkAsModified(); }; driveAngVelocityField.OnFocusLost += ConfirmModify; driveAngVelocityField.OnConfirmed += ConfirmModify; for (int i = 0; i < (int)D6JointAxis.Count; i++) { Layout.AddElement(motionFields[i]); } Layout.AddElement(linearLimitFoldout); linearLimitLayout = Layout.AddLayoutX(); { linearLimitLayout.AddSpace(10); GUILayoutY linearLimitContentsLayout = linearLimitLayout.AddLayoutY(); limitLinearGUI = new LimitLinearGUI(joint.LimitLinear, linearLimitContentsLayout, Persistent); limitLinearGUI.OnChanged += (x, y) => { joint.LimitLinear = x; joint.LimitLinear.SetBase(y); MarkAsModified(); }; limitLinearGUI.OnConfirmed += ConfirmModify; } Layout.AddElement(twistLimitFoldout); twistLimitLayout = Layout.AddLayoutX(); { twistLimitLayout.AddSpace(10); GUILayoutY twistLimitContentsLayout = twistLimitLayout.AddLayoutY(); limitTwistGUI = new LimitAngularRangeGUI(joint.LimitTwist, twistLimitContentsLayout, Persistent); limitTwistGUI.OnChanged += (x, y) => { joint.LimitTwist = x; joint.LimitTwist.SetBase(y); MarkAsModified(); }; limitTwistGUI.OnConfirmed += ConfirmModify; } Layout.AddElement(swingLimitFoldout); swingLimitLayout = Layout.AddLayoutX(); { swingLimitLayout.AddSpace(10); GUILayoutY swingLimitContentsLayout = swingLimitLayout.AddLayoutY(); limitSwingGUI = new LimitConeRangeGUI(joint.LimitSwing, swingLimitContentsLayout, Persistent); limitSwingGUI.OnChanged += (x, y) => { joint.LimitSwing = x; joint.LimitSwing.SetBase(y); MarkAsModified(); }; limitSwingGUI.OnConfirmed += ConfirmModify; } Layout.AddElement(driveFoldout); driveLayout = Layout.AddLayoutX(); { driveLayout.AddSpace(10); GUILayoutY driveContentsLayout = driveLayout.AddLayoutY(); for (int i = 0; i < (int)D6JointDriveType.Count; i++) { D6JointDriveType type = (D6JointDriveType)i; drivesGUI[i] = new D6JointDriveGUI(joint.GetDrive(type), driveContentsLayout); drivesGUI[i].OnChanged += x => { joint.SetDrive(type, x); MarkAsModified(); }; drivesGUI[i].OnConfirmed += ConfirmModify; } driveContentsLayout.AddElement(drivePositionField); driveContentsLayout.AddElement(driveRotationField); driveContentsLayout.AddElement(driveLinVelocityField); driveContentsLayout.AddElement(driveAngVelocityField); } linearLimitLayout.Active = Persistent.GetBool("linearLimit_Expanded"); twistLimitLayout.Active = Persistent.GetBool("twistLimit_Expanded"); swingLimitLayout.Active = Persistent.GetBool("swingLimit_Expanded"); driveLayout.Active = Persistent.GetBool("drive_Expanded"); base.BuildGUI(joint, true); }
/// <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> /// 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(); } }
/// <summary> /// Creates GUI elements for fields specific to the hinge joint. /// </summary> protected void BuildGUI(HingeJoint joint) { enableLimitField.OnChanged += x => { joint.EnableLimit = x; MarkAsModified(); ConfirmModify(); ToggleLimitFields(x); }; enableDriveField.OnChanged += x => { joint.EnableDrive = x; MarkAsModified(); ConfirmModify(); ToggleDriveFields(x); }; speedField.OnChanged += x => { HingeJointDriveData driveData = joint.Drive.Data; driveData.speed = x; joint.Drive = new HingeJointDrive(driveData); MarkAsModified(); }; speedField.OnFocusLost += ConfirmModify; speedField.OnConfirmed += ConfirmModify; forceLimitField.OnChanged += x => { HingeJointDriveData driveData = joint.Drive.Data; driveData.forceLimit = x; joint.Drive = new HingeJointDrive(driveData); MarkAsModified(); }; forceLimitField.OnFocusLost += ConfirmModify; forceLimitField.OnConfirmed += ConfirmModify; gearRatioField.OnChanged += x => { HingeJointDriveData driveData = joint.Drive.Data; driveData.gearRatio = x; joint.Drive = new HingeJointDrive(driveData); MarkAsModified(); }; gearRatioField.OnFocusLost += ConfirmModify; gearRatioField.OnConfirmed += ConfirmModify; freeSpinField.OnChanged += x => { HingeJointDriveData driveData = joint.Drive.Data; driveData.freeSpin = x; joint.Drive = new HingeJointDrive(driveData); MarkAsModified(); ConfirmModify(); }; Layout.AddElement(enableLimitField); limitLayout = Layout.AddLayoutX(); { limitLayout.AddSpace(10); GUILayoutY limitContentsLayout = limitLayout.AddLayoutY(); limitGUI = new LimitAngularRangeGUI(joint.Limit, limitContentsLayout, Persistent); limitGUI.OnChanged += (x, y) => { joint.Limit = new LimitAngularRange(x, y); MarkAsModified(); }; limitGUI.OnConfirmed += ConfirmModify; } Layout.AddElement(enableDriveField); driveLayout = Layout.AddLayoutX(); { driveLayout.AddSpace(10); GUILayoutY driveContentsLayout = driveLayout.AddLayoutY(); driveContentsLayout.AddElement(speedField); driveContentsLayout.AddElement(forceLimitField); driveContentsLayout.AddElement(gearRatioField); driveContentsLayout.AddElement(freeSpinField); } ToggleLimitFields(joint.EnableLimit); ToggleDriveFields(joint.EnableDrive); base.BuildGUI(joint, true); }
/// <summary> /// Creates GUI elements for fields specific to the spherical joint. /// </summary> protected void BuildGUI(D6Joint joint) { for (int i = 0; i < (int) D6JointAxis.Count; i++) { D6JointAxis axis = (D6JointAxis) i; string entryName = Enum.GetName(typeof (D6JointAxis), axis); motionFields[i] = new GUIEnumField(typeof (D6JointMotion), new LocEdString(entryName)); motionFields[i].OnSelectionChanged += x => { joint.SetMotion(axis, (D6JointMotion)x); MarkAsModified(); ConfirmModify(); }; } linearLimitFoldout.OnToggled += x => { linearLimitLayout.Active = x; Persistent.SetBool("linearLimit_Expanded", x); }; twistLimitFoldout.OnToggled += x => { twistLimitLayout.Active = x; Persistent.SetBool("twistLimit_Expanded", x); }; swingLimitFoldout.OnToggled += x => { swingLimitLayout.Active = x; Persistent.SetBool("swingLimit_Expanded", x); }; driveFoldout.OnToggled += x => { driveLayout.Active = x; Persistent.SetBool("drive_Expanded", x); }; drivePositionField.OnChanged += x => { joint.DrivePosition = x; MarkAsModified(); }; drivePositionField.OnFocusLost += ConfirmModify; drivePositionField.OnConfirmed += ConfirmModify; driveRotationField.OnChanged += x => { joint.DriveRotation = Quaternion.FromEuler(x); MarkAsModified(); }; driveRotationField.OnFocusLost += ConfirmModify; driveRotationField.OnConfirmed += ConfirmModify; driveLinVelocityField.OnChanged += x => { joint.DriveLinearVelocity = x; MarkAsModified(); }; driveLinVelocityField.OnFocusLost += ConfirmModify; driveLinVelocityField.OnConfirmed += ConfirmModify; driveAngVelocityField.OnChanged += x => { joint.DriveAngularVelocity = x; MarkAsModified(); }; driveAngVelocityField.OnFocusLost += ConfirmModify; driveAngVelocityField.OnConfirmed += ConfirmModify; for (int i = 0; i < (int) D6JointAxis.Count; i++) Layout.AddElement(motionFields[i]); Layout.AddElement(linearLimitFoldout); linearLimitLayout = Layout.AddLayoutX(); { linearLimitLayout.AddSpace(10); GUILayoutY linearLimitContentsLayout = linearLimitLayout.AddLayoutY(); limitLinearGUI = new LimitLinearGUI(joint.LimitLinear, linearLimitContentsLayout, Persistent); limitLinearGUI.OnChanged += (x, y) => { joint.LimitLinear = new LimitLinear(x, y); MarkAsModified(); }; limitLinearGUI.OnConfirmed += ConfirmModify; } Layout.AddElement(twistLimitFoldout); twistLimitLayout = Layout.AddLayoutX(); { twistLimitLayout.AddSpace(10); GUILayoutY twistLimitContentsLayout = twistLimitLayout.AddLayoutY(); limitTwistGUI = new LimitAngularRangeGUI(joint.LimitTwist, twistLimitContentsLayout, Persistent); limitTwistGUI.OnChanged += (x, y) => { joint.LimitTwist = new LimitAngularRange(x, y); MarkAsModified(); }; limitTwistGUI.OnConfirmed += ConfirmModify; } Layout.AddElement(swingLimitFoldout); swingLimitLayout = Layout.AddLayoutX(); { swingLimitLayout.AddSpace(10); GUILayoutY swingLimitContentsLayout = swingLimitLayout.AddLayoutY(); limitSwingGUI = new LimitConeRangeGUI(joint.LimitSwing, swingLimitContentsLayout, Persistent); limitSwingGUI.OnChanged += (x, y) => { joint.LimitSwing = new LimitConeRange(x, y); MarkAsModified(); }; limitSwingGUI.OnConfirmed += ConfirmModify; } Layout.AddElement(driveFoldout); driveLayout = Layout.AddLayoutX(); { driveLayout.AddSpace(10); GUILayoutY driveContentsLayout = driveLayout.AddLayoutY(); for (int i = 0; i < (int) D6JointDriveType.Count; i++) { D6JointDriveType type = (D6JointDriveType)i; drivesGUI[i] = new D6JointDriveGUI(joint.GetDrive(type), driveContentsLayout); drivesGUI[i].OnChanged += x => { joint.SetDrive(type, new D6JointDrive(x)); MarkAsModified(); }; drivesGUI[i].OnConfirmed += ConfirmModify; } driveContentsLayout.AddElement(drivePositionField); driveContentsLayout.AddElement(driveRotationField); driveContentsLayout.AddElement(driveLinVelocityField); driveContentsLayout.AddElement(driveAngVelocityField); } linearLimitLayout.Active = Persistent.GetBool("linearLimit_Expanded"); twistLimitLayout.Active = Persistent.GetBool("twistLimit_Expanded"); swingLimitLayout.Active = Persistent.GetBool("swingLimit_Expanded"); driveLayout.Active = Persistent.GetBool("drive_Expanded"); base.BuildGUI(joint, true); }
/// <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.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 ? EditorStyles.InspectorContentBgAlternate : EditorStyles.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()); 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(); } } }
public GUIAnimMissingEntry(GUIAnimFieldLayouts layouts, string path) : base(layouts, path, false, 15) { missingLabel = new GUILabel("Missing!", GUIOption.FixedHeight(GetEntryHeight())); underlayLayout = layouts.underlay.AddLayoutX(); underlayLayout.AddFlexibleSpace(); underlayLayout.AddElement(missingLabel); underlayLayout.AddSpace(15); overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight())); layouts.overlay.AddElement(overlaySpacing); }
/// <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")); guiCreateBtn = new GUIButton(createIcon, GUIOption.FixedWidth(30)); guiCreateBtn.OnClick += OnCreateButtonClicked; guiInternalTitleLayout.AddElement(guiCreateBtn); } }; 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); if (!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) { 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.Flags.HasFlag(SerializableFieldAttributes.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(); guiCreateBtn = null; BuildFilledGUI(); state = State.Filled; } } else if (state == State.Filled) { foreach (var child in children) { child.Destroy(); } children.Clear(); guiInternalTitleLayout.Destroy(); guiCreateBtn = null; if (guiChildLayout != null) { guiChildLayout.Destroy(); guiChildLayout = null; } if (propertyValue == null) { BuildEmptyGUI(); state = State.Empty; } else { BuildFilledGUI(); } } }
/// <summary> /// Creates GUI elements for fields specific to the distance joint. /// </summary> protected void BuildGUI(DistanceJoint joint) { enableMinLimitField.OnChanged += x => { joint.EnableMinDistanceLimit = x; MarkAsModified(); ConfirmModify(); minLimitField.Active = x; }; minLimitField.OnChanged += x => { joint.MinDistance = x; MarkAsModified(); }; minLimitField.OnFocusLost += ConfirmModify; minLimitField.OnConfirmed += ConfirmModify; enableMaxLimitField.OnChanged += x => { joint.EnableMaxDistanceLimit = x; MarkAsModified(); ConfirmModify(); maxLimitField.Active = x; }; maxLimitField.OnChanged += x => { joint.MaxDistance = x; MarkAsModified(); }; maxLimitField.OnFocusLost += ConfirmModify; maxLimitField.OnConfirmed += ConfirmModify; toleranceField.OnChanged += x => { joint.Tolerance = x; MarkAsModified(); }; toleranceField.OnFocusLost += ConfirmModify; toleranceField.OnConfirmed += ConfirmModify; enableSpringField.OnChanged += x => { joint.EnableSpring = x; MarkAsModified(); ConfirmModify(); springLayout.Active = x; }; Layout.AddElement(enableMinLimitField); GUILayoutX minLimitLayout = Layout.AddLayoutX(); { minLimitLayout.AddSpace(10); minLimitLayout.AddElement(minLimitField); } Layout.AddElement(enableMaxLimitField); GUILayoutX maxLimitLayout = Layout.AddLayoutX(); { maxLimitLayout.AddSpace(10); maxLimitLayout.AddElement(maxLimitField); } Layout.AddElement(toleranceField); Layout.AddElement(enableSpringField); springLayout = Layout.AddLayoutX(); { springLayout.AddSpace(10); springGUI = new SpringGUI(joint.Spring, springLayout); springGUI.OnChanged += x => { joint.Spring = x; MarkAsModified(); }; springGUI.OnConfirmed += ConfirmModify; } minLimitField.Active = joint.EnableMinDistanceLimit; maxLimitField.Active = joint.EnableMaxDistanceLimit; springLayout.Active = joint.EnableSpring; base.BuildGUI(joint, true); }
/// <summary> /// Rebuilds the GUI list 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); GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout); guiFoldout.Value = isExpanded; guiFoldout.OnToggled += ToggleFoldout; guiSizeField = new GUIIntField("", GUIOption.FixedWidth(50)); guiSizeField.SetRange(0, int.MaxValue); GUIContent resizeIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Resize), new LocEdString("Resize")); GUIButton guiResizeBtn = new GUIButton(resizeIcon, GUIOption.FixedWidth(30)); guiResizeBtn.OnClick += OnResizeButtonClicked; GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear), new LocEdString("Clear")); GUIButton guiClearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(30)); guiClearBtn.OnClick += OnClearButtonClicked; guiInternalTitleLayout.AddElement(guiFoldout); guiInternalTitleLayout.AddElement(guiSizeField); guiInternalTitleLayout.AddElement(guiResizeBtn); guiInternalTitleLayout.AddElement(guiClearBtn); guiSizeField.Value = GetNumRows(); guiChildLayout = guiLayout.AddLayoutX(); guiChildLayout.AddSpace(IndentAmount); guiChildLayout.Active = isExpanded; 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 ? EditorStyles.InspectorContentBgAlternate : EditorStyles.InspectorContentBg; GUIPanel backgroundPanel = guiContentPanel.AddPanel(backgroundDepth); GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle); backgroundPanel.AddElement(inspectorContentBg); }; 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> /// Refreshes the contents of the content area. Must be called at least once after construction. /// </summary> /// <param name="viewType">Determines how to display the resource tiles.</param> /// <param name="entriesToDisplay">Project library entries to display.</param> /// <param name="bounds">Bounds within which to lay out the content entries.</param> public void Refresh(ProjectViewType viewType, LibraryEntry[] entriesToDisplay, Rect2I bounds) { if (mainPanel != null) { mainPanel.Destroy(); } entries.Clear(); entryLookup.Clear(); mainPanel = parent.Layout.AddPanel(); GUIPanel contentPanel = mainPanel.AddPanel(1); overlay = mainPanel.AddPanel(0); underlay = mainPanel.AddPanel(2); deepUnderlay = mainPanel.AddPanel(3); renameOverlay = mainPanel.AddPanel(-1); main = contentPanel.AddLayoutY(); List <ResourceToDisplay> resourcesToDisplay = new List <ResourceToDisplay>(); foreach (var entry in entriesToDisplay) { if (entry.Type == LibraryEntryType.Directory) { resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.Single)); } else { FileEntry fileEntry = (FileEntry)entry; ResourceMeta[] metas = fileEntry.ResourceMetas; if (metas.Length > 0) { if (metas.Length == 1) { resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.Single)); } else { resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.MultiFirst)); for (int i = 1; i < metas.Length - 1; i++) { string path = Path.Combine(entry.Path, metas[i].SubresourceName); resourcesToDisplay.Add(new ResourceToDisplay(path, LibraryGUIEntryType.MultiElement)); } string lastPath = Path.Combine(entry.Path, metas[metas.Length - 1].SubresourceName); resourcesToDisplay.Add(new ResourceToDisplay(lastPath, LibraryGUIEntryType.MultiLast)); } } } } if (viewType == ProjectViewType.List16) { tileSize = 16; gridLayout = false; elementsPerRow = 1; horzElementSpacing = 0; int elemWidth = bounds.width; int elemHeight = tileSize; main.AddSpace(TOP_MARGIN); for (int i = 0; i < resourcesToDisplay.Count; i++) { ResourceToDisplay entry = resourcesToDisplay[i]; LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, main, entry.path, i, elemWidth, elemHeight, entry.type); entries.Add(guiEntry); entryLookup[guiEntry.path] = guiEntry; if (i != resourcesToDisplay.Count - 1) { main.AddSpace(LIST_ENTRY_SPACING); } } main.AddFlexibleSpace(); } else { int elemWidth = 0; int elemHeight = 0; int vertElemSpacing = 0; switch (viewType) { case ProjectViewType.Grid64: tileSize = 64; elemWidth = tileSize; elemHeight = tileSize + 36; horzElementSpacing = 10; vertElemSpacing = 12; break; case ProjectViewType.Grid48: tileSize = 48; elemWidth = tileSize; elemHeight = tileSize + 36; horzElementSpacing = 8; vertElemSpacing = 10; break; case ProjectViewType.Grid32: tileSize = 32; elemWidth = tileSize + 16; elemHeight = tileSize + 48; horzElementSpacing = 6; vertElemSpacing = 10; break; } gridLayout = true; int availableWidth = bounds.width; elementsPerRow = MathEx.FloorToInt((availableWidth - horzElementSpacing) / (float)(elemWidth + horzElementSpacing)); elementsPerRow = Math.Max(elementsPerRow, 1); int numRows = MathEx.CeilToInt(resourcesToDisplay.Count / (float)elementsPerRow); int neededHeight = numRows * elemHeight + TOP_MARGIN; if (numRows > 0) { neededHeight += (numRows - 1) * vertElemSpacing; } bool requiresScrollbar = neededHeight > bounds.height; if (requiresScrollbar) { availableWidth -= parent.ScrollBarWidth; elementsPerRow = MathEx.FloorToInt((availableWidth - horzElementSpacing) / (float)(elemWidth + horzElementSpacing)); elementsPerRow = Math.Max(elementsPerRow, 1); } int extraRowSpace = availableWidth - (elementsPerRow * (elemWidth + horzElementSpacing) + horzElementSpacing); main.AddSpace(TOP_MARGIN); GUILayoutX rowLayout = main.AddLayoutX(); rowLayout.AddSpace(horzElementSpacing); int elemsInRow = 0; for (int i = 0; i < resourcesToDisplay.Count; i++) { if (elemsInRow == elementsPerRow && elemsInRow > 0) { main.AddSpace(vertElemSpacing); rowLayout.AddSpace(extraRowSpace); rowLayout = main.AddLayoutX(); rowLayout.AddSpace(horzElementSpacing); elemsInRow = 0; } ResourceToDisplay entry = resourcesToDisplay[i]; LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, rowLayout, entry.path, i, elemWidth, elemHeight, entry.type); entries.Add(guiEntry); entryLookup[guiEntry.path] = guiEntry; rowLayout.AddSpace(horzElementSpacing); elemsInRow++; } int extraElements = elementsPerRow - elemsInRow; rowLayout.AddSpace((elemWidth + horzElementSpacing) * extraElements + extraRowSpace); main.AddFlexibleSpace(); } for (int i = 0; i < entries.Count; i++) { LibraryGUIEntry guiEntry = entries[i]; guiEntry.Initialize(); } }
/// <summary> /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts. /// </summary> /// <param name="layouts">Layouts to append the GUI elements to.</param> /// <param name="path">Path of the curve field.</param> /// <param name="color">Color of the path field curve, to display next to the element name.</param> /// <param name="child">Determines if the element is a root path, or a child (sub) element.</param> public GUIAnimSimpleEntry(GUIAnimFieldLayouts layouts, string path, Color color, bool child = false) : base(layouts, path, child, child ? 45 : 30) { valueDisplay = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight())); underlayLayout = layouts.underlay.AddLayoutX(); underlayLayout.AddSpace(child ? 30 : 15); GUITexture colorSquare = new GUITexture(Builtin.WhiteTexture, GUIOption.FixedWidth(10), GUIOption.FixedHeight(10)); colorSquare.SetTint(color); underlayLayout.AddElement(colorSquare); underlayLayout.AddFlexibleSpace(); underlayLayout.AddElement(valueDisplay); underlayLayout.AddSpace(10); overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight())); layouts.overlay.AddElement(overlaySpacing); }
/// <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); }
/// <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> /// 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 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> /// 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, LimitCommonData limitData, GUILayout layout, SerializableProperties properties) { this.limitData = limitData; this.properties = properties; this.prefix = prefix; 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.OnToggled += x => { properties.SetBool(prefix + "_softLimit_Expanded", x); ToggleLimitFields(); }; restitutionField.OnChanged += x => { this.limitData.restitution = x; MarkAsModified(); }; restitutionField.OnFocusLost += ConfirmModify; 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; } } }