滚轮缩放
This commit is contained in:
@@ -13,15 +13,23 @@ namespace NBF
|
|||||||
private Vector2 _startPos;
|
private Vector2 _startPos;
|
||||||
private Vector3 _startRot;
|
private Vector3 _startRot;
|
||||||
private SwipeGesture _swipeGesture;
|
private SwipeGesture _swipeGesture;
|
||||||
|
private bool _focus;
|
||||||
public float ZoomValue = 5;
|
|
||||||
public float MinZoom = 1;
|
|
||||||
public float MaxZoom = 15;
|
|
||||||
|
|
||||||
|
|
||||||
private void OnInited()
|
private void OnInited()
|
||||||
{
|
{
|
||||||
SetRotateListening();
|
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>
|
/// <summary>
|
||||||
@@ -66,6 +74,7 @@ namespace NBF
|
|||||||
gesture1.onEnd.Set(OnSwipeEnd);
|
gesture1.onEnd.Set(OnSwipeEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 旋转和平移
|
||||||
|
|
||||||
private void OnSwipeMove(EventContext context)
|
private void OnSwipeMove(EventContext context)
|
||||||
{
|
{
|
||||||
@@ -104,5 +113,36 @@ namespace NBF
|
|||||||
{
|
{
|
||||||
_renderImage.StopRotate();
|
_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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user