/// <summary> /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before /// use. /// </summary> /// <param name="parent">Scene window that this drop down window is a part of.</param> /// <param name="cameraOptions">Reference to the current scene camera options.</param> internal void Initialize(SceneWindow parent) { this.Parent = parent; GUIEnumField cameraProjectionTypeField = new GUIEnumField(typeof(ProjectionType), new LocEdString("Projection type")); cameraProjectionTypeField.Value = (ulong)Parent.ProjectionType; cameraProjectionTypeField.OnSelectionChanged += SetCameraProjectionType; nearClipPlaneInput = new GUIFloatField(new LocEdString("Near plane")); nearClipPlaneInput.Value = Parent.NearClipPlane; nearClipPlaneInput.OnChanged += OnNearClipPlaneChanged; nearClipPlaneInput.SetRange(SceneCameraOptions.MinNearClipPlane, SceneCameraOptions.MaxNearClipPlane); farClipPlaneInput = new GUIFloatField(new LocEdString("Far plane")); farClipPlaneInput.Value = Parent.FarClipPlane; farClipPlaneInput.OnChanged += OnFarClipPlaneChanged; farClipPlaneInput.SetRange(SceneCameraOptions.MinFarClipPlane, SceneCameraOptions.MaxFarClipPlane); cameraFieldOfView = new GUISliderField(1, 360, new LocEdString("Field of view")); cameraFieldOfView.Value = Parent.FieldOfView.Degrees; cameraFieldOfView.OnChanged += SetFieldOfView; cameraOrthographicSize = new GUIFloatField(new LocEdString("Orthographic size")); cameraOrthographicSize.Value = Parent.OrthographicSize; cameraOrthographicSize.OnChanged += SetOrthographicSize; GUISliderField cameraScrollSpeed = new GUISliderField(SceneCameraOptions.MinScrollSpeed, SceneCameraOptions.MaxScrollSpeed, new LocEdString("Scroll speed")); cameraScrollSpeed.Value = Parent.ScrollSpeed; cameraScrollSpeed.OnChanged += SetScrollSpeed; GUILayoutY vertLayout = GUI.AddLayoutY(); vertLayout.AddSpace(10); GUILayoutX cameraOptionsLayoutX = vertLayout.AddLayoutX(); cameraOptionsLayoutX.AddSpace(10); GUILayoutY cameraOptionsLayoutY = cameraOptionsLayoutX.AddLayoutY(); cameraOptionsLayoutY.AddElement(cameraProjectionTypeField); cameraOptionsLayoutY.AddElement(nearClipPlaneInput); cameraOptionsLayoutY.AddElement(farClipPlaneInput); cameraOptionsLayoutY.AddElement(cameraFieldOfView); cameraOptionsLayoutY.AddElement(cameraOrthographicSize); cameraOptionsLayoutY.AddElement(cameraScrollSpeed); cameraOptionsLayoutX.AddSpace(10); vertLayout.AddSpace(10); ToggleTypeSpecificFields((ProjectionType)cameraProjectionTypeField.Value); }
/// <inheritoc/> protected internal override void Initialize(int layoutIndex) { if (property != null) { guiFloatField = new GUISliderField(style.RangeStyle.Min, style.RangeStyle.Max, new GUIContent(title)); if (style != null && style.StepStyle != null && style.StepStyle.Step != 0) { guiFloatField.Step = style.StepStyle.Step; } guiFloatField.OnChanged += OnFieldValueChanged; guiFloatField.OnFocusLost += OnFieldValueConfirm; layout.AddElement(layoutIndex, guiFloatField); } }
/// <inheritoc/> protected internal override void Initialize(int layoutIndex) { if (property != null) { bool isSlider = style?.RangeStyle != null && style.RangeStyle.Slider; if (isSlider) { guiSliderField = new GUISliderField(style.RangeStyle.Min, style.RangeStyle.Max, new GUIContent(title)); if (style.StepStyle != null && style.StepStyle.Step != 0) { guiSliderField.Step = style.StepStyle.Step; } guiSliderField.OnChanged += OnFieldValueChanged; guiSliderField.OnFocusLost += OnFieldValueConfirm; guiSliderField.OnFocusGained += StartUndo; layout.AddElement(layoutIndex, guiSliderField); } else { guiFloatField = new GUIFloatField(new GUIContent(title)); if (style != null) { if (style.StepStyle != null && style.StepStyle.Step != 0) { guiFloatField.Step = style.StepStyle.Step; } if (style.RangeStyle != null) { guiFloatField.SetRange(style.RangeStyle.Min, style.RangeStyle.Max); } } guiFloatField.OnChanged += OnFieldValueChanged; guiFloatField.OnConfirmed += () => { OnFieldValueConfirm(); StartUndo(); }; guiFloatField.OnFocusLost += OnFieldValueConfirm; guiFloatField.OnFocusGained += StartUndo; layout.AddElement(layoutIndex, guiFloatField); } } }
/// <summary> /// Recreates all the GUI elements used by this inspector. /// </summary> private void BuildGUI() { Layout.Clear(); PhysicsMaterial material = InspectedObject as PhysicsMaterial; if (material == null) { return; } staticFrictionField = new GUIFloatField(new LocEdString("Static friction")); dynamicFrictionField = new GUIFloatField(new LocEdString("Dynamic friction")); restitutionField = new GUISliderField(0.0f, 1.0f, new LocEdString("Restitution")); staticFrictionField.OnChanged += x => { material.StaticFriction = x; EditorApplication.SetDirty(material); }; dynamicFrictionField.OnChanged += x => { material.DynamicFriction = x; EditorApplication.SetDirty(material); }; restitutionField.OnChanged += x => { material.Restitution = x; EditorApplication.SetDirty(material); }; Layout.AddElement(staticFrictionField); Layout.AddElement(dynamicFrictionField); Layout.AddElement(restitutionField); }
private static extern void Internal_CreateInstance(GUISliderField instance, float min, float max, ref GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle);
private void OnInitialize() { GUIToggle projectFoldout = new GUIToggle(new LocEdString("Project"), EditorStyles.Foldout); GUIToggle editorFoldout = new GUIToggle(new LocEdString("Editor"), EditorStyles.Foldout); projectFoldout.AcceptsKeyFocus = false; editorFoldout.AcceptsKeyFocus = false; 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; }