2021-04-15 10:13:01 +08:00
|
|
|
|
using Mapbox.Unity.Map;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MiniMapPlayerController: MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
private AbstractPlayer _player;
|
|
|
|
|
|
private AbstractMap _map;
|
2021-05-14 16:11:22 +08:00
|
|
|
|
RectTransform RectRoot;
|
|
|
|
|
|
GameObject arrow;
|
|
|
|
|
|
Camera _minicamera;
|
2021-04-15 10:13:01 +08:00
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
_map = transform.parent.Find("MiniMap").GetComponent<AbstractMap>();
|
2021-05-14 16:11:22 +08:00
|
|
|
|
_minicamera = transform.parent.Find("MiniCamera").GetComponent<Camera>();
|
|
|
|
|
|
RectRoot = transform.parent.Find("SingleUI/Panel/MiniMap/MiniMap").GetComponent<RectTransform>();
|
|
|
|
|
|
var parent = transform.parent.Find("SingleUI/Panel/MiniMap/MiniMap");
|
|
|
|
|
|
arrow = Instantiate(Resources.Load<GameObject>("UI/Prefab/Ride/MiniArrow"), parent);
|
2021-04-15 10:13:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
public void SetController(AbstractPlayer player)
|
|
|
|
|
|
{
|
|
|
|
|
|
_player = player;
|
|
|
|
|
|
}
|
|
|
|
|
|
float t = 1f;
|
|
|
|
|
|
private void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
t -= Time.deltaTime;
|
|
|
|
|
|
while (t < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_player != null)
|
|
|
|
|
|
{
|
2021-04-19 14:38:31 +08:00
|
|
|
|
transform.localPosition = _map.GeoToWorldPosition(_player.Currentlatlong);
|
2021-05-14 16:11:22 +08:00
|
|
|
|
var tr = arrow.GetComponent<RectTransform>();
|
|
|
|
|
|
Vector2 vp2 = _minicamera.WorldToViewportPoint(transform.localPosition);//将三维物体的世界坐标转换为视口坐标
|
|
|
|
|
|
tr.anchoredPosition = new Vector2((vp2.x * RectRoot.sizeDelta.x) - (RectRoot.sizeDelta.x * 0.5f), (vp2.y * RectRoot.sizeDelta.y) - (RectRoot.sizeDelta.y * 0.5f));
|
2021-04-15 10:13:01 +08:00
|
|
|
|
}
|
2021-05-20 15:55:27 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DestroyImmediate(arrow);
|
|
|
|
|
|
//DestroyImmediate(gameObject);
|
|
|
|
|
|
}
|
2021-04-15 10:13:01 +08:00
|
|
|
|
t = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|