| | |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using UnityEngine; |
| | | using UnityEngine.EventSystems; |
| | | using KTGMGemClient; |
| | | using UnityEngine.UI; |
| | | |
| | | public class ImageFire1 : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IDragHandler, IBeginDragHandler, IEndDragHandler |
| | | public class ImageFire1 : GuideImageBase, IDragHandler, IBeginDragHandler, IEndDragHandler |
| | | { |
| | | ImageFire2 imageFire2; |
| | | |
| | | public void OnPointerEnter(PointerEventData eventData) |
| | | { |
| | | if (imageFire2.IsDraging) |
| | | { |
| | | imageFire2.SetTarget(this); |
| | | } |
| | | } |
| | | |
| | | public void OnPointerExit(PointerEventData eventData) |
| | | { |
| | | if (imageFire2.IsDraging) |
| | | { |
| | | imageFire2.SetTarget(null); |
| | | } |
| | | } |
| | | |
| | | GameObject level1, level2;//等级标志 |
| | | bool canDrag;//是否可以推拽 |
| | | RectTransform rectTransform;//自身Rect |
| | | GameObject target;//推拽到塔位置的标识 |
| | | Image tmpImage;//自身图片 |
| | | Vector2 pos;//初始坐标 |
| | | GameObject levelImage; |
| | | |
| | | |
| | | // Start is called before the first frame update |
| | | void Start() |
| | | public Vector2 GetStartP |
| | | { |
| | | rectTransform = GetComponent<RectTransform>(); |
| | | |
| | | imageFire2 = transform.parent.Find("Image_Fire2").GetComponent<ImageFire2>(); |
| | | level1 = transform.Find("Image_1").gameObject; |
| | | level2 = transform.Find("Image_2").gameObject; |
| | | level2.SetActive(false); |
| | | |
| | | tmpImage = GetComponent<Image>(); |
| | | get |
| | | { |
| | | return pos; |
| | | } |
| | | } |
| | | // Start is called before the first frame update |
| | | private void Awake() |
| | | { |
| | | rectTransform = GetComponent<RectTransform>(); |
| | | pos = rectTransform.anchoredPosition; |
| | | } |
| | | tmpImage = GetComponent<Image>(); |
| | | levelImage = transform.Find("Image_1").gameObject; |
| | | |
| | | //合成宝石 |
| | | public void Add() |
| | | { |
| | | Debug.Log("合成了宝石"); |
| | | level1.SetActive(false); |
| | | level2.SetActive(true); |
| | | canDrag = true; |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.AddCard); |
| | | } |
| | | |
| | | public void SetTarget(GameObject target) |
| | | public override void SetTarget(GameObject target) |
| | | { |
| | | this.target = target; |
| | | } |
| | | |
| | | bool isDraging; |
| | | public bool IsDraging |
| | | { |
| | | get |
| | | { |
| | | return isDraging; |
| | | } |
| | | } |
| | | Vector3 dragPos;//开始拖拽的临时变量 |
| | | public void OnDrag(PointerEventData eventData) |
| | | { |
| | | if (!canDrag) |
| | | { |
| | | return; |
| | | } |
| | | RectTransformUtility.ScreenPointToWorldPointInRectangle(rectTransform, eventData.position, eventData.enterEventCamera, out dragPos); |
| | | //dragPos.z = 0; |
| | | rectTransform.position = dragPos; |
| | | } |
| | | |
| | | public void OnBeginDrag(PointerEventData eventData) |
| | | { |
| | | if (!canDrag) |
| | | { |
| | | return; |
| | | } |
| | | isDraging = true; |
| | | tmpImage.raycastTarget = false; |
| | | levelImage.SetActive(false); |
| | | |
| | | } |
| | | |
| | | public void OnEndDrag(PointerEventData eventData) |
| | | { |
| | | if (!canDrag) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | isDraging = false; |
| | | if (target != null) |
| | | { |
| | | //生成一个2级的火焰塔 |
| | | Debug.Log("生成一个2级的火焰塔"); |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.CreateFireLv2); |
| | | //生成一个1级的水元素塔 |
| | | Debug.Log("生成一个1级的火元素塔"); |
| | | gameObject.SetActive(false); |
| | | target.GetComponent<Image>().sprite = tmpImage.sprite; |
| | | //target.GetComponent<Image>().sprite = tmpImage.sprite; |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.CreateFireLv1); |
| | | } |
| | | else |
| | | { |
| | | rectTransform.anchoredPosition = pos; |
| | | levelImage.SetActive(true); |
| | | tmpImage.raycastTarget = true; |
| | | } |
| | | } |
| | | } |
| | | |