PathSign.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Unity.Mathematics;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class PathSign : MonoBehaviour
  8. {
  9. public GameObject bindObj;
  10. public Vector3 bindPos;
  11. public void SetIndex(int index) {
  12. this.GetComponentInChildren<Text>().text = index.ToString();
  13. }
  14. // Update is called once per frame
  15. void LateUpdate()
  16. {
  17. if (bindObj != null)
  18. {
  19. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(bindPos) / Screen.width * 1920.0f;
  20. float alpha = this.GetComponent<RectTransform>().anchoredPosition.y < 1000 ? 1 : (1 - (this.GetComponent<RectTransform>().anchoredPosition.y - 1000) / 16);
  21. this.GetComponent<Image>().color = new Color(1, 1, 1, alpha);
  22. float dyScale = 72 / CameraManager.instance.secondCamera.GetComponent<CameraBirdSec>().currentDistance;
  23. dyScale = math.clamp(dyScale, 1, 4);
  24. this.transform.localScale = new Vector3(dyScale, dyScale, dyScale);
  25. if (!bindObj.activeSelf || !bindObj.transform.parent.gameObject.activeSelf || !bindObj.transform.parent.parent.gameObject.activeSelf)
  26. {
  27. this.GetComponent<Image>().enabled = false;
  28. this.GetComponentInChildren<Text>().enabled = false;
  29. if(this.GetComponentInChildren<Button>() != null)
  30. this.GetComponentInChildren<Button>().interactable = false;
  31. }
  32. else {
  33. this.GetComponent<Image>().enabled = true;
  34. this.GetComponentInChildren<Text>().enabled = true;
  35. if (this.GetComponentInChildren<Button>() != null)
  36. this.GetComponentInChildren<Button>().interactable = true;
  37. }
  38. }
  39. }
  40. }