using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /// /// 显示小地图信息 /// public class TestMapShow : MonoBehaviour { public RectTransform canvas; public RectTransform mapPlayer; public RectTransform mapPlayer2; public Transform mapParent; public Image point; public Color lucency; public LineRenderer line; public RectTransform Rpoint; Vector2 startMapPos; private void Start() { startMapPos = canvas.anchoredPosition; } /// /// 小地图上所有Image /// /// public List listAllPoint; /// /// 显示角色在小地图的位置 ( Position EulerAngles) /// public void ShowPlayer( float x , float y , float rot) { Vector2 pos = new Vector2(canvas.rect.width * x > 5 ? canvas.rect.width * x : 5, canvas.rect.height * y > 5 ? canvas.rect.height * y : 5); mapPlayer.anchoredPosition = pos; mapPlayer.localRotation = Quaternion.Euler(0, 0, -rot); } /// /// 显示所有水晶点 (所有可触发交互的地方) /// /// public void ShowPoint(List list_Point) { listAllPoint = new List(); listAllPoint.Add(mapPlayer.GetComponent()); listAllPoint.Add(canvas.GetComponent()); for (int i = 0; i < list_Point.Count; i++) { // Debug.Log(list_Point[i]); Image newPoint = Instantiate(point, canvas); newPoint.GetComponent().anchoredPosition = new Vector2(canvas.rect.width * list_Point[i].x, canvas.rect.height * list_Point[i].y); // Debug.Log(" Point " + canvas.rect.width * list_Point[i].x+" "+canvas.rect.height * list_Point[i].y); newPoint.gameObject.SetActive(true); listAllPoint.Add(newPoint.GetComponent()); } mapPlayer.transform.SetAsLastSibling(); LucencyMap(); } /// /// 显示和隐藏地图 /// public void ShowMap( bool state) { for (int i = 0; i < listAllPoint.Count; i++) { listAllPoint[i].DOColor(new Color(listAllPoint[i].color.r, listAllPoint[i].color.g, listAllPoint[i].color.b, state?0: lucency.a), 1f); } line.gameObject.SetActive(!state); } /// /// 设置地图透明度 /// public void LucencyMap() { for (int i = 0; i < listAllPoint.Count; i++) { listAllPoint[i].color = new Color(listAllPoint[i].color.r, listAllPoint[i].color.g, listAllPoint[i].color.b,lucency.a); } } /// /// 地图旋转 人不动 /// public void MapRot( float x, float y , float rot) { Vector2 pos = new Vector2(canvas.rect.width * x > 5 ? canvas.rect.width * x : 5, canvas.rect.height * y > 5 ? canvas.rect.height * y : 5); mapPlayer2.anchoredPosition = pos; mapParent.localRotation = Quaternion.Euler(0, 0, rot); canvas.localRotation = Quaternion.Euler(0, 0, rot); mapPlayer2.transform.parent = mapPlayer.transform.parent; canvas.transform.parent = mapPlayer2.transform; mapPlayer2.anchoredPosition = mapPlayer.anchoredPosition; canvas.transform.parent = mapPlayer.transform.parent; mapPlayer2.transform.parent = canvas.transform; mapPlayer.transform.SetAsLastSibling(); } public void SettingMapRoute(List listMapRoutePos) { line.positionCount = 0; line.positionCount = listMapRoutePos.Count; for (int i = 0 ; i < listMapRoutePos.Count; i++) { Rpoint.anchoredPosition = new Vector3(canvas.rect.width * listMapRoutePos[i].x, canvas.rect.height * listMapRoutePos[i].y, transform.position.z); listMapRoutePos[i] = Rpoint.position; line.SetPosition(i, listMapRoutePos[i]); } } }