1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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;
- // Start is called before the first frame update
- void Start()
- {
-
- }
- public void InitPoint(Sprite newIcon, string name_pri, string newText,string 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);
- }
- 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;
- }
- else {
- pic.GetComponent<Image>().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();
- }
- }
- }
- }
|