75 lines
2.0 KiB
C#
75 lines
2.0 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
|
|
namespace Wing.Gizmos
|
|
{
|
|
public class GizmosMove : GizmosBase
|
|
{
|
|
public delegate void MoveEventHandler(float dx, float dy, float dz);
|
|
|
|
public event MoveEventHandler OnMove;
|
|
public event Action OnMoveEnd;
|
|
// Use this for initialization
|
|
|
|
private Vector3 mTotal = Vector3.zero;
|
|
|
|
protected override void OnInit()
|
|
{
|
|
ConstructAxis("X", EGizmosAxisType.X);
|
|
ConstructAxis("Y", EGizmosAxisType.Y);
|
|
ConstructAxis("Z", EGizmosAxisType.Z);
|
|
ConstructAxis("LockX", EGizmosAxisType.LockX);
|
|
ConstructAxis("LockY", EGizmosAxisType.LockY);
|
|
ConstructAxis("LockZ", EGizmosAxisType.LockZ);
|
|
}
|
|
|
|
protected override void OnDragDelta(GameObject go, float dx, float dy, float dz)
|
|
{
|
|
//精度捕捉
|
|
Vector3 delta = new Vector3(dx, dy, dz);
|
|
Vector3 newPos = Vector3.zero;
|
|
ISnap snap = SnapFactory.Instance.Get(ESnapType.Move);
|
|
if (snap.Snap(mTotal + delta, ref newPos))
|
|
{
|
|
dx = newPos.x - mTotal.x;
|
|
dy = newPos.y - mTotal.y;
|
|
dz = newPos.z - mTotal.z;
|
|
}
|
|
mTotal += new Vector3(dx, dy, dz);
|
|
///////
|
|
|
|
base.OnDragDelta(go, dx, dy, dz);
|
|
transform.Translate(dx, dy, dz);
|
|
if (OnMove != null)
|
|
{
|
|
OnMove(dx, dy, dz);
|
|
}
|
|
}
|
|
|
|
public void Move(float dx,float dy, float dz)
|
|
{
|
|
transform.Translate(dx, dy, dz);
|
|
if (OnMove != null)
|
|
{
|
|
OnMove(dx, dy, dz);
|
|
}
|
|
|
|
if (OnMoveEnd != null)
|
|
{
|
|
OnMoveEnd();
|
|
}
|
|
}
|
|
|
|
protected override void OnDragEnd(GameObject go)
|
|
{
|
|
base.OnDragEnd(go);
|
|
if (OnMoveEnd != null)
|
|
{
|
|
OnMoveEnd();
|
|
}
|
|
}
|
|
}
|
|
}
|