@@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using FlaxEditor.Gizmo;
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEditor.GUI.Input;
|
||||
using FlaxEditor.SceneGraph;
|
||||
using FlaxEditor.Viewport.Cameras;
|
||||
using FlaxEditor.Viewport.Widgets;
|
||||
@@ -298,9 +299,33 @@ namespace FlaxEditor.Viewport
|
||||
}
|
||||
var buttonBB = translateSnappingCM.AddButton("Bounding Box").LinkTooltip("Snaps the selection based on it's bounding volume");
|
||||
buttonBB.Tag = -1.0f;
|
||||
translateSnappingCM.ButtonClicked += button =>
|
||||
var buttonCustom = translateSnappingCM.AddButton("Custom");
|
||||
buttonCustom.LinkTooltip("Custom grid size");
|
||||
const float defaultCustomTranslateSnappingValue = 250.0f;
|
||||
float customTranslateSnappingValue = transformGizmo.TranslationSnapValue;
|
||||
if (customTranslateSnappingValue < 0.0f)
|
||||
customTranslateSnappingValue = defaultCustomTranslateSnappingValue;
|
||||
foreach (var v in TranslateSnapValues)
|
||||
{
|
||||
var v = (float)button.Tag;
|
||||
if (Mathf.Abs(transformGizmo.TranslationSnapValue - v) < 0.001f)
|
||||
{
|
||||
customTranslateSnappingValue = defaultCustomTranslateSnappingValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
buttonCustom.Tag = customTranslateSnappingValue;
|
||||
var customValue = new FloatValueBox(customTranslateSnappingValue, Style.Current.FontMedium.MeasureText(buttonCustom.Text).X + 5, 2, 70.0f, 0.001f, float.MaxValue, 0.1f)
|
||||
{
|
||||
Parent = buttonCustom
|
||||
};
|
||||
customValue.ValueChanged += () =>
|
||||
{
|
||||
buttonCustom.Tag = customValue.Value;
|
||||
buttonCustom.Click();
|
||||
};
|
||||
translateSnappingCM.ButtonClicked += b =>
|
||||
{
|
||||
var v = (float)b.Tag;
|
||||
transformGizmo.TranslationSnapValue = v;
|
||||
if (v < 0.0f)
|
||||
translateSnapping.Text = "Bounding Box";
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace FlaxEditor.Viewport
|
||||
editor.SceneEditing.SelectionChanged += OnSelectionChanged;
|
||||
|
||||
// Gizmo widgets
|
||||
AddGizmoViewportWidgets(this, TransformGizmo);
|
||||
AddGizmoViewportWidgets(this, TransformGizmo, true);
|
||||
|
||||
// Show grid widget
|
||||
_showGridButton = ViewWidgetShowMenu.AddButton("Grid", () => Grid.Enabled = !Grid.Enabled);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace FlaxEngine
|
||||
{
|
||||
partial struct SpriteHandle
|
||||
partial struct SpriteHandle : IEquatable<SpriteHandle>
|
||||
{
|
||||
/// <summary>
|
||||
/// Invalid sprite handle.
|
||||
@@ -107,5 +108,53 @@ namespace FlaxEngine
|
||||
Atlas.SetSprite(Index, ref sprite);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for equality between two objects.
|
||||
/// </summary>
|
||||
/// <param name="left">The first value to compare.</param>
|
||||
/// <param name="right">The second value to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(SpriteHandle left, SpriteHandle right)
|
||||
{
|
||||
return left.Index == right.Index && left.Atlas == right.Atlas;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for inequality between two objects.
|
||||
/// </summary>
|
||||
/// <param name="left">The first value to compare.</param>
|
||||
/// <param name="right">The second value to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(SpriteHandle left, SpriteHandle right)
|
||||
{
|
||||
return left.Index != right.Index || left.Atlas != right.Atlas;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(SpriteHandle other)
|
||||
{
|
||||
return Index == other.Index && Atlas == other.Atlas;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is SpriteHandle other && Equals(other);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Atlas, Index);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
if (Atlas)
|
||||
return $"{System.IO.Path.GetFileNameWithoutExtension(Atlas.Path)}[{Index}]";
|
||||
return "Invalid";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user