| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 | 
							- using System.Collections;
 
- using System.Collections.Generic;
 
- using UnityEngine;
 
- using UnityEngine.UI;
 
- public class WeiYiIconCtrl : MonoBehaviour
 
- {
 
-     private RectTransform rect;
 
-     private Camera _camera;
 
-     
 
-     public WeiYiData _data;
 
-     private Text valueText;
 
-     private Text nameText;
 
-     public Transform targetTransForm;
 
-     
 
-     public void Init(WeiYiData data)
 
-     {
 
-         _camera = CameraManager.instance.mainCamera;
 
-         _data = data;
 
-         
 
-         rect = this.GetComponent<RectTransform>();
 
-         
 
-         rect.anchoredPosition = new Vector2(2000, 0);
 
-         nameText = this.transform.Find("nameText").GetComponent<Text>();
 
-         nameText.text = $"{_data.name}位移";
 
-         valueText = this.transform.Find("valueText").GetComponent<Text>();
 
-         valueText.text = $"{data.value} <size=12><color=FFFFFF>mm</color></size>";
 
-     }
 
-     
 
-     void Update()
 
-     {
 
-         if (targetTransForm != null)
 
-         {
 
-             if (IsObjectInCameraView(targetTransForm, _camera))
 
-             {
 
-                 rect.transform.position=_camera.WorldToScreenPoint(targetTransForm.position);
 
-             }
 
-             else
 
-             {
 
-                 rect.transform.position = new Vector3(2000, 0, 0);
 
-             }
 
-         }
 
-     }
 
-     
 
-     bool IsObjectInCameraView(Transform objectTransform, Camera camera)
 
-     {
 
-         Vector3 objectScreenPosition = camera.WorldToScreenPoint(objectTransform.position);
 
-         return objectScreenPosition.z > 0 &&
 
-                objectScreenPosition.x > 0 &&
 
-                objectScreenPosition.x < Screen.width &&
 
-                objectScreenPosition.y > 0 &&
 
-                objectScreenPosition.y < Screen.height;
 
-     }
 
- }
 
 
  |