DragMune.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 void Initialize(Transform[] ikChain, Maid maid, Func<Vector3> position, Func<Vector3> rotation)
  14. {
  15. base.Initialize(maid, 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. }
  25. public void InitializeIK()
  26. {
  27. IK.Init(ikChain[upperArm], ikChain[foreArm], ikChain[hand], maid.body0);
  28. }
  29. protected override void GetDragType()
  30. {
  31. if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.LeftAlt))
  32. {
  33. dragType = DragType.RotLocalXZ;
  34. }
  35. else
  36. {
  37. dragType = DragType.None;
  38. }
  39. }
  40. protected override void DoubleClick()
  41. {
  42. if (dragType == DragType.RotLocalXZ)
  43. {
  44. maid.body0.MuneYureL(1f);
  45. maid.body0.MuneYureR(1f);
  46. maid.body0.jbMuneL.enabled = true;
  47. maid.body0.jbMuneR.enabled = true;
  48. }
  49. }
  50. protected override void InitializeDrag()
  51. {
  52. base.InitializeDrag();
  53. off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  54. off2 = new Vector3(
  55. transform.position.x - ikChain[hand].position.x,
  56. transform.position.y - ikChain[hand].position.y,
  57. transform.position.z - ikChain[hand].position.z);
  58. jointRotation[upperArmRot] = ikChain[upperArm].localEulerAngles;
  59. jointRotation[handRot] = ikChain[hand].localEulerAngles;
  60. maid.body0.MuneYureL(0f);
  61. maid.body0.MuneYureR(0f);
  62. maid.body0.jbMuneL.enabled = false;
  63. maid.body0.jbMuneR.enabled = false;
  64. }
  65. protected override void Drag()
  66. {
  67. if (dragType == DragType.None) return;
  68. if (isPlaying)
  69. {
  70. maid.GetAnimation().Stop();
  71. }
  72. IKCtrlData ikData = maid.body0.IKCtrl.GetIKData("左手");
  73. Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)) + off - off2;
  74. if (dragType == DragType.RotLocalXZ)
  75. {
  76. IK.Porc(ikChain[upperArm], ikChain[foreArm], ikChain[hand], pos, Vector3.zero, ikData);
  77. // IK.Porc(ikChain[upperArm], ikChain[foreArm], ikChain[hand], pos + (pos - ikChain[hand].position), Vector3.zero, ikData);
  78. jointRotation[handRot] = ikChain[hand].localEulerAngles;
  79. jointRotation[upperArmRot] = ikChain[upperArm].localEulerAngles;
  80. ikChain[upperArm].localEulerAngles = jointRotation[upperArm];
  81. ikChain[hand].localEulerAngles = jointRotation[handRot];
  82. }
  83. }
  84. }
  85. }