DragMune.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class DragMune : BaseDrag
  6. {
  7. private readonly TBody.IKCMO IK = new TBody.IKCMO();
  8. private readonly GameObject[] things = new GameObject[3];
  9. private Transform[] ikChain;
  10. private Vector3[] jointRotation = new Vector3[2];
  11. private Vector3 off;
  12. private Vector3 off2;
  13. public DragMune Initialize(Transform[] ikChain, Meido meido, Func<Vector3> position, Func<Vector3> rotation)
  14. {
  15. base.Initialize(meido, position, rotation);
  16. this.ikChain = ikChain;
  17. for (int i = 0; i < things.Length; i++)
  18. {
  19. things[i] = new GameObject();
  20. things[i].transform.position = this.ikChain[i].position;
  21. things[i].transform.localRotation = this.ikChain[i].localRotation;
  22. }
  23. InitializeIK();
  24. return this;
  25. }
  26. public void InitializeIK()
  27. {
  28. IK.Init(ikChain[upperArm], ikChain[foreArm], ikChain[hand], maid.body0);
  29. }
  30. protected override void GetDragType()
  31. {
  32. if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.LeftAlt))
  33. {
  34. dragType = DragType.RotLocalXZ;
  35. }
  36. else
  37. {
  38. dragType = DragType.None;
  39. }
  40. }
  41. protected override void DoubleClick()
  42. {
  43. if (dragType == DragType.RotLocalXZ) meido.SetMune();
  44. }
  45. protected override void InitializeDrag()
  46. {
  47. base.InitializeDrag();
  48. off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  49. off2 = new Vector3(
  50. transform.position.x - ikChain[hand].position.x,
  51. transform.position.y - ikChain[hand].position.y,
  52. transform.position.z - ikChain[hand].position.z);
  53. jointRotation[upperArmRot] = ikChain[upperArm].localEulerAngles;
  54. jointRotation[handRot] = ikChain[hand].localEulerAngles;
  55. meido.SetMune(true);
  56. }
  57. protected override void Drag()
  58. {
  59. if (dragType == DragType.None) return;
  60. if (isPlaying) meido.IsStop = true;
  61. IKCtrlData ikData = maid.body0.IKCtrl.GetIKData("左手");
  62. Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)) + off - off2;
  63. if (dragType == DragType.RotLocalXZ)
  64. {
  65. IK.Porc(ikChain[upperArm], ikChain[foreArm], ikChain[hand], pos, Vector3.zero, ikData);
  66. // IK.Porc(ikChain[upperArm], ikChain[foreArm], ikChain[hand], pos + (pos - ikChain[hand].position), Vector3.zero, ikData);
  67. jointRotation[handRot] = ikChain[hand].localEulerAngles;
  68. jointRotation[upperArmRot] = ikChain[upperArm].localEulerAngles;
  69. ikChain[upperArm].localEulerAngles = jointRotation[upperArm];
  70. ikChain[hand].localEulerAngles = jointRotation[handRot];
  71. }
  72. }
  73. }
  74. }