工具: unity2018.4.2 、vs2017
一、效果
二、代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AxisMouseEvent : MonoBehaviour
{
Transform m_gameManager;
void Start()
{
m_gameManager = GameObject.Find("GameManager").transform;
}
void OnMouseEnter()
{
m_gameManager.SendMessage("MoseHoverEnter",gameObject.name);
}
void OnMouseDown()
{
m_gameManager.SendMessage("MouseDown", gameObject.name);
}
void OnMouseExit()
{
m_gameManager.SendMessage("MouseHoverExis", gameObject.name);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 通过拖动小坐标轴 移动模型
/// </summary>
public class MoveModel : MonoBehaviour
{
#region 常量
//移动速度
const float MOVE_SPEED = 10F;
#endregion
#region 字段
public Transform m_camera;
//模型
Transform m_model;
//坐标轴
Transform m_axis;
//坐标轴颜色 分别对应x、y、z、选中轴
Color[] m_axisColors = new Color[] { Color.red, Color.green, Color.blue, Color.yellow };
//是否正在移动物体
bool m_isMoveModel = false;
//上一帧鼠标位置
Vector3 m_lastMousePos;
//当前选中坐标轴
AxisState m_axisState = AxisState.Idle;
//坐标轴的三个轴
Transform[] m_xyz = new Tra