wangguan
2020-11-17 8daf2a93dc9837593ccb66e52d30e093ffb6a4ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using KTGMGemClient;
 
public class ImageFire2 : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
{
    bool isDraging;
    public bool IsDraging
    {
        get
        {
            return isDraging;
        }
    }
    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 (imageFire1 != null)
        {
            //合成宝石
            Debug.Log("合成宝石");
            imageFire1.Add();
            gameObject.SetActive(false);
        }
        else
        {
            rectTransform.anchoredPosition = pos;
            tmpImage.raycastTarget = true;
 
            //返回原位,提示开始推拽
            GuideCtrl.Ins.EndDrag();
        }
 
    }
 
    ImageFire1 imageFire1;
    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()
    {
        //startP = transform.position;
 
        //imageFire1 = transform.parent.Find("Image_Fire1").GetComponent<ImageFire1>();
        tmpImage = GetComponent<Image>();
        rectTransform = GetComponent<RectTransform>();
        pos = rectTransform.anchoredPosition;
    }
 
    public void SetTarget(ImageFire1 target)
    {
        imageFire1 = target;
    }
 
}