using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RouteCtr : MonoBehaviour
{
///
/// 路径子物体
///
public GameObject RouteItem;
///
/// 所有路线
///
private List list_route;
[SerializeField]
private CalMap m_CalMap;
private Dictionary> m_RoutePoints;
private List m_CurrentPoints;
public List CurrentPoints
{
get { return m_CurrentPoints; }
}
private void Start()
{
list_route = new List();
m_RoutePoints = new Dictionary>();
m_CurrentPoints = new List();
}
public List List_route
{
get { return list_route; }
}
///
/// 设置路线数据
///
///
public void SetRouteValue(List navLines)
{
m_RoutePoints.Clear();
for (int i = 0; i < navLines.Count; i++)
{
List points = new List();
SettingLuJing(navLines[i], navLines[i].routerMod - 1, out points);
// 小地图显示路径
m_CalMap.SetLines(navLines[i]);
m_RoutePoints.Add(i, points);
}
}
///
/// 设置路径
///
///
/// 线段样式
private void SettingLuJing(NavLinesItem data, int routerMod, out List points)
{
points = new List();
GameObject routes = new GameObject(data.name);
routes.transform.parent = transform;
routes.transform.localPosition = Vector3.zero;
routes.transform.localEulerAngles = Vector3.zero;
for (int j = 0; j < data.lines.Count; j++)
{
var line = data.lines[j];
GameObject route = GameObject.Instantiate(RouteItem, routes.transform);
route.name = line._index.ToString();
Vector3 startPos = new Vector3((float)line.x1 / GameManager.Instance.WebMapSize.x * GameManager.Instance.MapSize.x, 0, -(float)line.y1 / GameManager.Instance.WebMapSize.y * GameManager.Instance.MapSize.y);
Vector3 endPos = new Vector3((float)line.x2 / GameManager.Instance.WebMapSize.x * GameManager.Instance.MapSize.x, 0, -(float)line.y2 / GameManager.Instance.WebMapSize.y * GameManager.Instance.MapSize.y);
route.GetComponent().SetRoute(endPos, startPos, routerMod);
route.SetActive(true);
points.Add(startPos);
if (j == data.lines.Count - 1)
{
points.Add(endPos);
}
}
list_route.Add(routes);
routes.SetActive(false);
}
///
/// 选择路线
///
///
public void SettingLuJing(int Index, bool isshow)
{
if (list_route == null || list_route.Count <= 0)
{
Debug.LogError(" 未初始化路径 或 所选的路径不存在 ");
return;
}
list_route[Index].SetActive(isshow);
m_CurrentPoints = isshow ? m_RoutePoints[Index] : m_RoutePoints[0];
}
}