83 lines
2.3 KiB
C#
83 lines
2.3 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
//============================================================
|
||
//支持中文,文件使用UTF-8编码
|
||
//@author YangHua
|
||
//@create 20230426
|
||
//@company Adam
|
||
//
|
||
//@description:
|
||
//============================================================
|
||
namespace HUD
|
||
{
|
||
public enum WorldOrLocal
|
||
{
|
||
World,
|
||
Local
|
||
}
|
||
public class StationInformation : MonoBehaviour
|
||
{
|
||
//public float offsetY = 1f;
|
||
|
||
public WorldOrLocal worldOrLocal = WorldOrLocal.World;
|
||
public bool lockXZ = false;
|
||
public UnityEvent onClick;
|
||
private Transform lookAtTarget;
|
||
|
||
|
||
public void SetTarget(Transform target)
|
||
{
|
||
lookAtTarget = target;
|
||
}
|
||
|
||
public void Init(Transform parent, Bounds b)
|
||
{
|
||
transform.SetParent(parent);
|
||
transform.localPosition = Vector3.zero;
|
||
Vector3 pos = b.center;
|
||
Vector3 extentsPos = b.extents;
|
||
if (worldOrLocal == WorldOrLocal.Local)
|
||
{
|
||
//transform.localEulerAngles = Vector3.zero;
|
||
Vector3 localPos = transform.InverseTransformPoint(pos);
|
||
transform.localPosition = new Vector3(localPos.x, localPos.y + extentsPos.y, localPos.z);
|
||
}
|
||
else if (worldOrLocal == WorldOrLocal.World)
|
||
{
|
||
|
||
Vector3 localPos = transform.InverseTransformPoint(pos);
|
||
Vector3 worldPos = transform.TransformPoint(localPos);
|
||
transform.position = new Vector3(worldPos.x, worldPos.y + extentsPos.y + 1f, worldPos.z);
|
||
}
|
||
else
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
if (lookAtTarget != null)
|
||
{
|
||
Vector3 pos;
|
||
if (lockXZ)
|
||
{
|
||
pos = new Vector3(lookAtTarget.localPosition.x, 0, lookAtTarget.localPosition.z);
|
||
}
|
||
else
|
||
{
|
||
pos = lookAtTarget.localPosition;
|
||
}
|
||
transform.LookAt(pos);
|
||
}
|
||
}
|
||
|
||
private void OnMouseDown()
|
||
{
|
||
onClick?.Invoke();
|
||
}
|
||
}
|
||
}
|