156 lines
4.4 KiB
C#
156 lines
4.4 KiB
C#
//**********************************************//
|
|
//作者:#AUTHOR#
|
|
//日期:#DATE#
|
|
//简述:#DESCRIPTION#
|
|
//*********************************************//
|
|
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Thousandto.Cfg.Data;
|
|
using Thousandto.Plugins.Common.UniScene;
|
|
using Thousandto.Code.Logic;
|
|
using System.Threading;
|
|
using Thousandto.Core.Base;
|
|
|
|
namespace Thousandto.Code.Global
|
|
{
|
|
/// <summary>
|
|
/// 玩家自动寻路系统--高层逻辑寻路,跨场景寻路处理
|
|
/// 其中包括切换场景,寻找某个地点,或者寻找某个NPC等.
|
|
/// </summary>
|
|
public class PathFinderSystem
|
|
{
|
|
#region //私有变量
|
|
private MapPathInfo mapPathInfo;
|
|
private Thread _loadThread = null;
|
|
#endregion
|
|
|
|
#region//公共接口
|
|
public void Initialize()
|
|
{
|
|
mapPathInfo = new MapPathInfo();
|
|
mapPathInfo.Initialize();
|
|
}
|
|
|
|
public void Uninitialize()
|
|
{
|
|
mapPathInfo = null;
|
|
if (_loadThread != null)
|
|
{
|
|
_loadThread.Abort();
|
|
_loadThread = null;
|
|
}
|
|
}
|
|
|
|
//private static void LoadThread(object obj,object sender=null)
|
|
//{
|
|
// MapPathInfo info = obj as MapPathInfo;
|
|
// if (info != null)
|
|
// {
|
|
// System.Diagnostics.Trace.Write("Load MapPathInfo Start");
|
|
// info.Initialize();
|
|
// System.Diagnostics.Trace.Write("Load MapPathInfo Finish");
|
|
// }
|
|
//}
|
|
|
|
// 获取到下一地图的传送点
|
|
|
|
|
|
public bool GetTeleport(int from, int to, ref Vector3 outVec)
|
|
{
|
|
if (!mapPathInfo.IsLoadFinish)
|
|
return false;
|
|
|
|
return mapPathInfo.GetTeleport(from, to, ref outVec);
|
|
}
|
|
|
|
// 获取到目标地图需要穿过的地图列表
|
|
public List<int> FindThroughMaps(int from, int to)
|
|
{
|
|
if (!mapPathInfo.IsLoadFinish)
|
|
return new List<int>();
|
|
|
|
return mapPathInfo.FindThroughMaps(from, to);
|
|
}
|
|
|
|
// 获取NPC坐标
|
|
public MapPathInfo.Position GetNpcPosition(int npcId)
|
|
{
|
|
if (!mapPathInfo.IsLoadFinish)
|
|
return null;
|
|
return mapPathInfo.GetNpcPosition(npcId);
|
|
}
|
|
|
|
//增加NPC坐标
|
|
public void AddNpcPosition(int npcId,MapPathInfo.Position pos)
|
|
{
|
|
mapPathInfo.AddNpcPosition(npcId, pos);
|
|
}
|
|
|
|
//判断是否存在npcId
|
|
public bool IsExitNpcPos(int npcId)
|
|
{
|
|
return mapPathInfo.IsExitNpcPos(npcId);
|
|
}
|
|
|
|
// 获取怪物坐标
|
|
public MapPathInfo.Position GetMonsterPosition(int monsterId, int campid = 0)
|
|
{
|
|
if (!mapPathInfo.IsLoadFinish)
|
|
return null;
|
|
var list = mapPathInfo.GetMonsterPosition(monsterId,campid);
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return list[Random.Range(0, list.Count - 1)];
|
|
}
|
|
|
|
// 获取采集坐标
|
|
public MapPathInfo.Position GetCollectPosition(int collectId, int campid = 0)
|
|
{
|
|
if (!mapPathInfo.IsLoadFinish)
|
|
return null;
|
|
var list = mapPathInfo.GetCollectPosition(collectId, campid);
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
int index = Random.Range(0, list.Count);
|
|
return list[index];
|
|
}
|
|
|
|
//获取复活点坐标
|
|
public Vector2 GetSpawnPosition(int mapID)
|
|
{
|
|
if (!mapPathInfo.IsLoadFinish)
|
|
return Vector2.zero;
|
|
List<Vector2> list = mapPathInfo.GetSpawnPosition(mapID);
|
|
if (list != null && list.Count > 0)
|
|
{
|
|
return list[0];
|
|
}
|
|
return Vector2.zero;
|
|
}
|
|
|
|
//获取地图信息
|
|
public MapPathInfo.MapObjInfo GetMapObjInfo(int mapID)
|
|
{
|
|
if (!mapPathInfo.IsLoadFinish)
|
|
return null;
|
|
return mapPathInfo.GetMapObjInfo(mapID);
|
|
}
|
|
|
|
//载入一张地图的信息
|
|
public void LoadSingleMapInfo(DeclareMapsetting cfg)
|
|
{
|
|
if(mapPathInfo != null)
|
|
{
|
|
mapPathInfo.LoadSingleMap(cfg);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|