滚轮缩放

This commit is contained in:
bob
2025-06-24 18:10:04 +08:00
parent 89cad84802
commit 979c876c33

View File

@@ -13,15 +13,23 @@ namespace NBF
private Vector2 _startPos;
private Vector3 _startRot;
private SwipeGesture _swipeGesture;
public float ZoomValue = 5;
public float MinZoom = 1;
public float MaxZoom = 15;
private bool _focus;
private void OnInited()
{
SetRotateListening();
// Stage.inst.on
TouchHolder.onRollOver.Set(OnFocusIn);
TouchHolder.onRollOut.Set(OnFocusOut);
Stage.inst.onMouseWheel.Add(OnMouseWheel);
// TouchHolder.onm
}
public override void Dispose()
{
Stage.inst.onMouseWheel.Remove(OnMouseWheel);
base.Dispose();
}
/// <summary>
@@ -66,6 +74,7 @@ namespace NBF
gesture1.onEnd.Set(OnSwipeEnd);
}
#region
private void OnSwipeMove(EventContext context)
{
@@ -104,5 +113,36 @@ namespace NBF
{
_renderImage.StopRotate();
}
#endregion
#region Zoom
private void OnFocusIn()
{
_focus = true;
Log.Info("focus true");
}
private void OnFocusOut()
{
_focus = false;
Log.Info("focus false");
}
private void OnMouseWheel(EventContext context)
{
if (!_focus) return;
float delta = context.inputEvent.mouseWheelDelta / Stage.devicePixelRatio;
SetZoom(delta * 0.2f);
}
private void SetZoom(float delta)
{
var pos = _renderImage.modelRoot.localPosition;
_renderImage.modelRoot.localPosition = new Vector3(pos.x, pos.y, pos.z + delta);
}
#endregion
}
}