/// <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); guiElem = new GUIFloatField(title); guiElem.OnChanged += (x) => { material.SetFloat(shaderParam.name, x); EditorApplication.SetDirty(material); }; layout.AddElement(guiElem); }
/// <summary> /// Constructs a new color picker window. /// </summary> /// <param name="color">Initial color to display.</param> /// <param name="closedCallback">Optional callback to trigger when the user selects a color or cancels out /// of the dialog.</param> protected ColorPicker(Color color, Action<bool, Color> closedCallback = null) : base(false) { Title = new LocEdString("Color Picker"); Width = 270; Height = 400; colRed = color.r; colGreen = color.g; colBlue = color.b; colAlpha = color.a; RGBToHSV(); this.closedCallback = closedCallback; }
/// <summary> /// Constructs a new color picker window. /// </summary> /// <param name="color">Initial color to display.</param> /// <param name="closedCallback">Optional callback to trigger when the user selects a color or cancels out /// of the dialog.</param> protected ColorPicker(Color color, Action <bool, Color> closedCallback = null) : base(false) { Title = new LocEdString("Color Picker"); Width = 270; Height = 400; colRed = color.r; colGreen = color.g; colBlue = color.b; colAlpha = color.a; RGBToHSV(); this.closedCallback = closedCallback; }
/// <summary> /// Attempts to open a project at the path currently entered in the project path input box. /// </summary> private void OpenProject() { string projectPath = projectInputBox.Value; if (EditorApplication.IsValidProject(projectPath)) { EditorSettings.AutoLoadLastProject = autoLoadToggle.Value; Close(); EditorApplication.LoadProject(projectPath); } else { // Remove invalid project from recent projects list RecentProject[] recentProjects = EditorSettings.RecentProjects; for (int i = 0; i < recentProjects.Length; i++) { if (PathEx.Compare(recentProjects[i].path, projectPath)) { RecentProject[] newRecentProjects = new RecentProject[recentProjects.Length - 1]; int idx = 0; for (int j = 0; j < recentProjects.Length; j++) { if (i == j) { continue; } newRecentProjects[idx] = recentProjects[j]; idx++; } EditorSettings.RecentProjects = newRecentProjects; EditorSettings.Save(); RefreshRecentProjects(); break; } } // Warn user LocString message = new LocEdString("Provided project path \"{0}\" doesn't contain a valid project."); message.SetParameter(0, projectPath); DialogBox.Open(new LocEdString("Error"), message, DialogBox.Type.OK); } }
/// <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, EditorStyles.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> /// 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 a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of texture 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 MaterialParamTextureGUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.Name); guiElem = new GUITextureField(title); switch (shaderParam.Type) { case ShaderParameterType.Texture2D: guiElem.OnChanged += (x) => { Texture2D texture = Resources.Load <Texture2D>(x); material.SetTexture2D(shaderParam.Name, texture); EditorApplication.SetDirty(material); }; break; case ShaderParameterType.Texture3D: guiElem.OnChanged += (x) => { Texture3D texture = Resources.Load <Texture3D>(x); material.SetTexture3D(shaderParam.Name, texture); EditorApplication.SetDirty(material); }; break; case ShaderParameterType.TextureCube: guiElem.OnChanged += (x) => { TextureCube texture = Resources.Load <TextureCube>(x); material.SetTextureCube(shaderParam.Name, texture); EditorApplication.SetDirty(material); }; break; } layout.AddElement(guiElem); }
/// <summary> /// Attempts to open a project at the path currently entered in the project path input box. /// </summary> private void OpenProject() { string projectPath = projectInputBox.Value; if (EditorApplication.IsValidProject(projectPath)) { EditorSettings.AutoLoadLastProject = autoLoadToggle.Value; Close(); EditorApplication.LoadProject(projectPath); } else { // Remove invalid project from recent projects list RecentProject[] recentProjects = EditorSettings.RecentProjects; for (int i = 0; i < recentProjects.Length; i++) { if (PathEx.Compare(recentProjects[i].path, projectPath)) { RecentProject[] newRecentProjects = new RecentProject[recentProjects.Length - 1]; int idx = 0; for (int j = 0; j < recentProjects.Length; j++) { if (i == j) continue; newRecentProjects[idx] = recentProjects[j]; idx++; } EditorSettings.RecentProjects = newRecentProjects; EditorSettings.Save(); RefreshRecentProjects(); break; } } // Warn user LocString message = new LocEdString("Provided project path \"{0}\" doesn't contain a valid project."); message.SetParameter(0, projectPath); DialogBox.Open(new LocEdString("Error"), message, DialogBox.Type.OK); } }
/// <summary> /// Recreates the entire curve editor GUI depending on the currently selected scene object. /// </summary> private void RebuildGUI() { GUI.Clear(); guiCurveEditor = null; guiFieldDisplay = null; if (selectedSO == null) { GUILabel warningLbl = new GUILabel(new LocEdString("Select an object to animate in the Hierarchy or Scene windows.")); GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX horzLayout = vertLayout.AddLayoutX(); vertLayout.AddFlexibleSpace(); horzLayout.AddFlexibleSpace(); horzLayout.AddElement(warningLbl); horzLayout.AddFlexibleSpace(); return; } // Top button row GUIContent playIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Play), new LocEdString("Play")); GUIContent recordIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Record), new LocEdString("Record")); GUIContent prevFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameBack), new LocEdString("Previous frame")); GUIContent nextFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameForward), new LocEdString("Next frame")); GUIContent addKeyframeIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddKeyframe), new LocEdString("Add keyframe")); GUIContent addEventIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddEvent), new LocEdString("Add event")); GUIContent optionsIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Options), new LocEdString("Options")); playButton = new GUIToggle(playIcon, EditorStyles.Button); recordButton = new GUIToggle(recordIcon, EditorStyles.Button); prevFrameButton = new GUIButton(prevFrameIcon); frameInputField = new GUIIntField(); nextFrameButton = new GUIButton(nextFrameIcon); addKeyframeButton = new GUIButton(addKeyframeIcon); addEventButton = new GUIButton(addEventIcon); optionsButton = new GUIButton(optionsIcon); playButton.OnToggled += x => { if(x) SwitchState(State.Playback); else SwitchState(State.Normal); }; recordButton.OnToggled += x => { if (x) SwitchState(State.Recording); else SwitchState(State.Normal); }; prevFrameButton.OnClick += () => { SetCurrentFrame(currentFrameIdx - 1); switch (state) { case State.Recording: case State.Normal: PreviewFrame(currentFrameIdx); break; default: SwitchState(State.Normal); break; } }; frameInputField.OnChanged += x => { SetCurrentFrame(x); switch (state) { case State.Recording: case State.Normal: PreviewFrame(currentFrameIdx); break; default: SwitchState(State.Normal); break; } }; nextFrameButton.OnClick += () => { SetCurrentFrame(currentFrameIdx + 1); switch (state) { case State.Recording: case State.Normal: PreviewFrame(currentFrameIdx); break; default: SwitchState(State.Normal); break; } }; addKeyframeButton.OnClick += () => { SwitchState(State.Normal); guiCurveEditor.AddKeyFrameAtMarker(); }; addEventButton.OnClick += () => { SwitchState(State.Normal); guiCurveEditor.AddEventAtMarker(); }; optionsButton.OnClick += () => { Vector2I openPosition = ScreenToWindowPos(Input.PointerPosition); AnimationOptions dropDown = DropDownWindow.Open<AnimationOptions>(this, openPosition); dropDown.Initialize(this); }; // Property buttons addPropertyBtn = new GUIButton(new LocEdString("Add property")); delPropertyBtn = new GUIButton(new LocEdString("Delete selected")); addPropertyBtn.OnClick += () => { Action openPropertyWindow = () => { Vector2I windowPos = ScreenToWindowPos(Input.PointerPosition); FieldSelectionWindow fieldSelection = DropDownWindow.Open<FieldSelectionWindow>(this, windowPos); fieldSelection.OnFieldSelected += OnFieldAdded; }; if (clipInfo.clip == null) { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("Selected object doesn't have an animation clip assigned. Would you like to create" + " a new animation clip?"); DialogBox.Open(title, message, DialogBox.Type.YesNoCancel, type => { if (type == DialogBox.ResultType.Yes) { string clipSavePath; if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.asset", out clipSavePath)) { SwitchState(State.Empty); clipSavePath = Path.ChangeExtension(clipSavePath, ".asset"); AnimationClip newClip = new AnimationClip(); ProjectLibrary.Create(newClip, clipSavePath); LoadAnimClip(newClip); Animation animation = selectedSO.GetComponent<Animation>(); if (animation == null) animation = selectedSO.AddComponent<Animation>(); animation.DefaultClip = newClip; EditorApplication.SetSceneDirty(); SwitchState(State.Normal); openPropertyWindow(); } } }); } else { if (clipInfo.isImported) { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("You cannot add/edit/remove curves from animation clips that" + " are imported from an external file."); DialogBox.Open(title, message, DialogBox.Type.OK); } else { SwitchState(State.Normal); openPropertyWindow(); } } }; delPropertyBtn.OnClick += () => { if (clipInfo.clip == null) return; SwitchState(State.Normal); if (clipInfo.isImported) { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("You cannot add/edit/remove curves from animation clips that" + " are imported from an external file."); DialogBox.Open(title, message, DialogBox.Type.OK); } else { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("Are you sure you want to remove all selected fields?"); DialogBox.Open(title, message, DialogBox.Type.YesNo, x => { if (x == DialogBox.ResultType.Yes) { RemoveSelectedFields(); ApplyClipChanges(); } }); } }; GUIPanel mainPanel = GUI.AddPanel(); GUIPanel backgroundPanel = GUI.AddPanel(1); GUILayout mainLayout = mainPanel.AddLayoutY(); buttonLayout = mainLayout.AddLayoutX(); buttonLayout.AddSpace(5); buttonLayout.AddElement(playButton); buttonLayout.AddElement(recordButton); buttonLayout.AddSpace(5); buttonLayout.AddElement(prevFrameButton); buttonLayout.AddElement(frameInputField); buttonLayout.AddElement(nextFrameButton); buttonLayout.AddSpace(5); buttonLayout.AddElement(addKeyframeButton); buttonLayout.AddElement(addEventButton); buttonLayout.AddSpace(5); buttonLayout.AddElement(optionsButton); buttonLayout.AddFlexibleSpace(); buttonLayoutHeight = playButton.Bounds.height; GUITexture buttonBackground = new GUITexture(null, EditorStyles.HeaderBackground); buttonBackground.Bounds = new Rect2I(0, 0, Width, buttonLayoutHeight); backgroundPanel.AddElement(buttonBackground); GUILayout contentLayout = mainLayout.AddLayoutX(); GUILayout fieldDisplayLayout = contentLayout.AddLayoutY(GUIOption.FixedWidth(FIELD_DISPLAY_WIDTH)); guiFieldDisplay = new GUIAnimFieldDisplay(fieldDisplayLayout, FIELD_DISPLAY_WIDTH, Height - buttonLayoutHeight * 2, selectedSO); guiFieldDisplay.OnEntrySelected += OnFieldSelected; GUILayout bottomButtonLayout = fieldDisplayLayout.AddLayoutX(); bottomButtonLayout.AddElement(addPropertyBtn); bottomButtonLayout.AddElement(delPropertyBtn); horzScrollBar = new GUIResizeableScrollBarH(); horzScrollBar.OnScrollOrResize += OnHorzScrollOrResize; vertScrollBar = new GUIResizeableScrollBarV(); vertScrollBar.OnScrollOrResize += OnVertScrollOrResize; GUITexture separator = new GUITexture(null, EditorStyles.Separator, GUIOption.FixedWidth(3)); contentLayout.AddElement(separator); GUILayout curveLayout = contentLayout.AddLayoutY(); GUILayout curveLayoutHorz = curveLayout.AddLayoutX(); GUILayout horzScrollBarLayout = curveLayout.AddLayoutX(); horzScrollBarLayout.AddElement(horzScrollBar); horzScrollBarLayout.AddFlexibleSpace(); editorPanel = curveLayoutHorz.AddPanel(); curveLayoutHorz.AddElement(vertScrollBar); curveLayoutHorz.AddFlexibleSpace(); scrollBarHeight = horzScrollBar.Bounds.height; scrollBarWidth = vertScrollBar.Bounds.width; Vector2I curveEditorSize = GetCurveEditorSize(); guiCurveEditor = new GUICurveEditor(this, editorPanel, curveEditorSize.x, curveEditorSize.y); guiCurveEditor.OnFrameSelected += OnFrameSelected; guiCurveEditor.OnEventAdded += OnEventsChanged; guiCurveEditor.OnEventModified += EditorApplication.SetProjectDirty; guiCurveEditor.OnEventDeleted += OnEventsChanged; guiCurveEditor.OnCurveModified += () => { SwitchState(State.Normal); ApplyClipChanges(); PreviewFrame(currentFrameIdx); EditorApplication.SetProjectDirty(); }; guiCurveEditor.OnClicked += () => { if(state != State.Recording) SwitchState(State.Normal); }; guiCurveEditor.Redraw(); horzScrollBar.SetWidth(curveEditorSize.x); vertScrollBar.SetHeight(curveEditorSize.y); UpdateScrollBarSize(); }
/// <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> /// 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.panel = inspectorLayout.AddPanel(); var persistentProperties = persistentData.GetProperties(meta.UUID.ToString()); inspectorResource.inspector = InspectorUtility.GetInspector(resourceType); inspectorResource.inspector.Initialize(inspectorResource.panel, activeResourcePath, persistentProperties); inspectorLayout.AddFlexibleSpace(); }
private void RebuildGUI() { GUI.Clear(); guiCurveEditor = null; guiFieldDisplay = null; if (selectedSO == null) { GUILabel warningLbl = new GUILabel(new LocEdString("Select an object to animate in the Hierarchy or Scene windows.")); GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX horzLayout = vertLayout.AddLayoutX(); vertLayout.AddFlexibleSpace(); horzLayout.AddFlexibleSpace(); horzLayout.AddElement(warningLbl); horzLayout.AddFlexibleSpace(); return; } // Top button row GUIContent playIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Play), new LocEdString("Play")); GUIContent recordIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Record), new LocEdString("Record")); GUIContent prevFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameBack), new LocEdString("Previous frame")); GUIContent nextFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameForward), new LocEdString("Next frame")); GUIContent addKeyframeIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddKeyframe), new LocEdString("Add keyframe")); GUIContent addEventIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddEvent), new LocEdString("Add event")); GUIContent optionsIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Options), new LocEdString("Options")); playButton = new GUIButton(playIcon); recordButton = new GUIButton(recordIcon); prevFrameButton = new GUIButton(prevFrameIcon); frameInputField = new GUIIntField(); nextFrameButton = new GUIButton(nextFrameIcon); addKeyframeButton = new GUIButton(addKeyframeIcon); addEventButton = new GUIButton(addEventIcon); optionsButton = new GUIButton(optionsIcon); playButton.OnClick += () => { // TODO // - Record current state of the scene object hierarchy // - Evaluate all curves manually and update them // - On end, restore original values of the scene object hierarchy }; recordButton.OnClick += () => { // TODO // - Every frame read back current values of all the current curve's properties and assign it to the current frame }; prevFrameButton.OnClick += () => { SetCurrentFrame(currentFrameIdx - 1); }; frameInputField.OnChanged += SetCurrentFrame; nextFrameButton.OnClick += () => { SetCurrentFrame(currentFrameIdx + 1); }; addKeyframeButton.OnClick += () => { guiCurveEditor.AddKeyFrameAtMarker(); }; addEventButton.OnClick += () => { guiCurveEditor.AddEventAtMarker(); }; optionsButton.OnClick += () => { Vector2I openPosition = ScreenToWindowPos(Input.PointerPosition); AnimationOptions dropDown = DropDownWindow.Open <AnimationOptions>(this, openPosition); dropDown.Initialize(this); }; // Property buttons addPropertyBtn = new GUIButton(new LocEdString("Add property")); delPropertyBtn = new GUIButton(new LocEdString("Delete selected")); addPropertyBtn.OnClick += () => { Action openPropertyWindow = () => { Vector2I windowPos = ScreenToWindowPos(Input.PointerPosition); FieldSelectionWindow fieldSelection = DropDownWindow.Open <FieldSelectionWindow>(this, windowPos); fieldSelection.OnFieldSelected += OnFieldAdded; }; if (clipInfo.clip == null) { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("Selected object doesn't have an animation clip assigned. Would you like to create" + " a new animation clip?"); DialogBox.Open(title, message, DialogBox.Type.YesNoCancel, type => { if (type == DialogBox.ResultType.Yes) { string clipSavePath; if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.asset", out clipSavePath)) { clipSavePath = Path.ChangeExtension(clipSavePath, ".asset"); AnimationClip newClip = new AnimationClip(); ProjectLibrary.Create(newClip, clipSavePath); LoadAnimClip(newClip); Animation animation = selectedSO.GetComponent <Animation>(); if (animation == null) { animation = selectedSO.AddComponent <Animation>(); } animation.DefaultClip = newClip; EditorApplication.SetSceneDirty(); openPropertyWindow(); } } }); } else { if (clipInfo.isImported) { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("You cannot add/edit/remove curves from animation clips that" + " are imported from an external file."); DialogBox.Open(title, message, DialogBox.Type.OK); } else { openPropertyWindow(); } } }; delPropertyBtn.OnClick += () => { if (clipInfo.clip == null) { return; } if (clipInfo.isImported) { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("You cannot add/edit/remove curves from animation clips that" + " are imported from an external file."); DialogBox.Open(title, message, DialogBox.Type.OK); } else { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("Are you sure you want to remove all selected fields?"); DialogBox.Open(title, message, DialogBox.Type.YesNo, x => { if (x == DialogBox.ResultType.Yes) { RemoveSelectedFields(); } }); } }; GUIPanel mainPanel = GUI.AddPanel(); GUIPanel backgroundPanel = GUI.AddPanel(1); GUILayout mainLayout = mainPanel.AddLayoutY(); buttonLayout = mainLayout.AddLayoutX(); buttonLayout.AddSpace(5); buttonLayout.AddElement(playButton); buttonLayout.AddElement(recordButton); buttonLayout.AddSpace(5); buttonLayout.AddElement(prevFrameButton); buttonLayout.AddElement(frameInputField); buttonLayout.AddElement(nextFrameButton); buttonLayout.AddSpace(5); buttonLayout.AddElement(addKeyframeButton); buttonLayout.AddElement(addEventButton); buttonLayout.AddSpace(5); buttonLayout.AddElement(optionsButton); buttonLayout.AddFlexibleSpace(); buttonLayoutHeight = playButton.Bounds.height; GUITexture buttonBackground = new GUITexture(null, EditorStyles.HeaderBackground); buttonBackground.Bounds = new Rect2I(0, 0, Width, buttonLayoutHeight); backgroundPanel.AddElement(buttonBackground); GUILayout contentLayout = mainLayout.AddLayoutX(); GUILayout fieldDisplayLayout = contentLayout.AddLayoutY(GUIOption.FixedWidth(FIELD_DISPLAY_WIDTH)); guiFieldDisplay = new GUIAnimFieldDisplay(fieldDisplayLayout, FIELD_DISPLAY_WIDTH, Height - buttonLayoutHeight * 2, selectedSO); guiFieldDisplay.OnEntrySelected += OnFieldSelected; GUILayout bottomButtonLayout = fieldDisplayLayout.AddLayoutX(); bottomButtonLayout.AddElement(addPropertyBtn); bottomButtonLayout.AddElement(delPropertyBtn); horzScrollBar = new GUIResizeableScrollBarH(); horzScrollBar.OnScrollOrResize += OnHorzScrollOrResize; vertScrollBar = new GUIResizeableScrollBarV(); vertScrollBar.OnScrollOrResize += OnVertScrollOrResize; GUITexture separator = new GUITexture(null, EditorStyles.Separator, GUIOption.FixedWidth(3)); contentLayout.AddElement(separator); GUILayout curveLayout = contentLayout.AddLayoutY(); GUILayout curveLayoutHorz = curveLayout.AddLayoutX(); GUILayout horzScrollBarLayout = curveLayout.AddLayoutX(); horzScrollBarLayout.AddElement(horzScrollBar); horzScrollBarLayout.AddFlexibleSpace(); editorPanel = curveLayoutHorz.AddPanel(); curveLayoutHorz.AddElement(vertScrollBar); curveLayoutHorz.AddFlexibleSpace(); scrollBarHeight = horzScrollBar.Bounds.height; scrollBarWidth = vertScrollBar.Bounds.width; Vector2I curveEditorSize = GetCurveEditorSize(); guiCurveEditor = new GUICurveEditor(this, editorPanel, curveEditorSize.x, curveEditorSize.y); guiCurveEditor.OnFrameSelected += OnFrameSelected; guiCurveEditor.OnEventAdded += OnEventsChanged; guiCurveEditor.OnEventModified += EditorApplication.SetProjectDirty; guiCurveEditor.OnEventDeleted += OnEventsChanged; guiCurveEditor.OnCurveModified += EditorApplication.SetProjectDirty; guiCurveEditor.Redraw(); horzScrollBar.SetWidth(curveEditorSize.x); vertScrollBar.SetHeight(curveEditorSize.y); UpdateScrollBarSize(); }
/// <summary> /// Creates a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of 4D vector 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 MaterialParamVec4GUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.Name); guiElem = new GUIVector4Field(title); guiElem.OnChanged += (x) => { material.SetVector4(shaderParam.Name, x); EditorApplication.SetDirty(material); }; layout.AddElement(guiElem); }
/// <summary> /// Creates a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of texture 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 MaterialParamTextureGUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.Name); guiElem = new GUITextureField(title); switch (shaderParam.Type) { case ShaderParameterType.Texture2D: guiElem.OnChanged += (x) => { Texture2D texture = Resources.Load<Texture2D>(x); material.SetTexture2D(shaderParam.Name, texture); EditorApplication.SetDirty(material); }; break; case ShaderParameterType.Texture3D: guiElem.OnChanged += (x) => { Texture3D texture = Resources.Load<Texture3D>(x); material.SetTexture3D(shaderParam.Name, texture); EditorApplication.SetDirty(material); }; break; case ShaderParameterType.TextureCube: guiElem.OnChanged += (x) => { TextureCube texture = Resources.Load<TextureCube>(x); material.SetTextureCube(shaderParam.Name, texture); EditorApplication.SetDirty(material); }; break; } layout.AddElement(guiElem); }
/// <summary> /// Recreates all the GUI elements used by this inspector. /// </summary> private void BuildGUI() { Layout.Clear(); Animation animation = InspectedObject as Animation; if (animation == null) { return; } animationClipField.OnChanged += x => { AnimationClip clip = Resources.Load <AnimationClip>(x.UUID); animation.DefaultClip = clip; MarkAsModified(); ConfirmModify(); }; wrapModeField.OnSelectionChanged += x => { animation.WrapMode = (AnimWrapMode)x; MarkAsModified(); ConfirmModify(); }; speedField.OnChanged += x => { animation.Speed = x; MarkAsModified(); }; speedField.OnConfirmed += ConfirmModify; speedField.OnFocusLost += ConfirmModify; cullingField.OnChanged += x => { animation.Cull = x; MarkAsModified(); ConfirmModify(); }; overrideBoundsField.OnChanged += x => { animation.UseBounds = x; MarkAsModified(); ConfirmModify(); }; centerField.OnChanged += x => { AABox bounds = animation.Bounds; Vector3 min = x - bounds.Size * 0.5f; Vector3 max = x + bounds.Size * 0.5f; animation.Bounds = new AABox(min, max); MarkAsModified(); }; centerField.OnConfirmed += ConfirmModify; centerField.OnFocusLost += ConfirmModify; sizeField.OnChanged += x => { AABox bounds = animation.Bounds; Vector3 min = bounds.Center - x * 0.5f; Vector3 max = bounds.Center + x * 0.5f; animation.Bounds = new AABox(min, max); MarkAsModified(); }; sizeField.OnConfirmed += ConfirmModify; sizeField.OnFocusLost += ConfirmModify; Layout.AddElement(animationClipField); Layout.AddElement(wrapModeField); Layout.AddElement(speedField); Layout.AddElement(cullingField); Layout.AddElement(overrideBoundsField); GUILayoutX boundsLayout = Layout.AddLayoutX(); boundsLayout.AddElement(new GUILabel(new LocEdString("Bounds"), GUIOption.FixedWidth(100))); GUILayoutY boundsContent = boundsLayout.AddLayoutY(); boundsContent.AddElement(centerField); boundsContent.AddElement(sizeField); // Morph shapes Renderable renderable = animation.SceneObject.GetComponent <Renderable>(); MorphShapes morphShapes = renderable?.Mesh.Value?.MorphShapes; if (morphShapes != null) { GUIToggle morphShapesToggle = new GUIToggle(new LocEdString("Morph shapes"), EditorStyles.Foldout); Layout.AddElement(morphShapesToggle); GUILayoutY channelsLayout = Layout.AddLayoutY(); morphShapesToggle.OnToggled += x => { channelsLayout.Active = x; Persistent.SetBool("Channels_Expanded", x); }; channelsLayout.Active = Persistent.GetBool("Channels_Expanded"); MorphChannel[] channels = morphShapes.Channels; for (int i = 0; i < channels.Length; i++) { GUILayoutY channelLayout = channelsLayout.AddLayoutY(); GUILayoutX channelTitleLayout = channelLayout.AddLayoutX(); channelLayout.AddSpace(5); GUILayoutY channelContentLayout = channelLayout.AddLayoutY(); string channelName = channels[i].Name; GUIToggle channelNameField = new GUIToggle(channelName, EditorStyles.Expand, GUIOption.FlexibleWidth()); channelTitleLayout.AddSpace(15); // Indent channelTitleLayout.AddElement(channelNameField); channelTitleLayout.AddFlexibleSpace(); channelNameField.OnToggled += x => { channelContentLayout.Active = x; Persistent.SetBool(channelName + "_Expanded", x); }; channelContentLayout.Active = Persistent.GetBool(channelName + "_Expanded"); MorphShape[] shapes = channels[i].Shapes; for (int j = 0; j < shapes.Length; j++) { GUILayoutX shapeLayout = channelContentLayout.AddLayoutX(); channelContentLayout.AddSpace(5); LocString nameString = new LocString("[{0}]. {1}"); nameString.SetParameter(0, j.ToString()); nameString.SetParameter(1, shapes[j].Name); GUILabel shapeNameField = new GUILabel(shapes[j].Name); LocString weightString = new LocEdString("Weight: {0}"); weightString.SetParameter(0, shapes[j].Weight.ToString()); GUILabel weightField = new GUILabel(weightString); shapeLayout.AddSpace(30); // Indent shapeLayout.AddElement(shapeNameField); shapeLayout.AddFlexibleSpace(); shapeLayout.AddElement(weightField); } } } }
/// <summary> /// Updates the contents of the details panel according to the currently selected element. /// </summary> private void RefreshDetailsPanel() { detailsArea.Layout.Clear(); if (sSelectedElementIdx != -1) { GUILayoutX paddingX = detailsArea.Layout.AddLayoutX(); paddingX.AddSpace(5); GUILayoutY paddingY = paddingX.AddLayoutY(); paddingX.AddSpace(5); paddingY.AddSpace(5); GUILayoutY mainLayout = paddingY.AddLayoutY(); paddingY.AddSpace(5); ConsoleEntryData entry = filteredEntries[sSelectedElementIdx]; LocString message = new LocEdString(entry.message); GUILabel messageLabel = new GUILabel(message, EditorStyles.MultiLineLabel, GUIOption.FlexibleHeight()); mainLayout.AddElement(messageLabel); mainLayout.AddSpace(10); if (entry.callstack != null) { foreach (var call in entry.callstack) { string fileName = Path.GetFileName(call.file); string callMessage; if (string.IsNullOrEmpty(call.method)) { callMessage = "\tin " + fileName + ":" + call.line; } else { callMessage = "\t" + call.method + " in " + fileName + ":" + call.line; } GUIButton callBtn = new GUIButton(new LocEdString(callMessage)); mainLayout.AddElement(callBtn); CallStackEntry hoistedCall = call; callBtn.OnClick += () => { CodeEditor.OpenFile(hoistedCall.file, hoistedCall.line); }; } } mainLayout.AddFlexibleSpace(); } else { GUILayoutX centerX = detailsArea.Layout.AddLayoutX(); centerX.AddFlexibleSpace(); GUILayoutY centerY = centerX.AddLayoutY(); centerX.AddFlexibleSpace(); centerY.AddFlexibleSpace(); GUILabel nothingSelectedLbl = new GUILabel(new LocEdString("(No entry selected)")); centerY.AddElement(nothingSelectedLbl); centerY.AddFlexibleSpace(); } }
/// <summary> /// Shows a dialog box that notifies the user that the animation clip is read only. /// </summary> private void ShowReadOnlyMessage() { LocEdString title = new LocEdString("Warning"); LocEdString message = new LocEdString("You cannot edit keyframes on animation clips that" + " are imported from an external file."); DialogBox.Open(title, message, DialogBox.Type.OK); }