/// <summary> /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before /// use. /// </summary> /// <param name="keyFrame">Keyframe whose properties to edit.</param> /// <param name="updateCallback">Callback triggered when event values change.</param> internal void Initialize(KeyFrame keyFrame, Action <KeyFrame> updateCallback) { GUIFloatField timeField = new GUIFloatField(new LocEdString("Time"), 40, ""); timeField.Value = keyFrame.time; timeField.OnChanged += x => { keyFrame.time = x; updateCallback(keyFrame); }; GUIFloatField valueField = new GUIFloatField(new LocEdString("Value"), 40, ""); valueField.Value = keyFrame.value; valueField.OnChanged += x => { keyFrame.value = x; updateCallback(keyFrame); }; GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX horzLayout = vertLayout.AddLayoutX(); horzLayout.AddFlexibleSpace(); GUILayout contentLayout = horzLayout.AddLayoutY(); GUILayout timeLayout = contentLayout.AddLayoutX(); timeLayout.AddSpace(5); timeLayout.AddElement(timeField); timeLayout.AddFlexibleSpace(); GUILayout componentLayout = contentLayout.AddLayoutX(); componentLayout.AddSpace(5); componentLayout.AddElement(valueField); componentLayout.AddFlexibleSpace(); horzLayout.AddFlexibleSpace(); vertLayout.AddFlexibleSpace(); }
private void OnInitialize() { treeScrollArea = new GUIScrollArea(); GUI.AddElement(treeScrollArea); treeView = new GUISceneTreeView(GUIOption.FlexibleHeight(20), GUIOption.FlexibleWidth(20)); treeScrollArea.Layout.AddElement(treeView); // Loading progress loadLabel = new GUILabel(new LocEdString("Loading scene...")); loadProgressBar = new GUIProgressBar(); progressLayout = GUI.AddLayoutY(); progressLayout.AddFlexibleSpace(); GUILayout loadLabelLayout = progressLayout.AddLayoutX(); loadLabelLayout.AddFlexibleSpace(); loadLabelLayout.AddElement(loadLabel); loadLabelLayout.AddFlexibleSpace(); GUILayout progressBarLayout = progressLayout.AddLayoutX(); progressBarLayout.AddFlexibleSpace(); progressBarLayout.AddElement(loadProgressBar); progressBarLayout.AddFlexibleSpace(); progressLayout.AddFlexibleSpace(); progressLayout.Active = false; EditorVirtualInput.OnButtonUp += OnButtonUp; }
/// <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; } } }
/// <inheritdoc/> protected internal override void Initialize() { LoadResource(); PlainText plainText = InspectedObject as PlainText; if (plainText == null) { return; } GUIPanel textPanel = Layout.AddPanel(); GUILayout textLayoutY = textPanel.AddLayoutY(); textLayoutY.AddSpace(5); GUILayout textLayoutX = textLayoutY.AddLayoutX(); textLayoutX.AddSpace(5); textLayoutX.AddElement(textLabel); textLayoutX.AddSpace(5); textLayoutY.AddSpace(5); GUIPanel textBgPanel = textPanel.AddPanel(1); textBgPanel.AddElement(textBg); }
/// <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="seqIndex">Sequential index of the list entry.</param> /// <param name="depth">Determines the depth at which the element is rendered.</param> internal void Initialize(GUIListFieldBase parent, GUILayout parentLayout, int seqIndex, int depth) { this.parent = parent; this.seqIndex = seqIndex; this.depth = depth; rowLayout = parentLayout.AddLayoutX(); contentLayout = rowLayout.AddLayoutY(); BuildGUI(); }
/// <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(); 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(); 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]); } }
private void OnInitialize() { GUILayout vertLayout = GUI.AddLayoutY(); GUILayout editorPanel = vertLayout.AddPanel(GUIOption.FixedHeight(400)); GUILayout buttonLayout = vertLayout.AddLayoutX(GUIOption.FixedHeight(40)); guiOK = new GUIButton(new LocEdString("OK")); guiCancel = new GUIButton(new LocEdString("Cancel")); guiOK.OnClick += OnOK; guiCancel.OnClick += OnCancel; CurveDrawOptions drawOptions = CurveDrawOptions.DrawKeyframes | CurveDrawOptions.DrawMarkers; if (curveB != null) { drawOptions |= CurveDrawOptions.DrawRange; } curveEditor = new GUICurveEditor(editorPanel, 600, 400, false, drawOptions); curveEditor.Redraw(); EdCurveDrawInfo[] drawinfo; if (curveB != null) { drawinfo = new [] { new EdCurveDrawInfo(curveA, Color.BansheeOrange), new EdCurveDrawInfo(curveB, Color.Green), }; } else { drawinfo = new [] { new EdCurveDrawInfo(curveA, Color.BansheeOrange), }; } curveEditor.SetCurves(drawinfo); curveEditor.CenterAndResize(true); buttonLayout.AddFlexibleSpace(); buttonLayout.AddElement(guiOK); buttonLayout.AddSpace(10); buttonLayout.AddElement(guiCancel); buttonLayout.AddFlexibleSpace(); EditorInput.OnPointerPressed += OnPointerPressed; EditorInput.OnPointerDoubleClick += OnPointerDoubleClicked; EditorInput.OnPointerMoved += OnPointerMoved; EditorInput.OnPointerReleased += OnPointerReleased; EditorInput.OnButtonUp += OnButtonUp; }
/// <summary> /// Creates a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of color 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 MaterialParamColorGUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.name); var guiToggle = new GUIToggle(new GUIContent( EditorBuiltin.GetEditorToggleIcon(EditorToggleIcon.AnimateProperty), new LocString("Animate"))); guiColor = new GUIColorField(title); guiColorGradient = new GUIColorGradientField(title); bool isAnimated = material.IsAnimated(shaderParam.name); guiColor.Active = !isAnimated; guiColorGradient.Active = isAnimated; fieldLayout = layout.AddLayoutX(); fieldLayout.AddElement(guiColor); fieldLayout.AddElement(guiColorGradient); fieldLayout.AddSpace(10); fieldLayout.AddElement(guiToggle); guiColor.OnChanged += (x) => { material.SetColor(shaderParam.name, x); EditorApplication.SetDirty(material); }; guiColorGradient.OnChanged += x => { material.SetColorGradient(shaderParam.name, x); EditorApplication.SetDirty(material); }; guiToggle.OnToggled += x => { guiColor.Active = !x; guiColorGradient.Active = x; if (x) { ColorGradient gradient = material.GetColorGradient(shaderParam.name); if (gradient.NumKeys == 0) { material.SetColorGradient(shaderParam.name, new ColorGradient(material.GetColor(shaderParam.name))); } } }; }
/// <summary> /// Creates the reimport GUI elements in the provided layout. /// </summary> /// <param name="path">Path of the resource that can be reimported.</param> /// <param name="parent">Parent GUI layout to which to add the reimport GUI elements.</param> /// <param name="doReimport">User provided callback that triggers when the reimport button is clicked.</param> internal GUIReimportButton(string path, GUILayout parent, Action doReimport) { this.path = path; reimportButton.OnClick += () => doReimport(); GUILayout reimportButtonLayout = parent.AddLayoutX(); reimportButtonLayout.AddFlexibleSpace(); reimportButtonLayout.AddElement(reimportButton); reimportButtonLayout.AddElement(guiSpinner); bool isImporting = ProjectLibrary.GetImportProgress(path) < 1.0f; guiSpinner.Active = isImporting; reimportButton.Active = !isImporting; }
/// <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) { 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) { SetObjectToInspect(objects[0]); } } else if (paths.Length == 1) { SetObjectToInspect(paths[0]); } }
/// <inheritdoc/> protected internal override void Initialize() { LoadResource(); ScriptCode scriptCode = InspectedObject as ScriptCode; if (scriptCode == null) { return; } importOptions = GetImportOptions(); isEditorField.OnChanged += x => { importOptions.EditorScript = x; }; GUIPanel textPanel = Layout.AddPanel(); GUILayout textLayoutY = textPanel.AddLayoutY(); textLayoutY.AddSpace(5); GUILayout textLayoutX = textLayoutY.AddLayoutX(); textLayoutX.AddSpace(5); textLayoutX.AddElement(textLabel); textLayoutX.AddSpace(5); textLayoutY.AddSpace(5); GUIPanel textBgPanel = textPanel.AddPanel(1); textBgPanel.AddElement(textBg); Layout.AddElement(isEditorField); GUIButton reimportButton = new GUIButton(new LocEdString("Reimport")); reimportButton.OnClick += TriggerReimport; GUILayout reimportButtonLayout = Layout.AddLayoutX(); reimportButtonLayout.AddElement(reimportButton); reimportButtonLayout.AddFlexibleSpace(); }
/// <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); }; } } }
/// <inheritdoc/> protected internal override void Initialize() { LoadResource(); ScriptCode scriptCode = InspectedObject as ScriptCode; if (scriptCode == null) { return; } importOptions = GetImportOptions(); isEditorField.OnChanged += x => { importOptions.EditorScript = x; }; GUIPanel textPanel = Layout.AddPanel(); GUILayout textLayoutY = textPanel.AddLayoutY(); textLayoutY.AddSpace(5); GUILayout textLayoutX = textLayoutY.AddLayoutX(); textLayoutX.AddSpace(5); textLayoutX.AddElement(textLabel); textLayoutX.AddSpace(5); textLayoutY.AddSpace(5); GUIPanel textBgPanel = textPanel.AddPanel(1); textBgPanel.AddElement(textBg); Layout.AddElement(isEditorField); Layout.AddSpace(10); reimportButton = new GUIReimportButton(InspectedResourcePath, Layout, () => { ProjectLibrary.Reimport(InspectedResourcePath, importOptions, true); }); UpdateGUIValues(); }
/// <summary> /// Creates a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of floating point 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 MaterialParamFloatGUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.name); var guiToggle = new GUIToggle(new GUIContent( EditorBuiltin.GetEditorToggleIcon(EditorToggleIcon.AnimateProperty), new LocString("Animate"))); guiConstant = new GUIFloatField(title); guiCurves = new GUICurvesField(title); bool isAnimated = material.IsAnimated(shaderParam.name); guiConstant.Active = !isAnimated; guiCurves.Active = isAnimated; fieldLayout = layout.AddLayoutX(); fieldLayout.AddElement(guiConstant); fieldLayout.AddElement(guiCurves); fieldLayout.AddSpace(10); fieldLayout.AddElement(guiToggle); guiConstant.OnChanged += (x) => { material.SetFloat(shaderParam.name, x); EditorApplication.SetDirty(material); }; guiCurves.OnChanged += x => { material.SetFloatCurve(shaderParam.name, x); EditorApplication.SetDirty(material); }; guiToggle.OnToggled += x => { guiConstant.Active = !x; guiCurves.Active = x; }; }
/// <summary> /// Constructs a new resource tile entry. /// </summary> /// <param name="owner">Content area this entry is part of.</param> /// <param name="parent">Parent layout to add this entry's GUI elements to.</param> /// <param name="entry">Project library entry this entry displays data for.</param> /// <param name="index">Sequential index of the entry in the conent area.</param> /// <param name="labelWidth">Width of the GUI labels that display the elements.</param> public LibraryGUIEntry(LibraryGUIContent owner, GUILayout parent, LibraryEntry entry, int index, int labelWidth) { GUILayout entryLayout; if (owner.GridLayout) { entryLayout = parent.AddLayoutY(); } else { entryLayout = parent.AddLayoutX(); } SpriteTexture iconTexture = GetIcon(entry, owner.TileSize); icon = new GUITexture(iconTexture, GUIImageScaleMode.ScaleToFit, true, GUIOption.FixedHeight(owner.TileSize), GUIOption.FixedWidth(owner.TileSize)); label = null; if (owner.GridLayout) { label = new GUILabel(entry.Name, EditorStyles.MultiLineLabelCentered, GUIOption.FixedWidth(labelWidth), GUIOption.FlexibleHeight(0, MAX_LABEL_HEIGHT)); } else { label = new GUILabel(entry.Name); } entryLayout.AddElement(icon); entryLayout.AddElement(label); this.owner = owner; this.index = index; this.path = entry.Path; this.bounds = new Rect2I(); this.underlay = null; }
/// <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); }
private void OnInitialize() { guiOK = new GUIButton(new LocEdString("OK")); guiCancel = new GUIButton(new LocEdString("Cancel")); guiOK.OnClick += OnOK; guiCancel.OnClick += OnCancel; GUILayout mainVertLayout = GUI.AddLayoutY(); mainVertLayout.AddSpace(10); GUILayout editorHorzLayout = mainVertLayout.AddLayoutX(); editorHorzLayout.AddSpace(EDITOR_HORZ_PADDING); GUIPanel gradientEditorPanel = editorHorzLayout.AddPanel(); editorHorzLayout.AddSpace(EDITOR_HORZ_PADDING); mainVertLayout.AddSpace(15); GUILayout buttonHorzLayout = mainVertLayout.AddLayoutX(); buttonHorzLayout.AddFlexibleSpace(); buttonHorzLayout.AddElement(guiOK); buttonHorzLayout.AddSpace(10); buttonHorzLayout.AddElement(guiCancel); buttonHorzLayout.AddFlexibleSpace(); mainVertLayout.AddFlexibleSpace(); editorPanel = gradientEditorPanel.AddPanel(0); GUIPanel editorOverlay = gradientEditorPanel.AddPanel(-1); overlayCanvas = new GUICanvas(); editorOverlay.AddElement(overlayCanvas); GUILayout editorVertLayout = editorPanel.AddLayoutY(); GUILayout guiGradientLayout = editorVertLayout.AddLayoutX(); guiGradientLayout.AddSpace(GradientKeyEditor.RECT_WIDTH / 2); texture = Texture.Create2D(TEX_WIDTH, TEX_HEIGHT); spriteTexture = new SpriteTexture(texture); guiGradientTexture = new GUITexture(spriteTexture, GUITextureScaleMode.StretchToFit); guiGradientTexture.SetHeight(30); UpdateTexture(); guiGradientLayout.AddElement(guiGradientTexture); guiGradientLayout.AddSpace(GradientKeyEditor.RECT_WIDTH / 2); editorVertLayout.AddSpace(10); editor = new GradientKeyEditor(editorVertLayout, gradient.GetKeys(), Width - EDITOR_HORZ_PADDING * 2, 20); editor.OnGradientModified += colorGradient => { gradient = colorGradient; UpdateTexture(); UpdateKeyLines(); }; editorVertLayout.AddFlexibleSpace(); GUITexture containerBg = new GUITexture(null, EditorStylesInternal.ContainerBg); Rect2I containerBounds = editor.GetBounds(GUI); containerBounds.x -= 2; containerBounds.y -= 2; containerBounds.width += 4; containerBounds.height += 6; containerBg.Bounds = containerBounds; GUIPanel editorUnderlay = GUI.AddPanel(1); editorUnderlay.AddElement(containerBg); UpdateKeyLines(); EditorInput.OnPointerPressed += OnPointerPressed; EditorInput.OnPointerDoubleClick += OnPointerDoubleClicked; EditorInput.OnPointerMoved += OnPointerMoved; EditorInput.OnPointerReleased += OnPointerReleased; EditorInput.OnButtonUp += OnButtonUp; }
/// <summary> /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before /// use. /// </summary> /// <param name="animEvent">Event whose properties to edit.</param> /// <param name="componentNames">List of component names that the user can select from.</param> /// <param name="updateCallback">Callback triggered when event values change.</param> internal void Initialize(AnimationEvent animEvent, string[] componentNames, Action updateCallback) { int selectedIndex = -1; string methodName = ""; if (!string.IsNullOrEmpty(animEvent.Name)) { string[] nameEntries = animEvent.Name.Split('/'); if (nameEntries.Length > 1) { string typeName = nameEntries[0]; for (int i = 0; i < componentNames.Length; i++) { if (componentNames[i] == typeName) { selectedIndex = i; break; } } methodName = nameEntries[nameEntries.Length - 1]; } } GUIFloatField timeField = new GUIFloatField(new LocEdString("Time"), 40, ""); timeField.Value = animEvent.Time; timeField.OnChanged += x => { animEvent.Time = x; updateCallback(); }; // TODO UNDOREDO GUIListBoxField componentField = new GUIListBoxField(componentNames, new LocEdString("Component"), 40); if (selectedIndex != -1) { componentField.Index = selectedIndex; } componentField.OnSelectionChanged += x => { string compName = ""; if (x != -1) { compName = componentNames[x] + "/"; } animEvent.Name = compName + x; updateCallback(); };// TODO UNDOREDO GUITextField methodField = new GUITextField(new LocEdString("Method"), 40, false, "", GUIOption.FixedWidth(190)); methodField.Value = methodName; methodField.OnChanged += x => { string compName = ""; if (componentField.Index != -1) { compName = componentNames[componentField.Index] + "/"; } animEvent.Name = compName + x; updateCallback(); }; // TODO UNDOREDO GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX horzLayout = vertLayout.AddLayoutX(); horzLayout.AddFlexibleSpace(); GUILayout contentLayout = horzLayout.AddLayoutY(); GUILayout timeLayout = contentLayout.AddLayoutX(); timeLayout.AddSpace(5); timeLayout.AddElement(timeField); timeLayout.AddFlexibleSpace(); GUILayout componentLayout = contentLayout.AddLayoutX(); componentLayout.AddSpace(5); componentLayout.AddElement(componentField); componentLayout.AddFlexibleSpace(); GUILayout methodLayout = contentLayout.AddLayoutX(); methodLayout.AddSpace(5); methodLayout.AddElement(methodField); methodLayout.AddFlexibleSpace(); horzLayout.AddFlexibleSpace(); vertLayout.AddFlexibleSpace(); }
/// <summary> /// Sets a scene object whose GUI is to be displayed in the inspector. Clears any previous contents of the window. /// </summary> /// <param name="so">Scene object to inspect.</param> private void SetObjectToInspect(SceneObject so) { if (so == null) { return; } currentType = InspectorType.SceneObject; activeSO = so; inspectorScrollArea = new GUIScrollArea(); scrollAreaHighlight = new GUITexture(Builtin.WhiteTexture); scrollAreaHighlight.SetTint(HIGHLIGHT_COLOR); scrollAreaHighlight.Active = false; GUI.AddElement(inspectorScrollArea); GUIPanel inspectorPanel = inspectorScrollArea.Layout.AddPanel(); inspectorLayout = inspectorPanel.AddLayoutY(); highlightPanel = inspectorPanel.AddPanel(-1); highlightPanel.AddElement(scrollAreaHighlight); // SceneObject fields CreateSceneObjectFields(); RefreshSceneObjectFields(true); // Components Component[] allComponents = so.GetComponents(); for (int i = 0; i < allComponents.Length; i++) { inspectorLayout.AddSpace(COMPONENT_SPACING); InspectorComponent data = new InspectorComponent(); data.instanceId = allComponents[i].InstanceId; data.folded = false; data.foldout = new GUIToggle(allComponents[i].GetType().Name, EditorStyles.Foldout); data.foldout.AcceptsKeyFocus = false; SpriteTexture xBtnIcon = EditorBuiltin.GetEditorIcon(EditorIcon.X); data.removeBtn = new GUIButton(new GUIContent(xBtnIcon), GUIOption.FixedWidth(30)); data.title = inspectorLayout.AddLayoutX(); data.title.AddElement(data.foldout); data.title.AddElement(data.removeBtn); data.panel = inspectorLayout.AddPanel(); var persistentProperties = persistentData.GetProperties(allComponents[i].InstanceId); data.inspector = InspectorUtility.GetInspector(allComponents[i].GetType()); data.inspector.Initialize(data.panel, allComponents[i], persistentProperties); bool isExpanded = data.inspector.Persistent.GetBool(data.instanceId + "_Expanded", true); data.foldout.Value = isExpanded; if (!isExpanded) { data.inspector.SetVisible(false); } Type curComponentType = allComponents[i].GetType(); data.foldout.OnToggled += (bool expanded) => OnComponentFoldoutToggled(data, expanded); data.removeBtn.OnClick += () => OnComponentRemoveClicked(curComponentType); inspectorComponents.Add(data); } inspectorLayout.AddFlexibleSpace(); UpdateDropAreas(); }
/// <summary> /// Constructs a new set of GUI elements for inspecting the post process settings object. /// </summary> /// <param name="settings">Initial values to assign to the GUI elements.</param> /// <param name="layout">Layout to append the GUI elements to.</param> /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state. /// </param> public RenderSettingsGUI(RenderSettings settings, GUILayout layout, SerializableProperties properties) { this.settings = settings; this.properties = properties; // Enable HDR enableHDRField.OnChanged += x => { this.settings.EnableHDR = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableHDRField); // Enable lighting enableLightingField.OnChanged += x => { this.settings.EnableLighting = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableLightingField); // Enable indirect lighting enableIndirectLightingField.OnChanged += x => { this.settings.EnableIndirectLighting = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableIndirectLightingField); // Overlay only overlayOnlyField.OnChanged += x => { this.settings.OverlayOnly = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(overlayOnlyField); // Shadows enableShadowsField.OnChanged += x => { this.settings.EnableShadows = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableShadowsField); shadowsFoldout.AcceptsKeyFocus = false; shadowsFoldout.OnToggled += x => { properties.SetBool("shadows_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(shadowsFoldout); shadowsLayout = layout.AddLayoutX(); { shadowsLayout.AddSpace(10); GUILayoutY contentsLayout = shadowsLayout.AddLayoutY(); shadowsGUI = new ShadowSettingsGUI(settings.ShadowSettings, contentsLayout); shadowsGUI.OnChanged += x => { this.settings.ShadowSettings = x; MarkAsModified(); }; shadowsGUI.OnConfirmed += ConfirmModify; } // Auto exposure enableAutoExposureField.OnChanged += x => { this.settings.EnableAutoExposure = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableAutoExposureField); autoExposureFoldout.AcceptsKeyFocus = false; autoExposureFoldout.OnToggled += x => { properties.SetBool("autoExposure_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(autoExposureFoldout); autoExposureLayout = layout.AddLayoutX(); { autoExposureLayout.AddSpace(10); GUILayoutY contentsLayout = autoExposureLayout.AddLayoutY(); autoExposureGUI = new AutoExposureSettingsGUI(settings.AutoExposure, contentsLayout); autoExposureGUI.OnChanged += x => { this.settings.AutoExposure = x; MarkAsModified(); }; autoExposureGUI.OnConfirmed += ConfirmModify; } // Tonemapping enableToneMappingField.OnChanged += x => { this.settings.EnableTonemapping = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableToneMappingField); //// Tonemapping settings toneMappingFoldout.AcceptsKeyFocus = false; toneMappingFoldout.OnToggled += x => { properties.SetBool("toneMapping_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(toneMappingFoldout); toneMappingLayout = layout.AddLayoutX(); { toneMappingLayout.AddSpace(10); GUILayoutY contentsLayout = toneMappingLayout.AddLayoutY(); toneMappingGUI = new TonemappingSettingsGUI(settings.Tonemapping, contentsLayout); toneMappingGUI.OnChanged += x => { this.settings.Tonemapping = x; MarkAsModified(); }; toneMappingGUI.OnConfirmed += ConfirmModify; } //// White balance settings whiteBalanceFoldout.AcceptsKeyFocus = false; whiteBalanceFoldout.OnToggled += x => { properties.SetBool("whiteBalance_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(whiteBalanceFoldout); whiteBalanceLayout = layout.AddLayoutX(); { whiteBalanceLayout.AddSpace(10); GUILayoutY contentsLayout = whiteBalanceLayout.AddLayoutY(); whiteBalanceGUI = new WhiteBalanceSettingsGUI(settings.WhiteBalance, contentsLayout); whiteBalanceGUI.OnChanged += x => { this.settings.WhiteBalance = x; MarkAsModified(); }; whiteBalanceGUI.OnConfirmed += ConfirmModify; } //// Color grading settings colorGradingFoldout.AcceptsKeyFocus = false; colorGradingFoldout.OnToggled += x => { properties.SetBool("colorGrading_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(colorGradingFoldout); colorGradingLayout = layout.AddLayoutX(); { colorGradingLayout.AddSpace(10); GUILayoutY contentsLayout = colorGradingLayout.AddLayoutY(); colorGradingGUI = new ColorGradingSettingsGUI(settings.ColorGrading, contentsLayout); colorGradingGUI.OnChanged += x => { this.settings.ColorGrading = x; MarkAsModified(); }; colorGradingGUI.OnConfirmed += ConfirmModify; } // Gamma gammaField.OnChanged += x => { this.settings.Gamma = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(gammaField); // Exposure scale exposureScaleField.OnChanged += x => { this.settings.ExposureScale = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(exposureScaleField); //// Depth of field settings depthOfFieldFoldout.AcceptsKeyFocus = false; depthOfFieldFoldout.OnToggled += x => { properties.SetBool("depthOfField_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(depthOfFieldFoldout); depthOfFieldLayout = layout.AddLayoutX(); { depthOfFieldLayout.AddSpace(10); GUILayoutY contentsLayout = depthOfFieldLayout.AddLayoutY(); depthOfFieldGUI = new DepthOfFieldSettingsGUI(settings.DepthOfField, contentsLayout); depthOfFieldGUI.OnChanged += x => { this.settings.DepthOfField = x; MarkAsModified(); }; depthOfFieldGUI.OnConfirmed += ConfirmModify; } //// Ambient occlusion settings ambientOcclusionFoldout.AcceptsKeyFocus = false; ambientOcclusionFoldout.OnToggled += x => { properties.SetBool("ambientOcclusion_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(ambientOcclusionFoldout); ambientOcclusionLayout = layout.AddLayoutX(); { ambientOcclusionLayout.AddSpace(10); GUILayoutY contentsLayout = ambientOcclusionLayout.AddLayoutY(); ambientOcclusionGUI = new AmbientOcclusionSettingsGUI(settings.AmbientOcclusion, contentsLayout); ambientOcclusionGUI.OnChanged += x => { this.settings.AmbientOcclusion = x; MarkAsModified(); }; ambientOcclusionGUI.OnConfirmed += ConfirmModify; } //// Screen space reflections settings screenSpaceReflectionsFoldout.AcceptsKeyFocus = false; screenSpaceReflectionsFoldout.OnToggled += x => { properties.SetBool("screenSpaceReflections_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(screenSpaceReflectionsFoldout); screenSpaceReflectionsLayout = layout.AddLayoutX(); { screenSpaceReflectionsLayout.AddSpace(10); GUILayoutY contentsLayout = screenSpaceReflectionsLayout.AddLayoutY(); screenSpaceReflectionsGUI = new ScreenSpaceReflectionsSettingsGUI(settings.ScreenSpaceReflections, contentsLayout); screenSpaceReflectionsGUI.OnChanged += x => { this.settings.ScreenSpaceReflections = x; MarkAsModified(); }; screenSpaceReflectionsGUI.OnConfirmed += ConfirmModify; } // FXAA enableFXAAField.OnChanged += x => { this.settings.EnableFXAA = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableFXAAField); ToggleFoldoutFields(); }
private void OnInitialize() { GUIToggle projectFoldout = new GUIToggle(new LocEdString("Project"), EditorStyles.Foldout); GUIToggle editorFoldout = new GUIToggle(new LocEdString("Editor"), EditorStyles.Foldout); defaultHandleSizeField = new GUIFloatField(new LocEdString("Handle size"), 200); defaultHandleSizeField.OnChanged += (x) => { EditorSettings.DefaultHandleSize = x; }; autoLoadLastProjectField = new GUIToggleField(new LocEdString("Automatically load last project"), 200); autoLoadLastProjectField.OnChanged += (x) => { EditorSettings.AutoLoadLastProject = x; }; CodeEditorType[] availableEditors = CodeEditor.AvailableEditors; Array.Resize(ref availableEditors, availableEditors.Length + 1); availableEditors[availableEditors.Length - 1] = CodeEditorType.None; string[] availableEditorNames = new string[availableEditors.Length]; for (int i = 0; i < availableEditors.Length; i++) { availableEditorNames[i] = Enum.GetName(typeof(CodeEditorType), availableEditors[i]); } codeEditorField = new GUIListBoxField(availableEditorNames, new LocEdString("Code editor"), 200); codeEditorField.OnSelectionChanged += x => { EditorSettings.SetInt(ActiveCodeEditorKey, (int)availableEditors[x]); CodeEditor.ActiveEditor = availableEditors[x]; }; fpsLimitField = new GUIIntField(new LocEdString("FPS limit"), 200); fpsLimitField.OnConfirmed += () => EditorSettings.FPSLimit = fpsLimitField.Value; fpsLimitField.OnFocusLost += () => EditorSettings.FPSLimit = fpsLimitField.Value; mouseSensitivityField = new GUISliderField(0.2f, 2.0f, new LocEdString("Mouse sensitivity")); mouseSensitivityField.OnChanged += (x) => EditorSettings.MouseSensitivity = x; GUILayout mainLayout = GUI.AddLayoutY(); mainLayout.AddElement(projectFoldout); GUILayout projectLayoutOuterY = mainLayout.AddLayoutY(); projectLayoutOuterY.AddSpace(5); GUILayout projectLayoutOuterX = projectLayoutOuterY.AddLayoutX(); projectLayoutOuterX.AddSpace(5); GUILayout projectLayout = projectLayoutOuterX.AddLayoutY(); projectLayoutOuterX.AddSpace(5); projectLayoutOuterY.AddSpace(5); mainLayout.AddElement(editorFoldout); GUILayout editorLayoutOuterY = mainLayout.AddLayoutY(); editorLayoutOuterY.AddSpace(5); GUILayout editorLayoutOuterX = editorLayoutOuterY.AddLayoutX(); editorLayoutOuterX.AddSpace(5); GUILayout editorLayout = editorLayoutOuterX.AddLayoutY(); editorLayoutOuterX.AddSpace(5); editorLayoutOuterY.AddSpace(5); mainLayout.AddFlexibleSpace(); editorLayout.AddElement(defaultHandleSizeField); editorLayout.AddElement(autoLoadLastProjectField); editorLayout.AddElement(codeEditorField); editorLayout.AddElement(fpsLimitField); editorLayout.AddElement(mouseSensitivityField); projectFoldout.Value = true; editorFoldout.Value = true; projectFoldout.OnToggled += (x) => projectLayout.Active = x; editorFoldout.OnToggled += (x) => editorLayout.Active = x; }
/// <summary> /// Creates a new rectangle offset GUI. /// </summary> /// <param name="title">Text to display on the title bar.</param> /// <param name="layout">Layout to append the GUI elements to.</param> public RectOffsetGUI(LocString title, GUILayout layout) { GUILayoutX rectLayout = layout.AddLayoutX(); rectLayout.AddElement(new GUILabel(title, GUIOption.FixedWidth(100))); GUILayoutY rectContentLayout = rectLayout.AddLayoutY(); GUILayoutX rectTopRow = rectContentLayout.AddLayoutX(); GUILayoutX rectBotRow = rectContentLayout.AddLayoutX(); offsetLeftField = new GUIIntField(new LocEdString("Left"), 40); offsetRightField = new GUIIntField(new LocEdString("Right"), 40); offsetTopField = new GUIIntField(new LocEdString("Top"), 40); offsetBottomField = new GUIIntField(new LocEdString("Bottom"), 40); rectTopRow.AddElement(offsetLeftField); rectTopRow.AddElement(offsetRightField); rectBotRow.AddElement(offsetTopField); rectBotRow.AddElement(offsetBottomField); offsetLeftField.OnChanged += x => { offset.left = x; if (OnChanged != null) { OnChanged(offset); } }; offsetRightField.OnChanged += x => { offset.right = x; if (OnChanged != null) { OnChanged(offset); } }; offsetTopField.OnChanged += x => { offset.top = x; if (OnChanged != null) { OnChanged(offset); } }; offsetBottomField.OnChanged += x => { offset.bottom = x; if (OnChanged != null) { OnChanged(offset); } }; Action DoOnConfirmed = () => { if (OnConfirmed != null) { OnConfirmed(); } }; offsetLeftField.OnConfirmed += DoOnConfirmed; offsetLeftField.OnFocusLost += DoOnConfirmed; offsetRightField.OnConfirmed += DoOnConfirmed; offsetRightField.OnFocusLost += DoOnConfirmed; offsetTopField.OnConfirmed += DoOnConfirmed; offsetTopField.OnFocusLost += DoOnConfirmed; offsetBottomField.OnConfirmed += DoOnConfirmed; offsetBottomField.OnFocusLost += DoOnConfirmed; }
private void OnInitialize() { EditorApplication.OnProjectSave += SaveSettings; SceneWindow sceneWindow = SceneWindow.GetWindow <SceneWindow>(); if (sceneWindow != null) { viewSettings = sceneWindow.Camera.ViewSettings; moveSettings = sceneWindow.Camera.MoveSettings; renderSettings = sceneWindow.Camera.RenderSettings; gizmoSettings = sceneWindow.GizmoDrawSettings; } else { viewSettings = ProjectSettings.GetObject <SceneCameraViewSettings>(SceneCamera.ViewSettingsKey); moveSettings = ProjectSettings.GetObject <SceneCameraMoveSettings>(SceneCamera.MoveSettingsKey); renderSettings = ProjectSettings.GetObject <RenderSettings>(SceneCamera.RenderSettingsKey); if (ProjectSettings.HasKey(SceneWindow.GizmoDrawSettingsKey)) { gizmoSettings = ProjectSettings.GetObject <GizmoDrawSettings>(SceneWindow.GizmoDrawSettingsKey); } else { gizmoSettings = GizmoDrawSettings.Default(); } } expandStates = ProjectSettings.GetObject <SerializableProperties>(ExpandStatesKey); InspectableContext inspectableContext = new InspectableContext(expandStates); GUILayout mainLayout = GUI.AddLayoutY(); GUIScrollArea scrollArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow); mainLayout.AddElement(scrollArea); GUILayoutX horzPadLayout = scrollArea.Layout.AddLayoutX(GUIOption.FlexibleWidth(100, 400)); horzPadLayout.AddSpace(5); GUILayout vertLayout = horzPadLayout.AddLayoutY(); horzPadLayout.AddSpace(5); vertLayout.AddSpace(5); vertLayout.AddElement(new GUILabel(new LocEdString("View Settings"), EditorStyles.LabelBold)); GUILayoutY viewSettingsLayout = vertLayout.AddLayoutY(); vertLayout.AddSpace(10); vertLayout.AddElement(new GUILabel(new LocEdString("Gizmo Settings"), EditorStyles.LabelBold)); GUILayoutY gizmoSettingsLayout = vertLayout.AddLayoutY(); vertLayout.AddSpace(10); vertLayout.AddElement(new GUILabel(new LocEdString("Move Settings"), EditorStyles.LabelBold)); GUILayoutY moveSettingsLayout = vertLayout.AddLayoutY(); vertLayout.AddSpace(10); vertLayout.AddElement(new GUILabel(new LocEdString("Render Settings"), EditorStyles.LabelBold)); GUILayoutY renderSettingsLayout = vertLayout.AddLayoutY(); guiViewSettings = new InspectorFieldDrawer(inspectableContext, viewSettingsLayout); guiGizmoSettings = new InspectorFieldDrawer(inspectableContext, gizmoSettingsLayout); guiMovementSettings = new InspectorFieldDrawer(inspectableContext, moveSettingsLayout); guiRenderSettings = new InspectorFieldDrawer(inspectableContext, renderSettingsLayout); objGizmoSettings = gizmoSettings; guiViewSettings.AddDefault(viewSettings); guiGizmoSettings.AddDefault(objGizmoSettings); guiMovementSettings.AddDefault(moveSettings); guiRenderSettings.AddDefault(renderSettings); mainLayout.AddSpace(5); GUILayout buttonCenterLayout = mainLayout.AddLayoutX(); mainLayout.AddSpace(5); GUIButton resetToDefaultBtn = new GUIButton(new LocEdString("Reset to defaults")); resetToDefaultBtn.OnClick += () => ConfirmResetToDefault(ResetToDefault, null); buttonCenterLayout.AddFlexibleSpace(); buttonCenterLayout.AddElement(resetToDefaultBtn); buttonCenterLayout.AddFlexibleSpace(); }
private void OnInitialize() { Title = "Project Manager"; Width = 500; Height = 290; GUILayout vertLayout = GUI.AddLayoutY(); vertLayout.AddSpace(5); GUILayout firstRow = vertLayout.AddLayoutX(); vertLayout.AddFlexibleSpace(); GUILayout secondRow = vertLayout.AddLayoutX(); vertLayout.AddSpace(5); GUILayout thirdRow = vertLayout.AddLayoutX(); vertLayout.AddFlexibleSpace(); GUILayout fourthRow = vertLayout.AddLayoutX(); vertLayout.AddSpace(5); projectInputBox = new GUITextField(new LocEdString("Project path"), 70, false, "", GUIOption.FixedWidth(398)); projectInputBox.Value = EditorSettings.LastOpenProject; GUIButton openBtn = new GUIButton(new LocEdString("Open"), GUIOption.FixedWidth(75)); openBtn.OnClick += OpenProject; firstRow.AddSpace(5); firstRow.AddElement(projectInputBox); firstRow.AddSpace(15); firstRow.AddElement(openBtn); firstRow.AddSpace(5); GUILabel recentProjectsLabel = new GUILabel(new LocEdString("Recent projects:")); secondRow.AddSpace(5); secondRow.AddElement(recentProjectsLabel); secondRow.AddFlexibleSpace(); GUIButton browseBtn = new GUIButton(new LocEdString("Browse"), GUIOption.FixedWidth(75)); browseBtn.OnClick += BrowseClicked; secondRow.AddElement(browseBtn); secondRow.AddSpace(5); thirdRow.AddSpace(5); GUIPanel recentProjectsPanel = thirdRow.AddPanel(); thirdRow.AddSpace(15); GUILayoutY thirdRowVertical = thirdRow.AddLayoutY(); GUIButton createBtn = new GUIButton(new LocEdString("Create new"), GUIOption.FixedWidth(75)); createBtn.OnClick += CreateClicked; thirdRowVertical.AddElement(createBtn); thirdRowVertical.AddFlexibleSpace(); thirdRow.AddSpace(5); recentProjectsArea = new GUIScrollArea(GUIOption.FixedWidth(385), GUIOption.FixedHeight(170)); GUILayoutX recentProjectsLayout = recentProjectsPanel.AddLayoutX(); recentProjectsLayout.AddSpace(10); GUILayoutY recentProjectsPanelY = recentProjectsLayout.AddLayoutY(); recentProjectsPanelY.AddSpace(5); recentProjectsPanelY.AddElement(recentProjectsArea); recentProjectsPanelY.AddSpace(5); recentProjectsLayout.AddFlexibleSpace(); GUIPanel scrollAreaBgPanel = recentProjectsPanel.AddPanel(1); GUITexture scrollAreaBgTex = new GUITexture(null, true, EditorStylesInternal.ScrollAreaBg); scrollAreaBgPanel.AddElement(scrollAreaBgTex); autoLoadToggle = new GUIToggle(""); autoLoadToggle.Value = EditorSettings.AutoLoadLastProject; GUILabel autoLoadLabel = new GUILabel(new LocEdString("Automatically load last open project")); GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel"), GUIOption.FixedWidth(75)); cancelBtn.OnClick += CancelClicked; fourthRow.AddSpace(5); fourthRow.AddElement(autoLoadToggle); fourthRow.AddElement(autoLoadLabel); fourthRow.AddFlexibleSpace(); fourthRow.AddElement(cancelBtn); fourthRow.AddSpace(5); RefreshRecentProjects(); }
private void OnInitialize() { mainLayout = GUI.AddLayoutY(); GUIContent viewIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.View), new LocEdString("View")); GUIContent moveIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Move), new LocEdString("Move")); GUIContent rotateIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Rotate), new LocEdString("Rotate")); GUIContent scaleIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Scale), new LocEdString("Scale")); GUIContent localIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Local), new LocEdString("Local")); GUIContent worldIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.World), new LocEdString("World")); GUIContent pivotIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Pivot), new LocEdString("Pivot")); GUIContent centerIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Center), new LocEdString("Center")); GUIContent moveSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.MoveSnap), new LocEdString("Move snap")); GUIContent rotateSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.RotateSnap), new LocEdString("Rotate snap")); GUIToggleGroup handlesTG = new GUIToggleGroup(); viewButton = new GUIToggle(viewIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); moveButton = new GUIToggle(moveIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); rotateButton = new GUIToggle(rotateIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); scaleButton = new GUIToggle(scaleIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); GUIToggleGroup coordModeTG = new GUIToggleGroup(); localCoordButton = new GUIToggle(localIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75)); worldCoordButton = new GUIToggle(worldIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75)); GUIToggleGroup pivotModeTG = new GUIToggleGroup(); pivotButton = new GUIToggle(pivotIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); centerButton = new GUIToggle(centerIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35)); moveSnapButton = new GUIToggle(moveSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35)); moveSnapInput = new GUIFloatField("", GUIOption.FlexibleWidth(35)); rotateSnapButton = new GUIToggle(rotateSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35)); rotateSnapInput = new GUIFloatField("", GUIOption.FlexibleWidth(35)); GUIContent cameraOptionsIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.SceneCameraOptions), new LocEdString("Camera options")); cameraOptionsButton = new GUIButton(cameraOptionsIcon); viewButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.View); moveButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Move); rotateButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Rotate); scaleButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Scale); localCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.Local); worldCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.World); pivotButton.OnClick += () => OnPivotModeButtonClicked(HandlePivotMode.Pivot); centerButton.OnClick += () => OnPivotModeButtonClicked(HandlePivotMode.Center); moveSnapButton.OnToggled += (bool active) => OnMoveSnapToggled(active); moveSnapInput.OnChanged += (float value) => OnMoveSnapValueChanged(value); rotateSnapButton.OnToggled += (bool active) => OnRotateSnapToggled(active); rotateSnapInput.OnChanged += (float value) => OnRotateSnapValueChanged(value); cameraOptionsButton.OnClick += () => OnCameraOptionsClicked(); GUILayout handlesLayout = mainLayout.AddLayoutX(); handlesLayout.AddElement(viewButton); handlesLayout.AddElement(moveButton); handlesLayout.AddElement(rotateButton); handlesLayout.AddElement(scaleButton); handlesLayout.AddSpace(10); handlesLayout.AddElement(localCoordButton); handlesLayout.AddElement(worldCoordButton); handlesLayout.AddSpace(10); handlesLayout.AddElement(pivotButton); handlesLayout.AddElement(centerButton); handlesLayout.AddFlexibleSpace(); handlesLayout.AddElement(moveSnapButton); handlesLayout.AddElement(moveSnapInput); handlesLayout.AddSpace(10); handlesLayout.AddElement(rotateSnapButton); handlesLayout.AddElement(rotateSnapInput); handlesLayout.AddSpace(10); handlesLayout.AddElement(cameraOptionsButton); handlesLayout.SetHeight(viewButton.Bounds.height); GUIPanel mainPanel = mainLayout.AddPanel(); rtPanel = mainPanel.AddPanel(); // Loading progress loadLabel = new GUILabel(new LocEdString("Loading scene...")); loadProgressBar = new GUIProgressBar("", GUIOption.FixedWidth(200)); progressLayout = mainPanel.AddLayoutY(); progressLayout.AddFlexibleSpace(); GUILayout loadLabelLayout = progressLayout.AddLayoutX(); loadLabelLayout.AddFlexibleSpace(); loadLabelLayout.AddElement(loadLabel); loadLabelLayout.AddFlexibleSpace(); GUILayout progressBarLayout = progressLayout.AddLayoutX(); progressBarLayout.AddFlexibleSpace(); progressBarLayout.AddElement(loadProgressBar); progressBarLayout.AddFlexibleSpace(); progressLayout.AddFlexibleSpace(); progressLayout.Active = false; selectionPanel = mainPanel.AddPanel(-1); sceneAxesPanel = mainPanel.AddPanel(-1); sceneAxesGUI = new SceneAxesGUI(this, sceneAxesPanel, HandleAxesGUISize, HandleAxesGUISize, ProjectionType.Perspective); focusCatcher = new GUIButton("", EditorStyles.Blank); focusCatcher.OnFocusGained += () => hasContentFocus = true; focusCatcher.OnFocusLost += () => hasContentFocus = false; GUIPanel focusPanel = GUI.AddPanel(-2); focusPanel.AddElement(focusCatcher); viewToolKey = new VirtualButton(ViewToolBinding); moveToolKey = new VirtualButton(MoveToolBinding); rotateToolKey = new VirtualButton(RotateToolBinding); scaleToolKey = new VirtualButton(ScaleToolBinding); frameKey = new VirtualButton(FrameBinding); UpdateRenderTexture(Width, Height - HeaderHeight); UpdateLoadingProgress(); }
/// <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 resource tile entry. /// </summary> /// <param name="owner">Content area this entry is part of.</param> /// <param name="parent">Parent layout to add this entry's GUI elements to.</param> /// <param name="path">Path to the project library entry to display data for.</param> /// <param name="index">Sequential index of the entry in the conent area.</param> /// <param name="width">Width of the GUI entry.</param> /// <param name="height">Maximum allowed height for the label.</param>" /// <param name="type">Type of the entry, which controls its style and/or behaviour.</param> public LibraryGUIEntry(LibraryGUIContent owner, GUILayout parent, string path, int index, int width, int height, LibraryGUIEntryType type) { GUILayout entryLayout; if (owner.GridLayout) { entryLayout = parent.AddLayoutY(); } else { entryLayout = parent.AddLayoutX(); } SpriteTexture iconTexture = GetIcon(path, owner.TileSize); icon = new GUITexture(iconTexture, GUITextureScaleMode.ScaleToFit, true, GUIOption.FixedHeight(owner.TileSize), GUIOption.FixedWidth(owner.TileSize)); label = null; string name = PathEx.GetTail(path); if (owner.GridLayout) { int labelHeight = height - owner.TileSize; label = new GUILabel(name, EditorStyles.MultiLineLabelCentered, GUIOption.FixedWidth(width), GUIOption.FixedHeight(labelHeight)); switch (type) { case LibraryGUIEntryType.Single: break; case LibraryGUIEntryType.MultiFirst: groupUnderlay = new GUITexture(null, LibraryEntryFirstBg); break; case LibraryGUIEntryType.MultiElement: groupUnderlay = new GUITexture(null, LibraryEntryBg); break; case LibraryGUIEntryType.MultiLast: groupUnderlay = new GUITexture(null, LibraryEntryLastBg); break; } } else { label = new GUILabel(name, GUIOption.FixedWidth(width - owner.TileSize), GUIOption.FixedHeight(height)); switch (type) { case LibraryGUIEntryType.Single: break; case LibraryGUIEntryType.MultiFirst: groupUnderlay = new GUITexture(null, LibraryEntryVertFirstBg); break; case LibraryGUIEntryType.MultiElement: groupUnderlay = new GUITexture(null, LibraryEntryVertBg); break; case LibraryGUIEntryType.MultiLast: groupUnderlay = new GUITexture(null, LibraryEntryVertLastBg); break; } } entryLayout.AddElement(icon); entryLayout.AddElement(label); if (groupUnderlay != null) { owner.DeepUnderlay.AddElement(groupUnderlay); } this.owner = owner; this.index = index; this.path = path; this.bounds = new Rect2I(); this.underlay = null; this.type = type; this.width = width; this.height = height; }
private void OnInitialize() { guiColor = new GUIColorField("", GUIOption.FixedWidth(100)); guiSlider2DTex = new GUITexture(null, GUIOption.FixedHeight(ColorBoxHeight), GUIOption.FixedWidth(ColorBoxWidth)); guiSliderVertTex = new GUITexture(null, GUIOption.FixedHeight(SliderSideHeight), GUIOption.FixedWidth(SliderSideWidth)); guiSliderRHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight)); guiSliderGHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight)); guiSliderBHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight)); guiSliderAHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight)); guiColorBoxBtn = new GUIButton(colorBoxMode.ToString()); guiColorModeBtn = new GUIButton(sliderMode.ToString()); guiSliderVert = new GUISliderV(EditorStyles.ColorSliderVert); guiSliderRHorz = new GUISliderH(EditorStyles.ColorSliderHorz); guiSliderGHorz = new GUISliderH(EditorStyles.ColorSliderHorz); guiSliderBHorz = new GUISliderH(EditorStyles.ColorSliderHorz); guiSliderAHorz = new GUISliderH(EditorStyles.ColorSliderHorz); guiSlider2DHandle = new GUITexture(null, EditorStyles.ColorSlider2DHandle); guiLabelR = new GUILabel(new LocEdString("R")); guiLabelG = new GUILabel(new LocEdString("G")); guiLabelB = new GUILabel(new LocEdString("B")); guiLabelA = new GUILabel(new LocEdString("A")); guiInputR = new GUIIntField(); guiInputG = new GUIIntField(); guiInputB = new GUIIntField(); guiInputA = new GUIIntField(); guiOK = new GUIButton(new LocEdString("OK")); guiCancel = new GUIButton(new LocEdString("Cancel")); guiColorBoxBtn.OnClick += OnColorBoxModeChanged; guiColorModeBtn.OnClick += OnSliderModeChanged; guiSliderVert.OnChanged += OnSliderVertChanged; guiSliderRHorz.OnChanged += OnSliderRHorzChanged; guiSliderGHorz.OnChanged += OnSliderGHorzChanged; guiSliderBHorz.OnChanged += OnSliderBHorzChanged; guiSliderAHorz.OnChanged += OnSliderAHorzChanged; guiInputR.OnChanged += OnInputRChanged; guiInputG.OnChanged += OnInputGChanged; guiInputB.OnChanged += OnInputBChanged; guiInputA.OnChanged += OnInputAChanged; guiOK.OnClick += OnOK; guiCancel.OnClick += OnCancel; GUIPanel mainPanel = GUI.AddPanel(0); GUILayout v0 = mainPanel.AddLayoutY(); v0.AddSpace(5); GUILayout h0 = v0.AddLayoutX(); h0.AddSpace(10); h0.AddElement(guiColor); h0.AddFlexibleSpace(); h0.AddElement(guiColorBoxBtn); h0.AddElement(guiColorModeBtn); h0.AddSpace(10); v0.AddSpace(10); GUILayout h1 = v0.AddLayoutX(); h1.AddSpace(10); h1.AddElement(guiSlider2DTex); h1.AddFlexibleSpace(); h1.AddElement(guiSliderVertTex); h1.AddSpace(10); v0.AddSpace(10); GUILayout h2 = v0.AddLayoutX(); h2.AddSpace(10); h2.AddElement(guiLabelR); h2.AddFlexibleSpace(); h2.AddElement(guiSliderRHorzTex); h2.AddFlexibleSpace(); h2.AddElement(guiInputR); h2.AddSpace(10); v0.AddSpace(5); GUILayout h3 = v0.AddLayoutX(); h3.AddSpace(10); h3.AddElement(guiLabelG); h3.AddFlexibleSpace(); h3.AddElement(guiSliderGHorzTex); h3.AddFlexibleSpace(); h3.AddElement(guiInputG); h3.AddSpace(10); v0.AddSpace(5); GUILayout h4 = v0.AddLayoutX(); h4.AddSpace(10); h4.AddElement(guiLabelB); h4.AddFlexibleSpace(); h4.AddElement(guiSliderBHorzTex); h4.AddFlexibleSpace(); h4.AddElement(guiInputB); h4.AddSpace(10); v0.AddSpace(5); GUILayout h5 = v0.AddLayoutX(); h5.AddSpace(10); h5.AddElement(guiLabelA); h5.AddFlexibleSpace(); h5.AddElement(guiSliderAHorzTex); h5.AddFlexibleSpace(); h5.AddElement(guiInputA); h5.AddSpace(10); v0.AddSpace(10); GUILayout h6 = v0.AddLayoutX(); h6.AddFlexibleSpace(); h6.AddElement(guiOK); h6.AddSpace(10); h6.AddElement(guiCancel); h6.AddFlexibleSpace(); v0.AddSpace(5); GUIPanel overlay = GUI.AddPanel(-1); overlay.SetWidth(Width); overlay.SetHeight(Height); overlay.AddElement(guiSliderVert); overlay.AddElement(guiSliderRHorz); overlay.AddElement(guiSliderGHorz); overlay.AddElement(guiSliderBHorz); overlay.AddElement(guiSliderAHorz); overlay.AddElement(guiSlider2DHandle); colorBox = new ColorSlider2D(guiSlider2DTex, guiSlider2DHandle, ColorBoxWidth, ColorBoxHeight); sideSlider = new ColorSlider1DVert(guiSliderVertTex, guiSliderVert, SliderSideWidth, SliderSideHeight); sliderR = new ColorSlider1DHorz(guiSliderRHorzTex, guiSliderRHorz, SliderIndividualWidth, SliderIndividualHeight); sliderG = new ColorSlider1DHorz(guiSliderGHorzTex, guiSliderGHorz, SliderIndividualWidth, SliderIndividualHeight); sliderB = new ColorSlider1DHorz(guiSliderBHorzTex, guiSliderBHorz, SliderIndividualWidth, SliderIndividualHeight); sliderA = new ColorSlider1DHorz(guiSliderAHorzTex, guiSliderAHorz, SliderIndividualWidth, SliderIndividualHeight); colorBox.OnValueChanged += OnColorBoxValueChanged; Color startA = new Color(0, 0, 0, 1); Color stepA = new Color(1, 1, 1, 0); sliderA.UpdateTexture(startA, stepA, false); guiInputA.SetRange(0, 255); guiInputA.Value = 255; guiSliderAHorz.Percent = 1.0f; guiColor.Value = SelectedColor; UpdateInputBoxValues(); Update2DSliderValues(); Update1DSliderValues(); UpdateSliderMode(); Update2DSliderTextures(); Update1DSliderTextures(); }
/// <summary> /// Constructs a new set of GUI elements for inspecting the post process settings object. /// </summary> /// <param name="settings">Initial values to assign to the GUI elements.</param> /// <param name="layout">Layout to append the GUI elements to.</param> /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state. /// </param> public PostProcessSettingsGUI(PostProcessSettings settings, GUILayout layout, SerializableProperties properties) { this.settings = settings; this.properties = properties; // Auto exposure enableAutoExposureField.OnChanged += x => { this.settings.EnableAutoExposure = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableAutoExposureField); autoExposureFoldout.OnToggled += x => { properties.SetBool("autoExposure_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(autoExposureFoldout); autoExposureLayout = layout.AddLayoutX(); { autoExposureLayout.AddSpace(10); GUILayoutY contentsLayout = autoExposureLayout.AddLayoutY(); autoExposureGUI = new AutoExposureSettingsGUI(settings.AutoExposure, contentsLayout); autoExposureGUI.OnChanged += x => { this.settings.AutoExposure = x; MarkAsModified(); }; autoExposureGUI.OnConfirmed += ConfirmModify; } // Tonemapping enableToneMappingField.OnChanged += x => { this.settings.EnableTonemapping = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(enableToneMappingField); //// Tonemapping settings toneMappingFoldout.OnToggled += x => { properties.SetBool("toneMapping_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(toneMappingFoldout); toneMappingLayout = layout.AddLayoutX(); { toneMappingLayout.AddSpace(10); GUILayoutY contentsLayout = toneMappingLayout.AddLayoutY(); toneMappingGUI = new TonemappingSettingsGUI(settings.Tonemapping, contentsLayout); toneMappingGUI.OnChanged += x => { this.settings.Tonemapping = x; MarkAsModified(); }; toneMappingGUI.OnConfirmed += ConfirmModify; } //// White balance settings whiteBalanceFoldout.OnToggled += x => { properties.SetBool("whiteBalance_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(whiteBalanceFoldout); whiteBalanceLayout = layout.AddLayoutX(); { whiteBalanceLayout.AddSpace(10); GUILayoutY contentsLayout = whiteBalanceLayout.AddLayoutY(); whiteBalanceGUI = new WhiteBalanceSettingsGUI(settings.WhiteBalance, contentsLayout); whiteBalanceGUI.OnChanged += x => { this.settings.WhiteBalance = x; MarkAsModified(); }; whiteBalanceGUI.OnConfirmed += ConfirmModify; } //// Color grading settings colorGradingFoldout.OnToggled += x => { properties.SetBool("colorGrading_Expanded", x); ToggleFoldoutFields(); }; layout.AddElement(colorGradingFoldout); colorGradingLayout = layout.AddLayoutX(); { colorGradingLayout.AddSpace(10); GUILayoutY contentsLayout = colorGradingLayout.AddLayoutY(); colorGradingGUI = new ColorGradingSettingsGUI(settings.ColorGrading, contentsLayout); colorGradingGUI.OnChanged += x => { this.settings.ColorGrading = x; MarkAsModified(); }; colorGradingGUI.OnConfirmed += ConfirmModify; } // Gamma gammaField.OnChanged += x => { this.settings.Gamma = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(gammaField); // Exposure scale exposureScaleField.OnChanged += x => { this.settings.ExposureScale = x; MarkAsModified(); ConfirmModify(); }; layout.AddElement(exposureScaleField); ToggleFoldoutFields(); }
/// <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)); } } } } int minHorzElemSpacing = 0; if (viewType == ProjectViewType.List16) { tileSize = 16; gridLayout = false; elementsPerRow = 1; minHorzElemSpacing = 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, 0, 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; minHorzElemSpacing = 10; vertElemSpacing = 12; break; case ProjectViewType.Grid48: tileSize = 48; elemWidth = tileSize; elemHeight = tileSize + 36; minHorzElemSpacing = 8; vertElemSpacing = 10; break; case ProjectViewType.Grid32: tileSize = 32; elemWidth = tileSize + 16; elemHeight = tileSize + 48; minHorzElemSpacing = 6; vertElemSpacing = 10; break; } gridLayout = true; int availableWidth = bounds.width; elementsPerRow = MathEx.FloorToInt((availableWidth - minHorzElemSpacing) / (float)(elemWidth + minHorzElemSpacing)); int numRows = MathEx.CeilToInt(resourcesToDisplay.Count / (float)Math.Max(elementsPerRow, 1)); 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 - minHorzElemSpacing) / (float)(elemWidth + minHorzElemSpacing)); } int extraRowSpace = availableWidth - minHorzElemSpacing * 2 - elementsPerRow * elemWidth; paddingLeft = minHorzElemSpacing; paddingRight = minHorzElemSpacing; float horzSpacing = 0.0f; // Distribute the spacing to the padding, as there are not in-between spaces to apply it to if (extraRowSpace > 0 && elementsPerRow < 2) { int extraPadding = extraRowSpace / 2; paddingLeft += extraPadding; paddingRight += (extraRowSpace - extraPadding); extraRowSpace = 0; } else { horzSpacing = extraRowSpace / (float)(elementsPerRow - 1); } elementsPerRow = Math.Max(elementsPerRow, 1); main.AddSpace(TOP_MARGIN); GUILayoutX rowLayout = main.AddLayoutX(); rowLayout.AddSpace(paddingLeft); float spacingCounter = 0.0f; int elemsInRow = 0; for (int i = 0; i < resourcesToDisplay.Count; i++) { if (elemsInRow == elementsPerRow && elemsInRow > 0) { main.AddSpace(vertElemSpacing); rowLayout = main.AddLayoutX(); rowLayout.AddSpace(paddingLeft); elemsInRow = 0; spacingCounter = 0.0f; } ResourceToDisplay entry = resourcesToDisplay[i]; elemsInRow++; if (elemsInRow != elementsPerRow) { spacingCounter += horzSpacing; } int spacing = (int)spacingCounter; spacingCounter -= spacing; LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, rowLayout, entry.path, i, elemWidth, elemHeight, spacing, entry.type); entries.Add(guiEntry); entryLookup[guiEntry.path] = guiEntry; if (elemsInRow == elementsPerRow) { rowLayout.AddSpace(paddingRight); } rowLayout.AddSpace(spacing); } int extraElements = elementsPerRow - elemsInRow; int extraSpacing = 0; if (extraElements > 1) { spacingCounter += (extraElements - 1) * horzSpacing; extraSpacing += (int)spacingCounter; } if (extraElements > 0) { rowLayout.AddSpace(elemWidth * extraElements + extraSpacing + paddingRight); } main.AddFlexibleSpace(); } // Fix bounds as that makes GUI updates faster underlay.Bounds = main.Bounds; overlay.Bounds = main.Bounds; deepUnderlay.Bounds = main.Bounds; renameOverlay.Bounds = main.Bounds; for (int i = 0; i < entries.Count; i++) { LibraryGUIEntry guiEntry = entries[i]; guiEntry.Initialize(); } }