123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using UnityEngine;
- public class MouseDrag2 : MonoBehaviour
- {
- public int ido;
- public bool isClick;
- public bool isIdo;
- public bool isOn;
- public bool isSelect;
- public Maid maid = null;
- public GameObject obj;
- public bool reset;
- private float doubleTapTime;
- private int idoOld;
- private Vector3 mouseIti;
- private Vector3 mouseIti2;
- private Vector3 off;
- private Vector3 off2;
- private Vector3 rotate;
- private float size;
- private Vector3 worldPoint;
- public void Update()
- {
- doubleTapTime += Time.deltaTime;
- }
- public void OnMouseDown()
- {
- if (maid == null)
- return;
- worldPoint = Camera.main.WorldToScreenPoint(transform.position);
- off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
- off2 = new Vector3(obj.transform.position.x - maid.transform.position.x,
- obj.transform.position.y - maid.transform.position.y,
- obj.transform.position.z - maid.transform.position.z);
- mouseIti = Input.mousePosition;
- if (doubleTapTime < 0.300000011920929 && isClick && ido == idoOld)
- {
- if (ido == 5)
- maid.transform.localScale = new Vector3(1f, 1f, 1f);
- if (ido == 4 || ido == 6)
- maid.transform.eulerAngles = new Vector3(0.0f, maid.transform.eulerAngles.y, 0.0f);
- }
- if (doubleTapTime >= 0.300000011920929 && isClick)
- isClick = false;
- doubleTapTime = 0.0f;
- rotate = maid.transform.localEulerAngles;
- size = maid.transform.localScale.x;
- isSelect = true;
- isOn = true;
- }
- public void OnMouseUp()
- {
- if (maid != null)
- isOn = false;
- if (doubleTapTime >= 0.300000011920929)
- return;
- isClick = true;
- doubleTapTime = 0.0f;
- idoOld = ido;
- }
- public void OnMouseDrag()
- {
- if (maid == null)
- return;
- if (reset)
- {
- reset = false;
- worldPoint = Camera.main.WorldToScreenPoint(transform.position);
- off = transform.position
- - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
- off2 = new Vector3(obj.transform.position.x - maid.transform.position.x,
- obj.transform.position.y - maid.transform.position.y,
- obj.transform.position.z - maid.transform.position.z);
- rotate = maid.transform.localEulerAngles;
- size = maid.transform.localScale.x;
- mouseIti = Input.mousePosition;
- }
- if (mouseIti != Input.mousePosition)
- {
- Vector3 vector3_1 = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z))
- + off - off2;
- isIdo = false;
- if (ido == 1)
- {
- maid.transform.position = new Vector3(vector3_1.x, maid.transform.position.y, vector3_1.z);
- isIdo = true;
- }
- if (ido == 2)
- {
- maid.transform.position = new Vector3(maid.transform.position.x, vector3_1.y, maid.transform.position.z);
- isIdo = true;
- }
- Vector3 vector3_2;
- if (ido == 3)
- {
- vector3_2 = Input.mousePosition - mouseIti;
- maid.transform.eulerAngles =
- new Vector3(maid.transform.eulerAngles.x, rotate.y - vector3_2.x / 2.2f, maid.transform.eulerAngles.z);
- }
- Vector3 vector3_3;
- if (ido == 4)
- {
- vector3_2 = Input.mousePosition - mouseIti;
- Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
- vector3_3 = transform.TransformDirection(Vector3.right);
- Vector3 vector3_4 = transform.TransformDirection(Vector3.forward);
- if (mouseIti2 != Input.mousePosition)
- {
- maid.transform.localEulerAngles = rotate;
- maid.transform.RotateAround(maid.transform.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), vector3_2.y / 4f);
- maid.transform.RotateAround(maid.transform.position,
- new Vector3(vector3_4.x, 0.0f, vector3_4.z),
- (float) (-(double) vector3_2.x / 6.0));
- }
- isIdo = true;
- mouseIti2 = Input.mousePosition;
- }
- if (ido == 6)
- {
- vector3_2 = Input.mousePosition - mouseIti;
- Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
- vector3_3 = transform.TransformDirection(Vector3.right);
- transform.TransformDirection(Vector3.forward);
- if (mouseIti2 != Input.mousePosition)
- {
- maid.transform.localEulerAngles = rotate;
- maid.body0.transform.localRotation = Quaternion.Euler(maid.body0.transform.localEulerAngles)
- * Quaternion.AngleAxis((float) (-(double) vector3_2.x / 2.20000004768372),
- Vector3.up);
- }
- isIdo = true;
- mouseIti2 = Input.mousePosition;
- }
- if (ido == 5)
- {
- vector3_2 = Input.mousePosition - mouseIti;
- float num = size + vector3_2.y / 200f;
- if (num < 0.100000001490116)
- num = 0.1f;
- maid.transform.localScale = new Vector3(num, num, num);
- }
- }
- }
- }
|