public class DeviceNameItem : MonoBehaviour
{
public Text Devicenametext;
public RectTransform rect;
private Camera mainCam;
private TipItemModel ItemDate;
private Vector3 mWorldTarget;
private Canvas mCanvas;
private string modelType = "";
private float distance = 0f;
private float currentAngle = 0;
private bool isHover = false;
private bool isShowLine = false;
private float MaxSizeDistance = 9;
public CanvasGroup mCanvasGroup;
private void Start()
{
mainCam = Camera.main;
rect = transform as RectTransform;
}
private void Update()
{
if (mWorldTarget==null||mCanvas==null)
{
return;
}
transform.localPosition = UnityTool.WorldToUGUILocalPosition(Camera.main, mWorldTarget, mCanvas);
distance = Vector3.Distance(mWorldTarget, mainCam.transform.position);
currentAngle = Vector3.Angle(mWorldTarget - mainCam.transform.position, mainCam.transform.forward);
currentAngle = Vector3.Angle(mWorldTarget - mainCam.transform.position, mainCam.transform.forward);
}
}
public void SetShowState(bool isShow)
{
mCanvasGroup.alpha = isShow ? 1 : 0;
mCanvasGroup.blocksRaycasts = isShow;
}
public void SetDeviceName(TipItemModel item, string modelType)
{
ItemDate = item;
this.modelType = modelType;
Devicenametext.text = item.DeviceName;
}
public void SetTarget(Vector3 worldPos, Canvas canvas)
{
mWorldTarget = worldPos;
mCanvas = canvas;
transform.localPosition = UnityTool.WorldToUGUILocalPosition(Camera.main, worldPos, canvas);
}
}```
|