using System; using UnityEngine; public class WorldTransformAxis : MonoBehaviour { public Vector2 ScaleMinMax { get { return this.ScaleMinMax_; } set { this.ScaleMinMax_ = value; GameObject[] array = new GameObject[] { this.XAxisObject, this.YAxisObject, this.ZAxisObject, this.AllAxisObject }; for (int i = 0; i < array.Length; i++) { if (array[i] != null && array[i].GetComponent() != null) { array[i].GetComponent().ScaleMinMax = value; } } } } public void Awake() { GameObject[] array = new GameObject[] { this.XAxisObject, this.YAxisObject, this.ZAxisObject, this.AllAxisObject }; WorldTransformAxis.MoveType[] array2 = new WorldTransformAxis.MoveType[] { WorldTransformAxis.MoveType.X, WorldTransformAxis.MoveType.Y, WorldTransformAxis.MoveType.Z, WorldTransformAxis.MoveType.All }; for (int i = 0; i < array.Length; i++) { if (array[i] != null && array[i].GetComponent() == null) { WorldTransformAxis worldTransformAxis = array[i].AddComponent(); worldTransformAxis.move_type_ = array2[i]; worldTransformAxis.parent_obj_ = this; worldTransformAxis.ScaleMinMax = this.ScaleMinMax; } } this.init_position_ = base.transform.localPosition; this.init_scale_ = base.transform.localScale; this.arrow_mesh_ = base.gameObject.GetComponent(); } public void Update() { if (this.move_type_ != WorldTransformAxis.MoveType.Null && this.target != null) { if (NInput.GetMouseButtonDown(0) && !this.is_click_) { if (UICamera.Raycast(Input.mousePosition) || GizmoRender.control_lock) { return; } Ray ray = GameMain.Instance.MainCamera.camera.ScreenPointToRay(Input.mousePosition); RaycastHit raycastHit = default(RaycastHit); if (!Physics.Raycast(ray, out raycastHit, float.PositiveInfinity, LayerMask.GetMask(new string[] { LayerMask.LayerToName(base.gameObject.layer) })) || raycastHit.transform != base.transform) { return; } this.OnMouseDownEvent(); return; } else if (this.is_click_) { if (NInput.GetMouseButton(0)) { this.OnMouseDragEvent(); return; } this.is_click_ = (this.parent_obj_.is_drag_ = false); GizmoRender.global_control_lock = false; } } if (this.target == null || this.parent_obj_ != null) { return; } base.transform.position = this.target.transform.position + this.offset_position_; if (GameMain.Instance.VRMode) { base.transform.rotation = this.target.transform.rotation; base.transform.localScale = this.target.transform.localScale; } } private void OnMouseDownEvent() { Transform transform = this.target.transform; GizmoRender.global_control_lock = true; this.screen_point_ = Camera.main.WorldToScreenPoint(transform.position); float x = Input.mousePosition.x; float y = Input.mousePosition.y; this.object_offset_ = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(x, y, this.screen_point_.z)); this.is_click_ = true; } private void OnMouseDragEvent() { if (this.move_type_ == WorldTransformAxis.MoveType.Null || this.target == null || !this.is_click_) { return; } this.parent_obj_.is_drag_ = true; this.is_drag_ = true; float x = Input.mousePosition.x; float y = Input.mousePosition.y; Vector3 position = new Vector3(x, y, this.screen_point_.z); Vector3 position2 = Camera.main.ScreenToWorldPoint(position) + this.object_offset_; Transform transform = this.target.transform; Vector3 position3 = transform.position; if (this.move_type_ != WorldTransformAxis.MoveType.All) { if (this.move_type_ != WorldTransformAxis.MoveType.X) { position2.x = position3.x; } if (this.move_type_ != WorldTransformAxis.MoveType.Y) { position2.y = position3.y; } if (this.move_type_ != WorldTransformAxis.MoveType.Z) { position2.z = position3.z; } } transform.position = position2; if (this.parent_obj_ != null) { this.parent_obj_.transform.position = position2; } else { base.transform.position = position2; } } public void Apply() { if (this.target == null || this.target.transform == null) { return; } Transform transform = (!(this.parent_obj_ != null)) ? base.transform : this.parent_obj_.transform; this.target.transform.position = transform.position; this.target.transform.rotation = transform.rotation; this.target.transform.localScale = transform.localScale; } public bool is_drag { get { return this.is_drag_; } } public bool is_grip { get { return this.is_grip_; } set { this.is_grip_ = value; if (this.parent_obj_ != null) { this.parent_obj_.is_grip = value; } } } public Vector3 offsetPosition { get { return this.offset_position_; } set { this.offset_position_ = value; } } public float offsetScale { get { return this.offset_scale_; } set { this.offset_scale_ = value; base.transform.localScale = new Vector3(this.offset_scale_, this.offset_scale_, this.offset_scale_); } } public bool Visible { get { return base.gameObject.activeSelf; } set { base.gameObject.SetActive(value); if (value) { this.Update(); } } } public bool VisibleAxisArrow { get { return !(this.arrow_mesh_ == null) && this.arrow_mesh_.enabled; } set { if (this.arrow_mesh_ == null) { return; } this.arrow_mesh_.enabled = value; if (this.XAxisObject != null) { this.XAxisObject.SetActive(value); } if (this.YAxisObject != null) { this.YAxisObject.SetActive(value); } if (this.ZAxisObject != null) { this.ZAxisObject.SetActive(value); } } } private GameObject target { get { return (!(this.parent_obj_ != null)) ? this.TargetObject : this.parent_obj_.target; } } public GameObject TargetObject; public GameObject XAxisObject; public GameObject YAxisObject; public GameObject ZAxisObject; public GameObject AllAxisObject; private Vector2 ScaleMinMax_; private bool is_grip_; private WorldTransformAxis.MoveType move_type_; private Vector3 screen_point_; private Vector3 object_offset_; private WorldTransformAxis parent_obj_; private MeshRenderer arrow_mesh_; private Vector3 init_position_; private Vector3 init_scale_; private Vector3 offset_position_; private float offset_scale_; private bool is_drag_; private bool is_click_; private enum MoveType { Null, X, Y, Z, All } }