| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 | using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;using System;using UnityEngine.EventSystems;public class Item0 : MonoBehaviour, IPointerDownHandler, IPointerUpHandler{    public float lastTime;    public Action onPointClick;    public Image icon;    public GameObject bg;    public Image pic;    public Text nameText;    public StaticImportant staticImp;    public GameObject bingObj;    public Sprite[] images;    public string mSpecial;    // Start is called before the first frame update    void Start()    {    }    public void InitPoint(Sprite newIcon, string name_pri, string newText, string special)    {        mSpecial = special;        if (special != "1")        {            bg.gameObject.SetActive(false);            this.GetComponentInChildren<Button>().targetGraphic = nameText;            this.GetComponent<RectTransform>().sizeDelta = new Vector2(this.GetComponent<RectTransform>().sizeDelta.x, 70);        }        else        {            switch (name_pri)            {                case "BuYuan":                    pic.GetComponent<Image>().sprite = images[0];                    break;                case "TaoKou":                    pic.GetComponent<Image>().sprite = images[1];                    break;                case "YaoKou":                    pic.GetComponent<Image>().sprite = images[2];                    break;                case "ZhuGeDi":                    pic.GetComponent<Image>().sprite = images[3];                    break;                case "YaoKouGeDi":                    pic.GetComponent<Image>().sprite = images[4];                    break;                case "ChangJiangGanDi":                    pic.GetComponent<Image>().sprite = images[5];                    break;                case "DongJingHe":                    pic.GetComponent<Image>().sprite = images[6];                    break;            }        }        nameText.text = newText;        if (name_pri.Trim().Length > 0)        {            staticImp = StaticLod.instance.staticImportantsDic[name_pri];            bingObj = staticImp.gameObject;        }        icon.sprite = newIcon;    }    void LateUpdate()    {        if (CameraManager.instance.mainCamera.GetComponent<CameraBird>().onScroll)        {            pic.GetComponent<Image>().raycastTarget = false;            nameText.raycastTarget = false;        }        else        {            pic.GetComponent<Image>().raycastTarget = true;            nameText.raycastTarget = true;        }        this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.mainCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;        float bi = CameraManager.instance.mainCamera.GetComponent<CameraBird>().currentDistance / 20;        bi = (float)Math.Clamp(bi, 0.3, 1);        this.GetComponent<RectTransform>().localScale = Vector3.one / bi;    }    public void OnPointerDown(PointerEventData eventData)    {        pic.GetComponent<Image>().color = Color.gray;        if (eventData.button == PointerEventData.InputButton.Left)        {            lastTime = Time.time;        }    }    public void OnPointerUp(PointerEventData eventData)    {        pic.GetComponent<Image>().color = Color.white;        if (eventData.button == PointerEventData.InputButton.Left)        {            if (Time.time - lastTime < 0.5f)            {                onPointClick?.Invoke();            }        }    }}
 |