AniBoneMove.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. using RootMotion.FinalIK;
  7. namespace MetaClient
  8. {
  9. public class AniBoneMove : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDragHandler
  10. {
  11. public Transform obj;
  12. public Transform target;
  13. public float dis;
  14. public Transform bone;
  15. public AniManager bonePicture;
  16. // Start is called before the first frame update
  17. public void ChangeDragImage(BonePicTarget _bonePicTarget, float _dis)
  18. {
  19. //tI = _tI;
  20. obj = _bonePicTarget.pic;
  21. target = _bonePicTarget.target;
  22. dis = _dis;
  23. bone = _bonePicTarget.bone;
  24. }
  25. public void OnDrag(PointerEventData eventData)
  26. {
  27. Vector3 imagePos = obj.transform.position;
  28. Vector3 imagePosNext = new Vector3(imagePos.x + eventData.delta.x, imagePos.y + eventData.delta.y, imagePos.z);
  29. Vector3 screenPos = Camera.main.ScreenToWorldPoint(imagePosNext);
  30. var boneParDis = Vector3.Distance(bone.transform.parent.position, screenPos);
  31. var boneDis = Vector3.Distance(bone.transform.position, bone.transform.parent.position);
  32. if ((boneDis + dis) < boneParDis)
  33. {
  34. return;
  35. }
  36. target.position = screenPos;
  37. obj.position = imagePosNext;
  38. //BoneRotateByTime boneRotateByTime = bone.gameObject.GetComponent<BoneRotateByTime>();
  39. // boneRotateByTime.NowRo();
  40. bonePicture.chooseImage.ForEach(i =>
  41. {
  42. // BoneRotateByTime boneRotateByTime = i.bone.gameObject.GetComponent<BoneRotateByTime>();
  43. // boneRotateByTime.NowRo();
  44. });
  45. bonePicture.bonePicTarget.ForEach(
  46. i =>
  47. {
  48. if (i.pic.gameObject != this.gameObject)
  49. {
  50. i.target.position = i.bone.transform.position;
  51. i.pic.position = Camera.main.WorldToScreenPoint(i.bone.transform.position);
  52. };
  53. }
  54. );
  55. }
  56. public void OnBeginDrag(PointerEventData eventData)
  57. {
  58. //LimbIK limbIK = target.gameObject.AddComponent<LimbIK>();
  59. ////limbIK.enabled = false;
  60. //limbIK.solver.bone1.transform = bone.parent.parent.transform;
  61. //limbIK.solver.bone2.transform = bone.transform;
  62. //limbIK.solver.bone3.transform = bone.GetChild(0).transform;
  63. //limbIK.solver.target = target.transform;
  64. //limbIK.solver.SetIKPositionWeight(1f);
  65. //limbIK.solver.SetIKRotationWeight(0);
  66. bonePicture.cCDIK.enabled = true;
  67. // bonePicture.MoveFun();
  68. Debug.Log("开始拖拽");
  69. }
  70. public void OnEndDrag(PointerEventData eventData)
  71. {
  72. // bonePicture.NotMoveFun();
  73. //bonePicture.cCDIK.enabled = false;
  74. ////Destroy(target.GetComponent<LimbIK>());
  75. //Debug.Log("结束拖拽");
  76. }
  77. // Update is called once per frame
  78. void Update()
  79. {
  80. }
  81. }
  82. }