Оптимизация MouseWorldPositionWindow: lookup-массив вместо Mathf.Pow, кеширование displayWorld
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
parent
6e2706883d
commit
bd44b3ab9b
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -46,7 +46,7 @@ Material:
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _Scale: 30
|
||||
- _Speed: 0.1
|
||||
- _Speed: 0.25
|
||||
m_Colors:
|
||||
- White: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _AddttionalColor: {r: 4, g: 0, b: 0.06557083, a: 1}
|
||||
|
||||
@ -4361,7 +4361,7 @@ MonoBehaviour:
|
||||
m_HandleRect: {fileID: 1078381204}
|
||||
m_Direction: 2
|
||||
m_Value: 1
|
||||
m_Size: 0.86301625
|
||||
m_Size: 0.8630169
|
||||
m_NumberOfSteps: 0
|
||||
m_OnValueChanged:
|
||||
m_PersistentCalls:
|
||||
@ -9455,7 +9455,7 @@ RectTransform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.132, y: 0.5}
|
||||
m_AnchorMax: {x: 0.846, y: 0.77500004}
|
||||
m_AnchoredPosition: {x: -54.500015, y: 5}
|
||||
m_AnchoredPosition: {x: -54.5, y: 5}
|
||||
m_SizeDelta: {x: -107, y: -10}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &1474919456
|
||||
@ -11914,7 +11914,7 @@ RectTransform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 1}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: 0.00088984595}
|
||||
m_AnchoredPosition: {x: 0, y: 0.0009278054}
|
||||
m_SizeDelta: {x: 0, y: 300}
|
||||
m_Pivot: {x: 0, y: 1}
|
||||
--- !u!114 &1792218764
|
||||
@ -13281,7 +13281,7 @@ RectTransform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.132, y: 0.21750003}
|
||||
m_AnchorMax: {x: 0.846, y: 0.5}
|
||||
m_AnchoredPosition: {x: -54.500015, y: -79}
|
||||
m_AnchoredPosition: {x: -54.5, y: -79.00001}
|
||||
m_SizeDelta: {x: -107, y: -63}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &1959311160
|
||||
|
||||
@ -6,12 +6,16 @@ public class MouseWorldPositionWindow : EditorWindow
|
||||
{
|
||||
private enum PlaneMode { XY, XZ, YZ, CameraFacing }
|
||||
|
||||
// Множители для быстрого доступа: multipliers[d] = 10^d
|
||||
private static readonly float[] Multipliers = { 1f, 10f, 100f, 1000f, 10000f, 100000f, 1000000f };
|
||||
|
||||
private PlaneMode planeMode = PlaneMode.XZ;
|
||||
private float planeOffset = 0f; // смещение плоскости по нормали (Z для XY, Y для XZ, X для YZ)
|
||||
private float planeOffset;
|
||||
private bool lockToSceneView = true;
|
||||
private int decimals = 3;
|
||||
|
||||
private Vector3 lastWorld;
|
||||
private Vector3 displayWorld;
|
||||
private bool hasPoint;
|
||||
|
||||
[MenuItem("Tools/Mouse World Position")]
|
||||
@ -38,9 +42,9 @@ public class MouseWorldPositionWindow : EditorWindow
|
||||
EditorGUILayout.Space(6);
|
||||
EditorGUILayout.LabelField("Projection", EditorStyles.boldLabel);
|
||||
|
||||
planeMode = (PlaneMode)EditorGUILayout.EnumPopup("Plane", planeMode);
|
||||
planeMode = (PlaneMode)EditorGUILayout.EnumPopup("Плоскость", planeMode);
|
||||
if (planeMode != PlaneMode.CameraFacing)
|
||||
planeOffset = EditorGUILayout.FloatField("Plane Offset", planeOffset);
|
||||
planeOffset = EditorGUILayout.FloatField("Смещение плоскости", planeOffset);
|
||||
|
||||
decimals = EditorGUILayout.IntSlider("Decimals", decimals, 0, 6);
|
||||
|
||||
@ -50,28 +54,24 @@ public class MouseWorldPositionWindow : EditorWindow
|
||||
using (new EditorGUI.DisabledScope(true))
|
||||
{
|
||||
EditorGUILayout.Toggle("Has Point", hasPoint);
|
||||
EditorGUILayout.Vector3Field("World", lastWorld);
|
||||
EditorGUILayout.Vector3Field("World", displayWorld);
|
||||
}
|
||||
|
||||
using (new EditorGUI.DisabledScope(!hasPoint))
|
||||
{
|
||||
if (GUILayout.Button("Copy (x,y,z)"))
|
||||
{
|
||||
EditorGUIUtility.systemCopyBuffer = FormatVec(lastWorld, decimals);
|
||||
string f = "F" + decimals;
|
||||
EditorGUIUtility.systemCopyBuffer = $"{displayWorld.x.ToString(f)}, {displayWorld.y.ToString(f)}, {displayWorld.z.ToString(f)}";
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
"Move mouse in Scene View. The window shows world position under cursor.\n" +
|
||||
"3D uses ray-plane intersection (choose plane). 2D обычно: XY @ Z=0.",
|
||||
MessageType.Info);
|
||||
}
|
||||
|
||||
private void OnSceneGUI(SceneView sv)
|
||||
{
|
||||
if (!lockToSceneView && sv != SceneView.lastActiveSceneView) return;
|
||||
|
||||
var e = Event.current;
|
||||
Event e = Event.current;
|
||||
if (e == null) return;
|
||||
|
||||
// Берём позицию мыши только когда курсор над SceneView
|
||||
@ -82,7 +82,21 @@ public class MouseWorldPositionWindow : EditorWindow
|
||||
|
||||
hasPoint = TryGetPoint(ray, sv.camera, out lastWorld);
|
||||
|
||||
// чтобы окно обновлялось живо
|
||||
// Вычисляем displayWorld один раз при изменении позиции
|
||||
if (hasPoint)
|
||||
{
|
||||
float mult = Multipliers[decimals];
|
||||
displayWorld = new Vector3(
|
||||
Mathf.Ceil(lastWorld.x * mult) / mult,
|
||||
Mathf.Ceil(lastWorld.y * mult) / mult,
|
||||
Mathf.Ceil(lastWorld.z * mult) / mult
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
displayWorld = default;
|
||||
}
|
||||
|
||||
Repaint();
|
||||
}
|
||||
|
||||
@ -107,8 +121,8 @@ public class MouseWorldPositionWindow : EditorWindow
|
||||
|
||||
case PlaneMode.CameraFacing:
|
||||
default:
|
||||
var normal = cam.transform.forward;
|
||||
var point = cam.transform.position; // можно поменять на position + forward*dist если надо
|
||||
Vector3 normal = cam.transform.forward;
|
||||
Vector3 point = cam.transform.position; // можно поменять на position + forward*dist если надо
|
||||
plane = new Plane(normal, point);
|
||||
break;
|
||||
}
|
||||
@ -123,10 +137,5 @@ public class MouseWorldPositionWindow : EditorWindow
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string FormatVec(Vector3 v, int d)
|
||||
{
|
||||
string f = "F" + Mathf.Clamp(d, 0, 6);
|
||||
return $"{v.x.ToString(f)}, {v.y.ToString(f)}, {v.z.ToString(f)}";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user