/// <summary> /// Triggered when the user drops a new resource onto the field, or clears the current value. /// </summary> /// <param name="newValue">New resource to reference.</param> private void OnFieldValueChanged(ResourceRef newValue) { Resource res = Resources.Load<Resource>(newValue); property.SetValue(res); state = InspectableState.Modified; }
/// <inheritdoc/> protected internal override InspectableState Refresh() { CharacterController controller = InspectedObject as CharacterController; if (controller == null) return InspectableState.NotModified; radiusField.Value = controller.Radius; heightField.Value = controller.Height; orientationField.Value = orientation; contactOffsetField.Value = controller.ContactOffset; minMoveDistanceField.Value = controller.MinMoveDistance; climbingModeField.Value = (ulong)controller.ClimbingMode; stepOffsetField.Value = controller.StepOffset; nonWalkableModeField.Value = (ulong)controller.NonWalkableMode; slopeLimitField.Value = controller.SlopeLimit.Degrees; if (layersValue != controller.Layer) { bool[] states = new bool[64]; for (int i = 0; i < states.Length; i++) states[i] = (controller.Layer & Layers.Values[i]) == Layers.Values[i]; layerField.States = states; layersValue = controller.Layer; } InspectableState oldState = modifyState; if (modifyState.HasFlag(InspectableState.Modified)) modifyState = InspectableState.NotModified; return oldState; }
/// <inheritdoc/> public override InspectableState Refresh(int layoutIndex) { if (guiFloatField != null && !guiFloatField.HasInputFocus) guiFloatField.Value = property.GetValue<float>(); InspectableState oldState = state; if (state.HasFlag(InspectableState.Modified)) state = InspectableState.NotModified; return oldState; }
/// <inheritdoc/> public override InspectableState Refresh(int layoutIndex) { if (guiField != null) guiField.Value = property.GetValue<Color>(); InspectableState oldState = state; if (state.HasFlag(InspectableState.Modified)) state = InspectableState.NotModified; return oldState; }
/// <inheritdoc/> protected internal override InspectableState Refresh() { GUIWidget guiWidget = InspectedObject as GUIWidget; if (guiWidget == null) return InspectableState.NotModified; skinField.Value = guiWidget.Skin; cameraField.Value = guiWidget.Camera; InspectableState oldState = modifyState; if (modifyState.HasFlag(InspectableState.Modified)) modifyState = InspectableState.NotModified; return oldState; }
/// <summary> /// Triggered when the user toggles the toggle button. /// </summary> /// <param name="newValue">New value of the toggle button.</param> private void OnFieldValueChanged(bool newValue) { property.SetValue(newValue); state = InspectableState.Modified; }
/// <summary> /// Triggered when the user updates the curve. /// </summary> /// <param name="newValue">New curve.</param> private void OnFieldValueChanged(AnimationCurve newValue) { property.SetValue(newValue); state = InspectableState.Modified; }
/// <summary> /// Marks the contents of the inspector as modified. /// </summary> protected void MarkAsModified() { modifyState |= InspectableState.ModifyInProgress; }
/// <summary> /// Triggered when the scene object modification is confirmed by the user. /// </summary> private void OnModifyConfirm() { if (modifyState.HasFlag(InspectableState.ModifyInProgress)) modifyState = InspectableState.Modified; }
/// <summary> /// Triggered when the user inputs a new floating point value. /// </summary> /// <param name="newValue">New value of the float field.</param> private void OnFieldValueChanged(float newValue) { property.SetValue(newValue); state |= InspectableState.ModifyInProgress; }
/// <inheritdoc/> protected internal override InspectableState Refresh() { Renderable renderable = InspectedObject as Renderable; if (renderable == null) { return(InspectableState.NotModified); } bool rebuildMaterialsGUI = false; Material[] newMaterials = renderable.Materials; if (newMaterials == null) { rebuildMaterialsGUI = materials != null; } else { if (materials == null) { rebuildMaterialsGUI = true; } else { if (materials.Length != newMaterials.Length) { rebuildMaterialsGUI = true; } else { for (int i = 0; i < materials.Length; i++) { if (materials[i] != newMaterials[i]) { rebuildMaterialsGUI = true; break; } } } } } if (rebuildMaterialsGUI) { BuildMaterialsGUI(); } meshField.Value = renderable.Mesh; if (layersValue != renderable.Layers) { bool[] states = new bool[64]; for (int i = 0; i < states.Length; i++) { states[i] = (renderable.Layers & Layers.Values[i]) == Layers.Values[i]; } layersField.States = states; layersValue = renderable.Layers; } InspectableState materialsModified = materialsField.Refresh(); if (materialsModified == InspectableState.Modified) { renderable.Materials = materials; } modifyState |= materialsModified; if (materials != null) { for (int i = 0; i < materialParams.Count; i++) { if (materialParams[i] != null) { foreach (var param in materialParams[i]) { param.Refresh(materials[i]); } } } } InspectableState oldState = modifyState; if (modifyState.HasFlag(InspectableState.Modified)) { modifyState = InspectableState.NotModified; } return(oldState); }
/// <summary> /// Triggered when the user edits the distribution. /// </summary> private void OnFieldValueChanged() { property.SetValue(guiDistributionField.Value); state |= InspectableState.ModifyInProgress; }
/// <summary> /// Triggered when the user changes the name of the currently active scene object. /// </summary> private void OnSceneObjectRename(string name) { if (activeSO != null) { activeSO.Name = name; modifyState |= InspectableState.ModifyInProgress; EditorApplication.SetSceneDirty(); } }
/// <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.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.TopCommandId; SetObjectToInspect(objects[0]); } } else if (paths.Length == 1) { SetObjectToInspect(paths[0]); } }
/// <summary> /// Triggered when the scale value in the currently active <see cref="SceneObject"/> changes. Updates the /// necessary GUI elements. /// </summary> /// <param name="idx">Index of the coordinate that was changed.</param> /// <param name="value">New value of the field.</param> private void OnScaleChanged(int idx, float value) { if (activeSO == null) return; Vector3 scale = activeSO.LocalScale; scale[idx] = value; activeSO.LocalScale = scale; modifyState = InspectableState.ModifyInProgress; EditorApplication.SetSceneDirty(); }
/// <summary> /// Triggered when the rotation value in the currently active <see cref="SceneObject"/> changes. Updates the /// necessary GUI elements. /// </summary> /// <param name="idx">Index of the euler angle that was changed (0 - X, 1 - Y, 2 - Z).</param> /// <param name="value">New value of the field.</param> private void OnRotationChanged(int idx, float value) { if (activeSO == null) return; if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World) { Vector3 angles = activeSO.Rotation.ToEuler(); angles[idx] = value; activeSO.Rotation = Quaternion.FromEuler(angles); } else { Vector3 angles = activeSO.LocalRotation.ToEuler(); angles[idx] = value; activeSO.LocalRotation = Quaternion.FromEuler(angles); } modifyState = InspectableState.ModifyInProgress; EditorApplication.SetSceneDirty(); }
/// <summary> /// Triggered when the position value in the currently active <see cref="SceneObject"/> changes. Updates the /// necessary GUI elements. /// </summary> /// <param name="idx">Index of the coordinate that was changed.</param> /// <param name="value">New value of the field.</param> private void OnPositionChanged(int idx, float value) { if (activeSO == null) return; if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World) { Vector3 position = activeSO.Position; position[idx] = value; activeSO.Position = position; } else { Vector3 position = activeSO.LocalPosition; position[idx] = value; activeSO.LocalPosition = position; } modifyState = InspectableState.ModifyInProgress; EditorApplication.SetSceneDirty(); }
/// <summary> /// Triggered when the user clicks the component remove button. Removes that component from the active scene object. /// </summary> /// <param name="componentType">Type of the component to remove.</param> private void OnComponentRemoveClicked(Type componentType) { if (activeSO != null) { activeSO.RemoveComponent(componentType); modifyState = InspectableState.Modified; EditorApplication.SetSceneDirty(); } }
/// <inheritoc/> protected internal override void Initialize(int layoutIndex) { GUILayoutX boundsLayout = new GUILayoutX(); centerField = new GUIVector3Field(new LocEdString("Center"), 50); sizeField = new GUIVector3Field(new LocEdString("Size"), 50); layout.AddElement(layoutIndex, boundsLayout); boundsLayout.AddElement(new GUILabel(new LocEdString(title), GUIOption.FixedWidth(100))); GUILayoutY boundsContent = boundsLayout.AddLayoutY(); boundsContent.AddElement(centerField); boundsContent.AddElement(sizeField); centerField.OnValueChanged += x => { AABox bounds = property.GetValue <AABox>(); Vector3 min = x - bounds.Size * 0.5f; Vector3 max = x + bounds.Size * 0.5f; property.SetValue(new AABox(min, max)); state |= InspectableState.ModifyInProgress; }; centerField.OnConfirm += x => { OnFieldValueConfirm(); StartUndo("center." + x.ToString()); }; centerField.OnComponentFocusChanged += (focus, comp) => { if (focus) { StartUndo("center." + comp.ToString()); } else { OnFieldValueConfirm(); } }; sizeField.OnValueChanged += x => { AABox bounds = property.GetValue <AABox>(); Vector3 min = bounds.Center - x * 0.5f; Vector3 max = bounds.Center + x * 0.5f; property.SetValue(new AABox(min, max)); state |= InspectableState.ModifyInProgress; }; sizeField.OnConfirm += x => { OnFieldValueConfirm(); StartUndo("size." + x.ToString()); }; sizeField.OnComponentFocusChanged += (focus, comp) => { if (focus) { StartUndo("size." + comp.ToString()); } else { OnFieldValueConfirm(); } }; }
/// <summary> /// Triggered when the user inputs a new string. /// </summary> /// <param name="newValue">New value of the text field.</param> private void OnFieldValueChanged(string newValue) { property.SetValue(newValue); state |= InspectableState.ModifyInProgress; }
/// <inheritdoc/> protected internal override InspectableState Refresh() { Camera camera = InspectedObject as Camera; if (camera == null) return InspectableState.NotModified; ProjectionType projType = camera.ProjectionType; if (projectionTypeField.Value != (ulong)projType) { projectionTypeField.Value = (ulong)projType; ToggleTypeSpecificFields(projType); } fieldOfView.Value = camera.FieldOfView.Degrees; orthoHeight.Value = camera.OrthoHeight; aspectField.Value = camera.AspectRatio; nearPlaneField.Value = camera.NearClipPlane; farPlaneField.Value = camera.FarClipPlane; viewportXField.Value = camera.ViewportRect.x; viewportYField.Value = camera.ViewportRect.y; viewportWidthField.Value = camera.ViewportRect.width; viewportHeightField.Value = camera.ViewportRect.height; clearFlagsFields.Value = (ulong)camera.ClearFlags; clearStencilField.Value = camera.ClearStencil; clearDepthField.Value = camera.ClearDepth; clearColorField.Value = camera.ClearColor; priorityField.Value = camera.Priority; mainField.Value = camera.Main; hdrField.Value = camera.HDR; skyboxField.Value = camera.Skybox; postProcessGUI.Settings = camera.PostProcess; if (layersValue != camera.Layers) { bool[] states = new bool[64]; for (int i = 0; i < states.Length; i++) states[i] = (camera.Layers & Layers.Values[i]) == Layers.Values[i]; layersField.States = states; layersValue = camera.Layers; } InspectableState oldState = modifyState; if (modifyState.HasFlag(InspectableState.Modified)) modifyState = InspectableState.NotModified; return oldState; }
/// <summary> /// Updates all GUI elements from the style if style changes. /// </summary> /// <param name="style">Style to display in the GUI.</param> /// <returns>State representing was anything modified between two last calls to <see cref="Refresh"/>.</returns> public InspectableState Refresh(GUIElementStyle style) { this.style = style; InspectableState oldModifiedState = modifiedState; if (modifiedState.HasFlag(InspectableState.Modified)) modifiedState = InspectableState.NotModified; if (style == null) return oldModifiedState; fontField.Value = style.Font; fontSizeField.Value = style.FontSize; horzAlignField.Value = (ulong)style.TextHorzAlign; vertAlignField.Value = (ulong)style.TextVertAlign; imagePositionField.Value = (ulong)style.ImagePosition; wordWrapField.Value = style.WordWrap; normalGUI.Refresh(style.Normal); hoverGUI.Refresh(style.Hover); activeGUI.Refresh(style.Active); focusedGUI.Refresh(style.Focused); normalOnGUI.Refresh(style.NormalOn); hoverOnGUI.Refresh(style.HoverOn); activeOnGUI.Refresh(style.ActiveOn); focusedOnGUI.Refresh(style.FocusedOn); borderGUI.Refresh(style.Border); marginsGUI.Refresh(style.Margins); contentOffsetGUI.Refresh(style.ContentOffset); fixedWidthField.Value = style.FixedWidth; widthField.Value = style.Width; minWidthField.Value = style.MinWidth; maxWidthField.Value = style.MaxWidth; fixedHeightField.Value = style.FixedHeight; heightField.Value = style.Height; minHeightField.Value = style.MinHeight; maxHeightField.Value = style.MaxHeight; widthField.Active = style.FixedWidth; minWidthField.Active = !style.FixedWidth; maxWidthField.Active = !style.FixedWidth; heightField.Active = style.FixedHeight; minHeightField.Active = !style.FixedHeight; maxHeightField.Active = !style.FixedHeight; return oldModifiedState; }
/// <inheritdoc/> protected internal override InspectableState Refresh() { Renderable renderable = InspectedObject as Renderable; if (renderable == null) return InspectableState.NotModified; bool rebuildMaterialsGUI = false; Material[] newMaterials = renderable.Materials; if (newMaterials == null) rebuildMaterialsGUI = materials != null; else { if (materials == null) rebuildMaterialsGUI = true; else { if (materials.Length != newMaterials.Length) rebuildMaterialsGUI = true; else { for (int i = 0; i < materials.Length; i++) { if (materials[i] != newMaterials[i]) { rebuildMaterialsGUI = true; break; } } } } } if (rebuildMaterialsGUI) BuildMaterialsGUI(); meshField.Value = renderable.Mesh; if (layersValue != renderable.Layers) { bool[] states = new bool[64]; for (int i = 0; i < states.Length; i++) states[i] = (renderable.Layers & Layers.Values[i]) == Layers.Values[i]; layersField.States = states; layersValue = renderable.Layers; } InspectableState materialsModified = materialsField.Refresh(); if (materialsModified == InspectableState.Modified) renderable.Materials = materials; modifyState |= materialsModified; if (materials != null) { for (int i = 0; i < materialParams.Count; i++) { if (materialParams[i] != null) { foreach (var param in materialParams[i]) param.Refresh(materials[i]); } } } InspectableState oldState = modifyState; if (modifyState.HasFlag(InspectableState.Modified)) modifyState = InspectableState.NotModified; return oldState; }
private void OnEditorUpdate() { if (currentType == InspectorType.SceneObject) { Component[] allComponents = activeSO.GetComponents(); bool requiresRebuild = allComponents.Length != inspectorComponents.Count; if (!requiresRebuild) { for (int i = 0; i < inspectorComponents.Count; i++) { if (inspectorComponents[i].instanceId != allComponents[i].InstanceId) { requiresRebuild = true; break; } } } if (requiresRebuild) { SceneObject so = activeSO; Clear(); SetObjectToInspect(so); } else { RefreshSceneObjectFields(false); InspectableState componentModifyState = InspectableState.NotModified; for (int i = 0; i < inspectorComponents.Count; i++) componentModifyState |= inspectorComponents[i].inspector.Refresh(); if (componentModifyState.HasFlag(InspectableState.ModifyInProgress)) EditorApplication.SetSceneDirty(); modifyState |= componentModifyState; } } else if (currentType == InspectorType.Resource) { inspectorResource.inspector.Refresh(); } // Detect drag and drop bool isValidDrag = false; if (activeSO != null) { if ((DragDrop.DragInProgress || DragDrop.DropInProgress) && DragDrop.Type == DragDropType.Resource) { Vector2I windowPos = ScreenToWindowPos(Input.PointerPosition); Vector2I scrollPos = windowPos; Rect2I contentBounds = inspectorLayout.Bounds; scrollPos.x -= contentBounds.x; scrollPos.y -= contentBounds.y; bool isInBounds = false; Rect2I dropArea = new Rect2I(); foreach (var bounds in dropAreas) { if (bounds.Contains(scrollPos)) { isInBounds = true; dropArea = bounds; break; } } Type draggedComponentType = null; if (isInBounds) { ResourceDragDropData dragData = DragDrop.Data as ResourceDragDropData; if (dragData != null) { foreach (var resPath in dragData.Paths) { ResourceMeta meta = ProjectLibrary.GetMeta(resPath); if (meta != null) { if (meta.ResType == ResourceType.ScriptCode) { ScriptCode scriptFile = ProjectLibrary.Load<ScriptCode>(resPath); if (scriptFile != null) { Type[] scriptTypes = scriptFile.Types; foreach (var type in scriptTypes) { if (type.IsSubclassOf(typeof (Component))) { draggedComponentType = type; isValidDrag = true; break; } } if (draggedComponentType != null) break; } } } } } } if (isValidDrag) { scrollAreaHighlight.Bounds = dropArea; if (DragDrop.DropInProgress) { activeSO.AddComponent(draggedComponentType); modifyState = InspectableState.Modified; EditorApplication.SetSceneDirty(); } } } } if (scrollAreaHighlight != null) scrollAreaHighlight.Active = isValidDrag; }
/// <summary> /// Marks the contents of the style as modified. /// </summary> private void MarkAsModified() { modifiedState |= InspectableState.ModifyInProgress; }
/// <summary> /// Triggered when the user updates the color gradient. /// </summary> /// <param name="newValue">New value of the gradient field.</param> private void OnFieldValueChanged(ColorGradient newValue) { property.SetValue(newValue); state = InspectableState.Modified; }
/// <summary> /// Triggered when the user confirms input in the text field. /// </summary> private void OnFieldValueConfirm() { if (state.HasFlag(InspectableState.ModifyInProgress)) state |= InspectableState.Modified; }
/// <summary> /// Triggered when the user changes the field value of a single component. /// </summary> /// <param name="newValue">New value of a single component in the 3D vector field.</param> /// <param name="component">Component that was changed.</param> private void OnFieldValueChanged(float newValue, VectorComponent component) { property.SetValue(guiField.Value); state |= InspectableState.ModifyInProgress; }
/// <summary> /// Confirms any queued modifications. /// </summary> protected void ConfirmModify() { if (modifyState.HasFlag(InspectableState.ModifyInProgress)) modifyState |= InspectableState.Modified; }
/// <summary> /// Triggered when the user selects a new color. /// </summary> /// <param name="newValue">New value of the color field.</param> private void OnFieldValueChanged(Color newValue) { property.SetValue(newValue); state = InspectableState.Modified; }
/// <inheritdoc/> protected internal override InspectableState Refresh() { Light light = InspectedObject as Light; if (light == null) return InspectableState.NotModified; LightType lightType = light.Type; if (lightTypeField.Value != (ulong)lightType || physBasedAttenField.Value != light.PhysicallyBasedAttenuation) ToggleTypeSpecificFields(lightType, light.PhysicallyBasedAttenuation); lightTypeField.Value = (ulong)lightType; colorField.Value = light.Color; intensityField.Value = light.Intensity; rangeField.Value = light.Range; spotAngleField.Value = light.SpotAngle.Degrees; spotFalloffAngleField.Value = light.SpotFalloffAngle.Degrees; physBasedAttenField.Value = light.PhysicallyBasedAttenuation; castShadowField.Value = light.CastsShadow; InspectableState oldState = modifyState; if (modifyState.HasFlag(InspectableState.Modified)) modifyState = InspectableState.NotModified; return oldState; }