1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- using RootMotion.FinalIK;
- namespace MetaClient
- {
- public class AniBoneMove : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDragHandler
- {
- public Transform obj;
- public Transform target;
- public float dis;
- public Transform bone;
- public AniManager bonePicture;
- // Start is called before the first frame update
- public void ChangeDragImage(BonePicTarget _bonePicTarget, float _dis)
- {
- //tI = _tI;
- obj = _bonePicTarget.pic;
- target = _bonePicTarget.target;
- dis = _dis;
- bone = _bonePicTarget.bone;
- }
- public void OnDrag(PointerEventData eventData)
- {
- Vector3 imagePos = obj.transform.position;
- Vector3 imagePosNext = new Vector3(imagePos.x + eventData.delta.x, imagePos.y + eventData.delta.y, imagePos.z);
- Vector3 screenPos = Camera.main.ScreenToWorldPoint(imagePosNext);
- var boneParDis = Vector3.Distance(bone.transform.parent.position, screenPos);
- var boneDis = Vector3.Distance(bone.transform.position, bone.transform.parent.position);
- if ((boneDis + dis) < boneParDis)
- {
- return;
- }
- target.position = screenPos;
- obj.position = imagePosNext;
- //BoneRotateByTime boneRotateByTime = bone.gameObject.GetComponent<BoneRotateByTime>();
- // boneRotateByTime.NowRo();
- bonePicture.chooseImage.ForEach(i =>
- {
- // BoneRotateByTime boneRotateByTime = i.bone.gameObject.GetComponent<BoneRotateByTime>();
- // boneRotateByTime.NowRo();
- });
- bonePicture.bonePicTarget.ForEach(
- i =>
- {
- if (i.pic.gameObject != this.gameObject)
- {
- i.target.position = i.bone.transform.position;
- i.pic.position = Camera.main.WorldToScreenPoint(i.bone.transform.position);
- };
- }
- );
- }
- public void OnBeginDrag(PointerEventData eventData)
- {
- //LimbIK limbIK = target.gameObject.AddComponent<LimbIK>();
- ////limbIK.enabled = false;
- //limbIK.solver.bone1.transform = bone.parent.parent.transform;
- //limbIK.solver.bone2.transform = bone.transform;
- //limbIK.solver.bone3.transform = bone.GetChild(0).transform;
- //limbIK.solver.target = target.transform;
- //limbIK.solver.SetIKPositionWeight(1f);
- //limbIK.solver.SetIKRotationWeight(0);
- bonePicture.cCDIK.enabled = true;
- // bonePicture.MoveFun();
- Debug.Log("开始拖拽");
- }
- public void OnEndDrag(PointerEventData eventData)
- {
- // bonePicture.NotMoveFun();
- //bonePicture.cCDIK.enabled = false;
- ////Destroy(target.GetComponent<LimbIK>());
- //Debug.Log("结束拖拽");
- }
- // Update is called once per frame
- void Update()
- {
- }
- }
- }
|