diff --git a/Source/Editor/Gizmo/GizmosCollection.cs b/Source/Editor/Gizmo/GizmosCollection.cs
index b77d22e84..0f69c0756 100644
--- a/Source/Editor/Gizmo/GizmosCollection.cs
+++ b/Source/Editor/Gizmo/GizmosCollection.cs
@@ -161,5 +161,20 @@ namespace FlaxEditor.Gizmo
}
throw new ArgumentException("Not added mode to activate.");
}
+
+ ///
+ /// Gets the gizmo of a given type or returns null if not added.
+ ///
+ /// Type of the gizmo.
+ /// Found gizmo or null.
+ public T Get() where T : GizmoBase
+ {
+ foreach (var e in this)
+ {
+ if (e is T asT)
+ return asT;
+ }
+ return null;
+ }
}
}
diff --git a/Source/Editor/Viewport/EditorGizmoViewport.cs b/Source/Editor/Viewport/EditorGizmoViewport.cs
index 8f038ce17..f1c4fed70 100644
--- a/Source/Editor/Viewport/EditorGizmoViewport.cs
+++ b/Source/Editor/Viewport/EditorGizmoViewport.cs
@@ -41,6 +41,7 @@ namespace FlaxEditor.Viewport
Gizmos[i].Update(deltaTime);
}
}
+
///
public EditorViewport Viewport => this;
@@ -121,5 +122,41 @@ namespace FlaxEditor.Viewport
base.OnDestroy();
}
+
+ internal static readonly float[] TranslateSnapValues =
+ {
+ 0.1f,
+ 0.5f,
+ 1.0f,
+ 5.0f,
+ 10.0f,
+ 100.0f,
+ 1000.0f,
+ };
+
+ internal static readonly float[] RotateSnapValues =
+ {
+ 1.0f,
+ 5.0f,
+ 10.0f,
+ 15.0f,
+ 30.0f,
+ 45.0f,
+ 60.0f,
+ 90.0f,
+ };
+
+ internal static readonly float[] ScaleSnapValues =
+ {
+ 0.05f,
+ 0.1f,
+ 0.25f,
+ 0.5f,
+ 1.0f,
+ 2.0f,
+ 4.0f,
+ 6.0f,
+ 8.0f,
+ };
}
}
diff --git a/Source/Editor/Viewport/MainEditorGizmoViewport.cs b/Source/Editor/Viewport/MainEditorGizmoViewport.cs
index 541bbcfba..1e63888bf 100644
--- a/Source/Editor/Viewport/MainEditorGizmoViewport.cs
+++ b/Source/Editor/Viewport/MainEditorGizmoViewport.cs
@@ -268,16 +268,14 @@ namespace FlaxEditor.Viewport
Parent = scaleSnappingWidget
};
enableScaleSnapping.Toggled += OnScaleSnappingToggle;
-
var scaleSnappingCM = new ContextMenu();
_scaleSnapping = new ViewportWidgetButton(TransformGizmo.ScaleSnapValue.ToString(), SpriteHandle.Invalid, scaleSnappingCM)
{
TooltipText = "Scale snapping values"
};
-
- for (int i = 0; i < EditorViewportScaleSnapValues.Length; i++)
+ for (int i = 0; i < ScaleSnapValues.Length; i++)
{
- var v = EditorViewportScaleSnapValues[i];
+ var v = ScaleSnapValues[i];
var button = scaleSnappingCM.AddButton(v.ToString());
button.Tag = v;
}
@@ -295,16 +293,14 @@ namespace FlaxEditor.Viewport
Parent = rotateSnappingWidget
};
enableRotateSnapping.Toggled += OnRotateSnappingToggle;
-
var rotateSnappingCM = new ContextMenu();
_rotateSnapping = new ViewportWidgetButton(TransformGizmo.RotationSnapValue.ToString(), SpriteHandle.Invalid, rotateSnappingCM)
{
TooltipText = "Rotation snapping values"
};
-
- for (int i = 0; i < EditorViewportRotateSnapValues.Length; i++)
+ for (int i = 0; i < RotateSnapValues.Length; i++)
{
- var v = EditorViewportRotateSnapValues[i];
+ var v = RotateSnapValues[i];
var button = rotateSnappingCM.AddButton(v.ToString());
button.Tag = v;
}
@@ -322,7 +318,6 @@ namespace FlaxEditor.Viewport
Parent = translateSnappingWidget
};
enableTranslateSnapping.Toggled += OnTranslateSnappingToggle;
-
var translateSnappingCM = new ContextMenu();
_translateSnapping = new ViewportWidgetButton(TransformGizmo.TranslationSnapValue.ToString(), SpriteHandle.Invalid, translateSnappingCM)
{
@@ -330,16 +325,14 @@ namespace FlaxEditor.Viewport
};
if (TransformGizmo.TranslationSnapValue < 0.0f)
_translateSnapping.Text = "Bounding Box";
-
- for (int i = 0; i < EditorViewportTranslateSnapValues.Length; i++)
+ for (int i = 0; i < TranslateSnapValues.Length; i++)
{
- var v = EditorViewportTranslateSnapValues[i];
+ var v = TranslateSnapValues[i];
var button = translateSnappingCM.AddButton(v.ToString());
button.Tag = v;
}
var buttonBB = translateSnappingCM.AddButton("Bounding Box").LinkTooltip("Snaps the selection based on it's bounding volume");
buttonBB.Tag = -1.0f;
-
translateSnappingCM.ButtonClicked += OnWidgetTranslateSnapClick;
translateSnappingCM.VisibleChanged += OnWidgetTranslateSnapShowHide;
_translateSnapping.Parent = translateSnappingWidget;
@@ -552,7 +545,7 @@ namespace FlaxEditor.Viewport
var task = renderContext.Task;
// Render editor primitives, gizmo and debug shapes in debug view modes
- // Note: can use Output buffer as both input and output because EditorPrimitives is using a intermediate buffers
+ // Note: can use Output buffer as both input and output because EditorPrimitives is using an intermediate buffer
if (EditorPrimitives && EditorPrimitives.CanRender())
{
EditorPrimitives.Render(context, ref renderContext, task.Output, task.Output);
@@ -619,19 +612,6 @@ namespace FlaxEditor.Viewport
_gizmoModeScale.Checked = mode == TransformGizmoBase.Mode.Scale;
}
- private static readonly float[] EditorViewportScaleSnapValues =
- {
- 0.05f,
- 0.1f,
- 0.25f,
- 0.5f,
- 1.0f,
- 2.0f,
- 4.0f,
- 6.0f,
- 8.0f,
- };
-
private void OnWidgetScaleSnapClick(ContextMenuButton button)
{
var v = (float)button.Tag;
@@ -651,25 +631,11 @@ namespace FlaxEditor.Viewport
if (e is ContextMenuButton b)
{
var v = (float)b.Tag;
- b.Icon = Mathf.Abs(TransformGizmo.ScaleSnapValue - v) < 0.001f
- ? Style.Current.CheckBoxTick
- : SpriteHandle.Invalid;
+ b.Icon = Mathf.Abs(TransformGizmo.ScaleSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
}
}
}
- private static readonly float[] EditorViewportRotateSnapValues =
- {
- 1.0f,
- 5.0f,
- 10.0f,
- 15.0f,
- 30.0f,
- 45.0f,
- 60.0f,
- 90.0f,
- };
-
private void OnWidgetRotateSnapClick(ContextMenuButton button)
{
var v = (float)button.Tag;
@@ -689,24 +655,11 @@ namespace FlaxEditor.Viewport
if (e is ContextMenuButton b)
{
var v = (float)b.Tag;
- b.Icon = Mathf.Abs(TransformGizmo.RotationSnapValue - v) < 0.001f
- ? Style.Current.CheckBoxTick
- : SpriteHandle.Invalid;
+ b.Icon = Mathf.Abs(TransformGizmo.RotationSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
}
}
}
- private static readonly float[] EditorViewportTranslateSnapValues =
- {
- 0.1f,
- 0.5f,
- 1.0f,
- 5.0f,
- 10.0f,
- 100.0f,
- 1000.0f,
- };
-
private void OnWidgetTranslateSnapClick(ContextMenuButton button)
{
var v = (float)button.Tag;
@@ -729,9 +682,7 @@ namespace FlaxEditor.Viewport
if (e is ContextMenuButton b)
{
var v = (float)b.Tag;
- b.Icon = Mathf.Abs(TransformGizmo.TranslationSnapValue - v) < 0.001f
- ? Style.Current.CheckBoxTick
- : SpriteHandle.Invalid;
+ b.Icon = Mathf.Abs(TransformGizmo.TranslationSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
}
}
}
diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs
index 2fdb39b4f..f66d4e861 100644
--- a/Source/Editor/Viewport/PrefabWindowViewport.cs
+++ b/Source/Editor/Viewport/PrefabWindowViewport.cs
@@ -131,16 +131,14 @@ namespace FlaxEditor.Viewport
Parent = scaleSnappingWidget
};
enableScaleSnapping.Toggled += OnScaleSnappingToggle;
-
var scaleSnappingCM = new ContextMenu();
_scaleSnapping = new ViewportWidgetButton(TransformGizmo.ScaleSnapValue.ToString(), SpriteHandle.Invalid, scaleSnappingCM)
{
TooltipText = "Scale snapping values"
};
-
- for (int i = 0; i < EditorViewportScaleSnapValues.Length; i++)
+ for (int i = 0; i < EditorGizmoViewport.ScaleSnapValues.Length; i++)
{
- var v = EditorViewportScaleSnapValues[i];
+ var v = EditorGizmoViewport.ScaleSnapValues[i];
var button = scaleSnappingCM.AddButton(v.ToString());
button.Tag = v;
}
@@ -158,16 +156,14 @@ namespace FlaxEditor.Viewport
Parent = rotateSnappingWidget
};
enableRotateSnapping.Toggled += OnRotateSnappingToggle;
-
var rotateSnappingCM = new ContextMenu();
_rotateSnapping = new ViewportWidgetButton(TransformGizmo.RotationSnapValue.ToString(), SpriteHandle.Invalid, rotateSnappingCM)
{
TooltipText = "Rotation snapping values"
};
-
- for (int i = 0; i < EditorViewportRotateSnapValues.Length; i++)
+ for (int i = 0; i < EditorGizmoViewport.RotateSnapValues.Length; i++)
{
- var v = EditorViewportRotateSnapValues[i];
+ var v = EditorGizmoViewport.RotateSnapValues[i];
var button = rotateSnappingCM.AddButton(v.ToString());
button.Tag = v;
}
@@ -185,16 +181,14 @@ namespace FlaxEditor.Viewport
Parent = translateSnappingWidget
};
enableTranslateSnapping.Toggled += OnTranslateSnappingToggle;
-
var translateSnappingCM = new ContextMenu();
_translateSnappng = new ViewportWidgetButton(TransformGizmo.TranslationSnapValue.ToString(), SpriteHandle.Invalid, translateSnappingCM)
{
TooltipText = "Position snapping values"
};
-
- for (int i = 0; i < EditorViewportTranslateSnapValues.Length; i++)
+ for (int i = 0; i < EditorGizmoViewport.TranslateSnapValues.Length; i++)
{
- var v = EditorViewportTranslateSnapValues[i];
+ var v = EditorGizmoViewport.TranslateSnapValues[i];
var button = translateSnappingCM.AddButton(v.ToString());
button.Tag = v;
}
@@ -428,19 +422,6 @@ namespace FlaxEditor.Viewport
_gizmoModeScale.Checked = mode == TransformGizmoBase.Mode.Scale;
}
- private static readonly float[] EditorViewportScaleSnapValues =
- {
- 0.05f,
- 0.1f,
- 0.25f,
- 0.5f,
- 1.0f,
- 2.0f,
- 4.0f,
- 6.0f,
- 8.0f,
- };
-
private void OnWidgetScaleSnapClick(ContextMenuButton button)
{
var v = (float)button.Tag;
@@ -459,25 +440,11 @@ namespace FlaxEditor.Viewport
if (e is ContextMenuButton b)
{
var v = (float)b.Tag;
- b.Icon = Mathf.Abs(TransformGizmo.ScaleSnapValue - v) < 0.001f
- ? Style.Current.CheckBoxTick
- : SpriteHandle.Invalid;
+ b.Icon = Mathf.Abs(TransformGizmo.ScaleSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
}
}
}
- private static readonly float[] EditorViewportRotateSnapValues =
- {
- 1.0f,
- 5.0f,
- 10.0f,
- 15.0f,
- 30.0f,
- 45.0f,
- 60.0f,
- 90.0f,
- };
-
private void OnWidgetRotateSnapClick(ContextMenuButton button)
{
var v = (float)button.Tag;
@@ -496,24 +463,11 @@ namespace FlaxEditor.Viewport
if (e is ContextMenuButton b)
{
var v = (float)b.Tag;
- b.Icon = Mathf.Abs(TransformGizmo.RotationSnapValue - v) < 0.001f
- ? Style.Current.CheckBoxTick
- : SpriteHandle.Invalid;
+ b.Icon = Mathf.Abs(TransformGizmo.RotationSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
}
}
}
- private static readonly float[] EditorViewportTranslateSnapValues =
- {
- 0.1f,
- 0.5f,
- 1.0f,
- 5.0f,
- 10.0f,
- 100.0f,
- 1000.0f,
- };
-
private void OnWidgetTranslateSnapClick(ContextMenuButton button)
{
var v = (float)button.Tag;
@@ -532,9 +486,7 @@ namespace FlaxEditor.Viewport
if (e is ContextMenuButton b)
{
var v = (float)b.Tag;
- b.Icon = Mathf.Abs(TransformGizmo.TranslationSnapValue - v) < 0.001f
- ? Style.Current.CheckBoxTick
- : SpriteHandle.Invalid;
+ b.Icon = Mathf.Abs(TransformGizmo.TranslationSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
}
}
}
diff --git a/Source/Editor/Viewport/ViewportDraggingHelper.cs b/Source/Editor/Viewport/ViewportDraggingHelper.cs
index 72fcce828..86a127647 100644
--- a/Source/Editor/Viewport/ViewportDraggingHelper.cs
+++ b/Source/Editor/Viewport/ViewportDraggingHelper.cs
@@ -146,7 +146,7 @@ namespace FlaxEditor.Viewport
var gridPlane = new Plane(Vector3.Zero, Vector3.Up);
var flags = SceneGraphNode.RayCastData.FlagTypes.SkipColliders | SceneGraphNode.RayCastData.FlagTypes.SkipEditorPrimitives;
hit = _owner.SceneGraphRoot.RayCast(ref ray, ref view, out var closest, out var normal, flags);
- var girdGizmo = (GridGizmo)_owner.Gizmos.FirstOrDefault(x => x is GridGizmo);
+ var girdGizmo = _owner.Gizmos.Get();
if (hit != null)
{
// Use hit location
@@ -180,7 +180,7 @@ namespace FlaxEditor.Viewport
var location = hitLocation + new Vector3(0, bottomToCenter, 0);
// Apply grid snapping if enabled
- var transformGizmo = (TransformGizmo)_owner.Gizmos.FirstOrDefault(x => x is TransformGizmo);
+ var transformGizmo = _owner.Gizmos.Get();
if (transformGizmo != null && (_owner.UseSnapping || transformGizmo.TranslationSnapEnable))
{
float snapValue = transformGizmo.TranslationSnapValue;
diff --git a/Source/Editor/Windows/Assets/PrefabWindow.cs b/Source/Editor/Windows/Assets/PrefabWindow.cs
index 2e3e700a2..eb5070cb1 100644
--- a/Source/Editor/Windows/Assets/PrefabWindow.cs
+++ b/Source/Editor/Windows/Assets/PrefabWindow.cs
@@ -132,7 +132,7 @@ namespace FlaxEditor.Windows.Assets
IsScrollable = false,
Offsets = new Margin(0, 0, 0, 18 + 6),
};
- _searchBox = new SearchBox()
+ _searchBox = new SearchBox
{
AnchorPreset = AnchorPresets.HorizontalStretchMiddle,
Parent = headerPanel,
@@ -140,7 +140,8 @@ namespace FlaxEditor.Windows.Assets
};
_searchBox.TextChanged += OnSearchBoxTextChanged;
- _treePanel = new Panel()
+ // Prefab structure tree
+ _treePanel = new Panel
{
AnchorPreset = AnchorPresets.StretchAll,
Offsets = new Margin(0.0f, 0.0f, headerPanel.Bottom, 0.0f),
@@ -148,8 +149,6 @@ namespace FlaxEditor.Windows.Assets
IsScrollable = true,
Parent = sceneTreePanel,
};
-
- // Prefab structure tree
Graph = new LocalSceneGraph(new CustomRootNode(this));
Graph.Root.TreeNode.Expand(true);
_tree = new PrefabTree
@@ -316,11 +315,7 @@ namespace FlaxEditor.Windows.Assets
return;
// Restore
- _viewport.Prefab = _asset;
- Graph.MainActor = _viewport.Instance;
- Selection.Clear();
- Select(Graph.Main);
- Graph.Root.TreeNode.Expand(true);
+ OnPrefabOpened();
_undo.Clear();
ClearEditedFlag();
}
@@ -346,6 +341,15 @@ namespace FlaxEditor.Windows.Assets
}
}
+ private void OnPrefabOpened()
+ {
+ _viewport.Prefab = _asset;
+ Graph.MainActor = _viewport.Instance;
+ Selection.Clear();
+ Select(Graph.Main);
+ Graph.Root.TreeNode.Expand(true);
+ }
+
///
public override void Save()
{
@@ -417,13 +421,8 @@ namespace FlaxEditor.Windows.Assets
return;
}
- _viewport.Prefab = _asset;
- Graph.MainActor = _viewport.Instance;
+ OnPrefabOpened();
_focusCamera = true;
- Selection.Clear();
- Select(Graph.Main);
- Graph.Root.TreeNode.Expand(true);
-
_undo.Clear();
ClearEditedFlag();
@@ -468,11 +467,7 @@ namespace FlaxEditor.Windows.Assets
_viewport.Prefab = null;
if (_asset.IsLoaded)
{
- _viewport.Prefab = _asset;
- Graph.MainActor = _viewport.Instance;
- Selection.Clear();
- Select(Graph.Main);
- Graph.Root.TreeNode.ExpandAll(true);
+ OnPrefabOpened();
}
}
finally
@@ -484,7 +479,6 @@ namespace FlaxEditor.Windows.Assets
if (_focusCamera && _viewport.Task.FrameCount > 1)
{
_focusCamera = false;
-
Editor.GetActorEditorSphere(_viewport.Instance, out BoundingSphere bounds);
_viewport.ViewPosition = bounds.Center - _viewport.ViewDirection * (bounds.Radius * 1.2f);
}