1
0

MouseDrag4.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using UnityEngine;
  2. public class MouseDrag4 : MonoBehaviour
  3. {
  4. public Transform HandL;
  5. public int ido;
  6. public bool isPlay = false;
  7. public bool isSelect;
  8. public bool isStop = false;
  9. public Maid maid = null;
  10. public GameObject obj;
  11. public bool reset;
  12. private Vector3 mouseIti;
  13. private Vector3 mouseIti2;
  14. private Vector3 off;
  15. private Vector3 off2;
  16. private Vector3 rotate;
  17. private Vector3 worldPoint;
  18. public void OnMouseDown()
  19. {
  20. if (maid == null)
  21. return;
  22. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  23. off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  24. off2 = new Vector3(obj.transform.position.x - HandL.position.x,
  25. obj.transform.position.y - HandL.position.y,
  26. obj.transform.position.z - HandL.position.z);
  27. mouseIti = Input.mousePosition;
  28. isSelect = true;
  29. rotate = HandL.localEulerAngles;
  30. }
  31. public void OnMouseDrag()
  32. {
  33. if (maid == null)
  34. return;
  35. if (reset)
  36. {
  37. reset = false;
  38. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  39. off = transform.position
  40. - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  41. off2 = new Vector3(obj.transform.position.x - HandL.position.x,
  42. obj.transform.position.y - HandL.position.y,
  43. obj.transform.position.z - HandL.position.z);
  44. rotate = HandL.localEulerAngles;
  45. mouseIti = Input.mousePosition;
  46. }
  47. if (mouseIti != Input.mousePosition)
  48. {
  49. Vector3 vector3_1 = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z))
  50. + off - off2;
  51. Vector3 vector3_2 = Input.mousePosition - mouseIti;
  52. Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
  53. Vector3 vector3_3 = transform.TransformDirection(Vector3.right);
  54. Vector3 vector3_4 = transform.TransformDirection(Vector3.forward);
  55. if (mouseIti2 != Input.mousePosition)
  56. {
  57. HandL.localEulerAngles = rotate;
  58. if (ido == 1)
  59. {
  60. HandL.RotateAround(HandL.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), vector3_2.y / 1f);
  61. HandL.RotateAround(HandL.position, new Vector3(vector3_4.x, 0.0f, vector3_4.z), (float) (-(double) vector3_2.x / 1.5));
  62. }
  63. if (ido == 2)
  64. HandL.localRotation = Quaternion.Euler(HandL.localEulerAngles)
  65. * Quaternion.AngleAxis(vector3_2.x / 1.5f, Vector3.right);
  66. }
  67. }
  68. mouseIti2 = Input.mousePosition;
  69. }
  70. }