using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class ImageWood2 : GuideImageBase, IDragHandler, IBeginDragHandler, IEndDragHandler { public void OnBeginDrag(PointerEventData eventData) { isDraging = true; tmpImage.raycastTarget = false; GuideCtrl.Ins.BeginDrag(); } Vector3 dragPos; public void OnDrag(PointerEventData eventData) { RectTransformUtility.ScreenPointToWorldPointInRectangle(rectTransform, eventData.position, eventData.enterEventCamera, out dragPos); //dragPos.z = 0; rectTransform.position = dragPos; } public void OnEndDrag(PointerEventData eventData) { isDraging = false; if (imageWood1 != null) { //合成宝石 Debug.Log("合成宝石"); imageWood1.GetComponent().Add(); gameObject.SetActive(false); } else { rectTransform.anchoredPosition = pos; tmpImage.raycastTarget = true; //返回原位,提示开始推拽 GuideCtrl.Ins.EndDrag(); } } GameObject imageWood1; Image tmpImage; Vector2 pos; RectTransform rectTransform; //Vector3 startP; public Vector2 GetStartP { get { return pos; } } // Start is called before the first frame update private void Awake() { tmpImage = GetComponent(); rectTransform = GetComponent(); pos = rectTransform.anchoredPosition; } public override void SetTarget(GameObject target) { imageWood1 = target; } }