/// <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); }
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> /// 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) { activeResource = ProjectLibrary.Load <Resource>(resourcePath); if (activeResource == null) { return; } 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 = activeResource.GetType().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(activeResource.UUID); inspectorResource.inspector = InspectorUtility.GetInspector(activeResource.GetType()); inspectorResource.inspector.Initialize(inspectorResource.panel, activeResource, persistentProperties); inspectorLayout.AddFlexibleSpace(); }
/// <summary> /// Triggered when the user selects a new resource or a scene object, or deselects everything. /// </summary> /// <param name="objects">A set of new scene objects that were selected.</param> /// <param name="paths">A set of absolute resource paths that were selected.</param> private void OnSelectionChanged(SceneObject[] objects, string[] paths) { if (currentType == InspectorType.SceneObject && modifyState == InspectableState.NotModified) { UndoRedo.Global.PopCommand(undoCommandIdx); } Clear(); modifyState = InspectableState.NotModified; if (objects.Length == 0 && paths.Length == 0) { currentType = InspectorType.None; inspectorScrollArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow); GUI.AddElement(inspectorScrollArea); inspectorLayout = inspectorScrollArea.Layout; inspectorLayout.AddFlexibleSpace(); GUILayoutX layoutMsg = inspectorLayout.AddLayoutX(); layoutMsg.AddFlexibleSpace(); layoutMsg.AddElement(new GUILabel(new LocEdString("No object selected"))); layoutMsg.AddFlexibleSpace(); inspectorLayout.AddFlexibleSpace(); } else if ((objects.Length + paths.Length) > 1) { currentType = InspectorType.None; inspectorScrollArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow); GUI.AddElement(inspectorScrollArea); inspectorLayout = inspectorScrollArea.Layout; inspectorLayout.AddFlexibleSpace(); GUILayoutX layoutMsg = inspectorLayout.AddLayoutX(); layoutMsg.AddFlexibleSpace(); layoutMsg.AddElement(new GUILabel(new LocEdString("Multiple objects selected"))); layoutMsg.AddFlexibleSpace(); inspectorLayout.AddFlexibleSpace(); } else if (objects.Length == 1) { if (objects[0] != null) { UndoRedo.RecordSO(objects[0]); undoCommandIdx = UndoRedo.Global.TopCommandId; SetObjectToInspect(objects[0]); } } else if (paths.Length == 1) { SetObjectToInspect(paths[0]); } }
/// <summary> /// Destroys all row GUI elements. /// </summary> public void Destroy() { if (rowLayout != null) { rowLayout.Destroy(); rowLayout = null; } contentLayout = null; titleLayout = null; localTitleLayout = false; }
/// <inheritdoc/> protected internal override void Initialize(int index) { guiLayout = layout.AddLayoutY(index); if (!isInline) { guiTitleLayout = guiLayout.AddLayoutX(); } propertyValue = property.GetValue <object>(); BuildGUI(index); }
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); }
/// <inheritdoc/> protected override GUILayoutX CreateGUI(GUILayoutY layout) { GUILayoutX titleLayout = layout.AddLayoutX(); sizeField = new GUIIntField(new LocEdString(SeqIndex + ". ")); titleLayout.AddElement(sizeField); sizeField.OnChanged += x => { SetValue(x); MarkAsModified(); }; sizeField.OnFocusLost += ConfirmModify; sizeField.OnConfirmed += ConfirmModify; return(titleLayout); }
/// <summary> /// Initializes the row and creates row GUI elements. /// </summary> /// <param name="parent">Parent array GUI object that the entry is contained in.</param> /// <param name="parentLayout">Parent layout that row GUI elements will be added to.</param> /// <param name="rowIdx">Sequential index of the row.</param> /// <param name="depth">Determines the depth at which the element is rendered.</param> internal void Initialize(GUIDictionaryFieldBase parent, GUILayout parentLayout, int rowIdx, int depth) { this.parent = parent; this.rowIdx = rowIdx; this.depth = depth; rowLayout = parentLayout.AddLayoutY(); keyRowLayout = rowLayout.AddLayoutX(); keyLayout = keyRowLayout.AddLayoutY(); valueLayout = rowLayout.AddLayoutY(); BuildGUI(); }
/// <summary> /// (Re)creates all row GUI elements. /// </summary> internal protected void BuildGUI() { contentLayout.Clear(); GUILayoutX externalTitleLayout = CreateGUI(contentLayout); if (localTitleLayout || (titleLayout != null && titleLayout == externalTitleLayout)) { return; } if (externalTitleLayout != null) { localTitleLayout = false; titleLayout = externalTitleLayout; } else { GUILayoutY buttonCenter = rowLayout.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 moveUp = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.MoveUp), new LocEdString("Move up")); GUIContent moveDown = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.MoveDown), new LocEdString("Move down")); GUIButton cloneBtn = new GUIButton(cloneIcon, GUIOption.FixedWidth(30)); GUIButton deleteBtn = new GUIButton(deleteIcon, GUIOption.FixedWidth(30)); GUIButton moveUpBtn = new GUIButton(moveUp, GUIOption.FixedWidth(30)); GUIButton moveDownBtn = new GUIButton(moveDown, GUIOption.FixedWidth(30)); cloneBtn.OnClick += () => parent.OnCloneButtonClicked(seqIndex); deleteBtn.OnClick += () => parent.OnDeleteButtonClicked(seqIndex); moveUpBtn.OnClick += () => parent.OnMoveUpButtonClicked(seqIndex); moveDownBtn.OnClick += () => parent.OnMoveDownButtonClicked(seqIndex); titleLayout.AddElement(cloneBtn); titleLayout.AddElement(deleteBtn); titleLayout.AddElement(moveUpBtn); titleLayout.AddElement(moveDownBtn); }
/// <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; }
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 a new scene axes GUI. /// </summary> /// <param name="window">Window in which the GUI is located in.</param> /// <param name="panel">Panel onto which to place the GUI element.</param> /// <param name="width">Width of the GUI element.</param> /// <param name="height">Height of the GUI element.</param> /// <param name="projType">Projection type to display on the GUI.</param> public SceneAxesGUI(SceneWindow window, GUIPanel panel, int width, int height, ProjectionType projType) { renderTexture = new RenderTexture(PixelFormat.RGBA8, width, height); renderTexture.Priority = 1; SceneObject cameraSO = new SceneObject("SceneAxesCamera", true); camera = cameraSO.AddComponent <Camera>(); camera.Viewport.Target = renderTexture; camera.Viewport.Area = new Rect2(0.0f, 0.0f, 1.0f, 1.0f); cameraSO.Position = new Vector3(0, 0, 5); cameraSO.LookAt(new Vector3(0, 0, 0)); camera.Priority = 2; camera.NearClipPlane = 0.05f; camera.FarClipPlane = 1000.0f; camera.Viewport.ClearColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); camera.ProjectionType = ProjectionType.Orthographic; camera.Layers = SceneAxesHandle.LAYER; camera.AspectRatio = 1.0f; camera.OrthoHeight = 2.0f; camera.RenderSettings.EnableHDR = false; camera.RenderSettings.EnableSkybox = false; camera.Flags |= CameraFlag.OnDemand; renderTextureGUI = new GUIRenderTexture(renderTexture, true); GUILayoutY layout = panel.AddLayoutY(); GUILayoutX textureLayout = layout.AddLayoutX(); textureLayout.AddElement(renderTextureGUI); textureLayout.AddFlexibleSpace(); Rect2I bounds = new Rect2I(0, 0, width, height); sceneHandles = new SceneHandles(window, camera); renderTextureGUI.Bounds = bounds; labelGUI = new GUILabel(projType.ToString(), EditorStyles.LabelCentered); layout.AddElement(labelGUI); layout.AddFlexibleSpace(); this.panel = panel; this.bounds = bounds; NotifyNeedsRedraw(); }
/// <inheritdoc/> protected override GUILayoutX CreateGUI(GUILayoutY layout) { GUILayoutX titleLayout = layout.AddLayoutX(); materialField = new GUIResourceField(typeof(Material), new LocEdString(SeqIndex + ". "), 20); titleLayout.AddElement(materialField); materialField.OnChanged += x => { SetValue(x.As <Material>()); MarkAsModified(); ConfirmModify(); }; return(titleLayout); }
/// <summary> /// Destroys all row GUI elements. /// </summary> public void Destroy() { if (rowLayout != null) { rowLayout.Destroy(); rowLayout = null; } keyRowLayout = null; keyLayout = null; valueLayout = null; titleLayout = null; cloneBtn = null; deleteBtn = null; editBtn = null; localTitleLayout = false; }
/// <summary> /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before /// use. /// </summary> /// <param name="parent">Animation window that this drop down window is a part of.</param> internal void Initialize(AnimationWindow parent) { GUIIntField fpsField = new GUIIntField(new LocEdString("FPS"), 40); fpsField.Value = parent.FPS; fpsField.OnChanged += x => { parent.FPS = x; }; GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX contentLayout = vertLayout.AddLayoutX(); contentLayout.AddFlexibleSpace(); contentLayout.AddElement(fpsField); contentLayout.AddFlexibleSpace(); vertLayout.AddFlexibleSpace(); }
/// <inheritoc/> protected internal override void Initialize(int layoutIndex) { GUILayoutX boundsLayout = new GUILayoutX(); centerField = new GUIVector3Field(new LocEdString("Center"), 50); sizeField = new GUIVector3Field(new LocEdString("Size"), 50); layout.AddElement(layoutIndex, boundsLayout); boundsLayout.AddElement(new GUILabel(new LocEdString(title), GUIOption.FixedWidth(100))); GUILayoutY boundsContent = boundsLayout.AddLayoutY(); boundsContent.AddElement(centerField); boundsContent.AddElement(sizeField); centerField.OnValueChanged += x => { AABox bounds = property.GetValue <AABox>(); Vector3 min = x - bounds.Size * 0.5f; Vector3 max = x + bounds.Size * 0.5f; RecordStateForUndoIfNeeded(); property.SetValue(new AABox(min, max)); state |= InspectableState.ModifyInProgress; }; centerField.OnConfirm += x => OnFieldValueConfirm(); centerField.OnFocusLost += OnFieldValueConfirm; centerField.OnFocusGained += RecordStateForUndoRequested; sizeField.OnValueChanged += x => { AABox bounds = property.GetValue <AABox>(); Vector3 min = bounds.Center - x * 0.5f; Vector3 max = bounds.Center + x * 0.5f; RecordStateForUndoIfNeeded(); property.SetValue(new AABox(min, max)); state |= InspectableState.ModifyInProgress; }; sizeField.OnConfirm += x => OnFieldValueConfirm(); sizeField.OnFocusLost += OnFieldValueConfirm; sizeField.OnFocusGained += RecordStateForUndoRequested; }
/// <summary> /// Creates a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of 4x4 matrix type.</param> /// <param name="material">Material the parameter is a part of.</param> /// <param name="layout">Layout to append the GUI elements to.</param> internal MaterialParamMat4GUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.name); GUILabel guiTitle = new GUILabel(title, GUIOption.FixedWidth(100)); mainLayout = layout.AddLayoutY(); GUILayoutX titleLayout = mainLayout.AddLayoutX(); titleLayout.AddElement(guiTitle); titleLayout.AddFlexibleSpace(); GUILayoutY contentLayout = mainLayout.AddLayoutY(); GUILayoutX[] rows = new GUILayoutX[MAT_SIZE]; for (int i = 0; i < rows.Length; i++) { rows[i] = contentLayout.AddLayoutX(); } for (int row = 0; row < MAT_SIZE; row++) { for (int col = 0; col < MAT_SIZE; col++) { int index = row * MAT_SIZE + col; guiMatFields[index] = new GUIFloatField(row + "," + col, 20, "", GUIOption.FixedWidth(80)); GUIFloatField field = guiMatFields[index]; rows[row].AddElement(field); rows[row].AddSpace(5); int hoistedRow = row; int hoistedCol = col; field.OnChanged += (x) => { Matrix4 value = material.GetMatrix4(shaderParam.name); value[hoistedRow, hoistedCol] = x; material.SetMatrix4(shaderParam.name, value); EditorApplication.SetDirty(material); }; } } }
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; }
/// <summary> /// Destroys the GUI elements. /// </summary> public void Destroy() { if (guiTitleLayout != null) { guiTitleLayout.Destroy(); guiTitleLayout = null; } if (guiChildLayout != null) { guiChildLayout.Destroy(); guiChildLayout = null; } for (int i = 0; i < rows.Count; i++) { rows[i].Destroy(); } rows.Clear(); }
/// <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; }
/// <inheritdoc/> protected override GUILayoutX CreateGUI(GUILayoutY layout) { GUILayoutX titleLayout = layout.AddLayoutX(); rangeStartField = new GUIIntField(new LocEdString(SeqIndex + ". Start")); rangeEndField = new GUIIntField(new LocEdString("End")); titleLayout.AddElement(rangeStartField); titleLayout.AddElement(rangeEndField); rangeStartField.OnChanged += x => { CharRange range = GetValue <CharRange>(); range.start = x; SetValue(range); MarkAsModified(); }; rangeEndField.OnChanged += x => { CharRange range = GetValue <CharRange>(); range.end = x; SetValue(range); MarkAsModified(); }; rangeStartField.OnFocusLost += ConfirmModify; rangeStartField.OnConfirmed += ConfirmModify; rangeEndField.OnFocusLost += ConfirmModify; rangeEndField.OnConfirmed += ConfirmModify; return(titleLayout); }
/// <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); }
/// <inheritdoc/> protected internal override void Initialize(int index) { guiLayout = layout.AddLayoutY(index); guiTitleLayout = guiLayout.AddLayoutX(); propertyValue = property.GetValue<object>(); BuildGUI(index); }
/// <summary> /// Adds a new horizontal layout as a child of this layout. Layout is inserted /// before the element at the specified index. /// </summary> /// <param name="idx">Index to insert the layout at. This must be in range [0, GetNumChildren()).</param> /// <param name="options">Options that allow you to control how is the layout positioned and sized.</param> /// <returns>Newly created horizontal layout.</returns> public GUILayoutX InsertLayoutX(int idx, params GUIOption[] options) { GUILayoutX layout = new GUILayoutX(options); InsertElement(idx, layout); return layout; }
/// <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> /// 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(); } } }
/// <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> /// 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 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> /// 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> /// 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(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow); 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.mainPanel = inspectorLayout.AddPanel(); inspectorLayout.AddFlexibleSpace(); inspectorResource.previewPanel = inspectorLayout.AddPanel(); var persistentProperties = persistentData.GetProperties(meta.UUID.ToString()); inspectorResource.inspector = InspectorUtility.GetInspector(resourceType); inspectorResource.inspector.Initialize(inspectorResource.mainPanel, inspectorResource.previewPanel, activeResourcePath, persistentProperties); }
/// <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); }
private void OnInitialize() { ProjectLibrary.OnEntryAdded += OnEntryChanged; ProjectLibrary.OnEntryImported += OnEntryChanged; ProjectLibrary.OnEntryRemoved += OnEntryChanged; GUILayoutY contentLayout = GUI.AddLayoutY(); searchBarLayout = contentLayout.AddLayoutX(); searchField = new GUITextField(); searchField.OnChanged += OnSearchChanged; searchField.OnFocusGained += StopRename; GUIContent clearIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Clear), new LocEdString("Clear")); GUIButton clearSearchBtn = new GUIButton(clearIcon); clearSearchBtn.OnClick += OnClearClicked; clearSearchBtn.SetWidth(40); GUIContent optionsIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Options), new LocEdString("Options")); optionsButton = new GUIButton(optionsIcon); optionsButton.OnClick += OnOptionsClicked; optionsButton.SetWidth(40); searchBarLayout.AddElement(searchField); searchBarLayout.AddElement(clearSearchBtn); searchBarLayout.AddElement(optionsButton); folderBarLayout = contentLayout.AddLayoutX(); GUIContent homeIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Home), new LocEdString("Home")); GUIButton homeButton = new GUIButton(homeIcon, GUIOption.FixedWidth(FOLDER_BUTTON_WIDTH)); homeButton.OnClick += OnHomeClicked; GUIContent upIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Up), new LocEdString("Up")); GUIButton upButton = new GUIButton(upIcon, GUIOption.FixedWidth(FOLDER_BUTTON_WIDTH)); upButton.OnClick += OnUpClicked; folderBarLayout.AddElement(homeButton); folderBarLayout.AddElement(upButton); folderBarLayout.AddSpace(10); contentScrollArea = new GUIScrollArea(GUIOption.FlexibleWidth(), GUIOption.FlexibleHeight()); contentLayout.AddElement(contentScrollArea); contentLayout.AddFlexibleSpace(); entryContextMenu = LibraryMenu.CreateContextMenu(this); content = new LibraryGUIContent(this, contentScrollArea); Refresh(); dropTarget = new LibraryDropTarget(this); dropTarget.Bounds = GetScrollAreaBounds(); dropTarget.OnStart += OnDragStart; dropTarget.OnDrag += OnDragMove; dropTarget.OnLeave += OnDragLeave; dropTarget.OnDropResource += OnResourceDragDropped; dropTarget.OnDropSceneObject += OnSceneObjectDragDropped; dropTarget.OnEnd += OnDragEnd; Selection.OnSelectionChanged += OnSelectionChanged; Selection.OnResourcePing += OnPing; }
/// <summary> /// Adds a new horizontal layout as a child of this layout. Layout is inserted after all existing elements. /// </summary> /// <param name="options">Options that allow you to control how is the layout positioned and sized.</param> /// <returns>Newly created horizontal layout.</returns> public GUILayoutX AddLayoutX(params GUIOption[] options) { GUILayoutX layout = new GUILayoutX(options); AddElement(layout); return layout; }
/// <summary> /// Creates a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of 4x4 matrix type.</param> /// <param name="material">Material the parameter is a part of.</param> /// <param name="layout">Layout to append the GUI elements to.</param> internal MaterialParamMat4GUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.Name); GUILabel guiTitle = new GUILabel(title, GUIOption.FixedWidth(100)); mainLayout = layout.AddLayoutY(); GUILayoutX titleLayout = mainLayout.AddLayoutX(); titleLayout.AddElement(guiTitle); titleLayout.AddFlexibleSpace(); GUILayoutY contentLayout = mainLayout.AddLayoutY(); GUILayoutX[] rows = new GUILayoutX[MAT_SIZE]; for (int i = 0; i < rows.Length; i++) rows[i] = contentLayout.AddLayoutX(); for (int row = 0; row < MAT_SIZE; row++) { for (int col = 0; col < MAT_SIZE; col++) { int index = row * MAT_SIZE + col; guiMatFields[index] = new GUIFloatField(row + "," + col, 20, "", GUIOption.FixedWidth(80)); GUIFloatField field = guiMatFields[index]; rows[row].AddElement(field); rows[row].AddSpace(5); int hoistedRow = row; int hoistedCol = col; field.OnChanged += (x) => { Matrix4 value = material.GetMatrix4(shaderParam.Name); value[hoistedRow, hoistedCol] = x; material.SetMatrix4(shaderParam.Name, value); EditorApplication.SetDirty(material); }; } } }
/// <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; } } }