123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using DG.Tweening;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /// <summary>
- /// 显示小地图信息
- /// </summary>
- 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;
- }
- /// <summary>
- /// 小地图上所有Image
- ///
- /// </summary>
- public List<Image> listAllPoint;
- /// <summary>
- /// 显示角色在小地图的位置 ( Position EulerAngles)
- /// </summary>
- 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);
- }
- /// <summary>
- /// 显示所有水晶点 (所有可触发交互的地方)
- /// </summary>
- /// <param name="list_Point"></param>
- public void ShowPoint(List<Vector3> list_Point)
- {
- listAllPoint = new List<Image>();
- listAllPoint.Add(mapPlayer.GetComponent<Image>());
- listAllPoint.Add(canvas.GetComponent<Image>());
- for (int i = 0; i < list_Point.Count; i++)
- {
- // Debug.Log(list_Point[i]);
- Image newPoint = Instantiate(point, canvas);
- newPoint.GetComponent<RectTransform>().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<Image>());
- }
- mapPlayer.transform.SetAsLastSibling();
- LucencyMap();
- }
- /// <summary>
- /// 显示和隐藏地图
- /// </summary>
- 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);
- }
- /// <summary>
- /// 设置地图透明度
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 地图旋转 人不动
- /// </summary>
- 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<Vector3> 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]);
- }
- }
- }
|