public void Init() { if (_hasInited) { return; } m_circleTrans = transform; m_arrowTrans = m_circleTrans.FindChild(m_arrowObjectName); if (m_arrowTrans != null) { m_arrowTrans.parent = null; } Transform rotatedObjTrans = m_circleTrans.FindChild(m_rotatedCircleName); if (rotatedObjTrans != null) { Quaternion.Euler(90, 360, 0); EffectObjRotatedY.AddToObj(rotatedObjTrans.gameObject, 180); } if (LoadDestEffect()) { HideDestEffect(); } if (LoadArrowEffect()) { HideArrawEffect(); } arrowAnims = new ArrowAnim[8]; arrowAnims[0] = new ArrowAnim(); arrowAnims[0].idx = 0; arrowAnims[0].timer = .21875f; arrowAnims[1] = new ArrowAnim(); arrowAnims[1].idx = 1; arrowAnims[1].timer = .1875f; arrowAnims[2] = new ArrowAnim(); arrowAnims[2].idx = 2; arrowAnims[2].timer = .15625f; arrowAnims[3] = new ArrowAnim(); arrowAnims[3].idx = 3; arrowAnims[3].timer = .125f; arrowAnims[4] = new ArrowAnim(); arrowAnims[4].idx = 4; arrowAnims[4].timer = .09375f; arrowAnims[5] = new ArrowAnim(); arrowAnims[5].idx = 5; arrowAnims[5].timer = .0625f; arrowAnims[6] = new ArrowAnim(); arrowAnims[6].idx = 6; arrowAnims[6].timer = .03125f; arrowAnims[7] = new ArrowAnim(); arrowAnims[7].idx = 7; arrowAnims[7].timer = 0f; m_bHasDestination = false; m_Destination = new AutoSearchPoint(); m_Path = new AutoSearchPath(); m_NavPath = new NavMeshPath(); _hasInited = true; }
//初始化 void Awake() { m_Path = new AutoSearchPath(); m_Path.ResetPath(); m_bIsAutoSearching = false; m_EndPointCache = new AutoSearchPoint(); //InitMapConnectPath(); }
//搜索路径算法,根据DJ算法生成最短路径 public bool FindPath(AutoSearchPoint startPoint, AutoSearchPoint endPoint, ref AutoSearchPath autoSearchPath) { List <int> path = new List <int>(); //最后生成的最短路径图 //统计所有节点,计算srcid的逆临街表,放在nodeMap中 Dictionary <int, PathNodeInfo> nodeMap = new Dictionary <int, PathNodeInfo>(); foreach (MapConnectPath connectPath in m_ConnectPath) { if (false == nodeMap.ContainsKey(connectPath.SrcSceneId)) { PathNodeInfo info = new PathNodeInfo(); info.sceneId = connectPath.SrcSceneId; info.dis = GetDisBySceneID(startPoint.SceneID, info.sceneId); info.prevNode = startPoint.SceneID; nodeMap.Add(info.sceneId, info); } if (false == nodeMap.ContainsKey(connectPath.DstSceneId)) { PathNodeInfo info = new PathNodeInfo(); info.sceneId = connectPath.DstSceneId; info.dis = GetDisBySceneID(startPoint.SceneID, info.sceneId); info.prevNode = startPoint.SceneID; nodeMap.Add(info.sceneId, info); } } List <int> openList = new List <int>(); List <int> closeList = new List <int>(); //放入开始点 openList.Add(startPoint.SceneID); while (openList.Count > 0) { int minPt = openList[0]; int minDis = m_nMinDistanceMaxValue; foreach (int openPoint in openList) { if (!nodeMap.ContainsKey(openPoint)) { continue; } if (nodeMap[openPoint].dis < minDis) { minPt = openPoint; minDis = nodeMap[openPoint].dis; } } int minDisNode = minPt; openList.Remove(minDisNode); closeList.Add(minDisNode); //展开该节点,更新所有邻接表的距离,并把下一个(或几个)最短路径上的点放入openList。 foreach (MapConnectPath connectPath in m_ConnectPath) { if (connectPath.SrcSceneId == minDisNode) { int newDis = nodeMap[minDisNode].dis + GetDisBySceneID(minDisNode, connectPath.DstSceneId); if (newDis < nodeMap[connectPath.DstSceneId].dis) { nodeMap[connectPath.DstSceneId].dis = newDis; nodeMap[connectPath.DstSceneId].prevNode = minDisNode; } if (!openList.Contains(connectPath.DstSceneId) && !closeList.Contains(connectPath.DstSceneId)) { openList.Add(connectPath.DstSceneId); } } } } if (!nodeMap.ContainsKey(endPoint.SceneID)) { return(false); } //这里生成最短路径和下一个场景号,这里的邻接表已经记录了最短路径信息 if (nodeMap[endPoint.SceneID].dis < m_nMinDistanceMaxValue) { path.Insert(0, endPoint.SceneID); int backId = nodeMap[endPoint.SceneID].prevNode; while (backId != -1) { if (backId == startPoint.SceneID) { //int nextScn = path[0]; path.Insert(0, backId); break; } path.Insert(0, backId); backId = nodeMap[backId].prevNode; } } if (path.Count > 1) { //生成路径 int beginScene = path[0]; int endScene = -1; for (int i = 1; i < path.Count; ++i) { endScene = path[i]; foreach (MapConnectPath connectPath in m_ConnectPath) { if (connectPath.SrcSceneId == beginScene && connectPath.DstSceneId == endScene) { AutoSearchPoint point = new AutoSearchPoint(connectPath.SrcSceneId, connectPath.TelePosX, connectPath.TelePosZ); autoSearchPath.AutoSearchPosCache.Add(point); beginScene = endScene; } } } //最后加入目标点 autoSearchPath.AutoSearchPosCache.Add(endPoint); return(true); } return(false); }
void UpdateMap() { if (!m_bLoadMap) { return; } Obj_MainPlayer curPlayer = Singleton <ObjManager> .GetInstance().MainPlayer; if (null == curPlayer) { return; } arrowPos = GetMapPos(curPlayer.transform.position); ObjArrow.transform.localPosition = arrowPos; arrowRot.z = -curPlayer.transform.localRotation.eulerAngles.y; ObjArrow.transform.rotation = Quaternion.Euler(arrowRot); mapPos.x = Mathf.Min(-MapScreenHalfWidth, Mathf.Max(-arrowPos.x, MapScreenHalfWidth - m_mapTexWidth)); mapPos.y = Mathf.Min(-MapScreenHalfHeight, Mathf.Max(-arrowPos.y, MapScreenHalfHeight - m_mapTexHeight)); MapClip.transform.localPosition = mapPos; if (null != LabelPos) { LabelPos.text = ((int)curPlayer.transform.position.x).ToString() + ", " + ((int)curPlayer.transform.position.z).ToString(); } if (GameManager.gameManager && GameManager.gameManager.AutoSearch && GameManager.gameManager.AutoSearch.IsAutoSearching) { AutoSearchPath path = GameManager.gameManager.AutoSearch.Path; if (path.AutoSearchPosCache.Count > 0) { AutoSearchPoint lastPoint = path.AutoSearchPosCache[path.AutoSearchPosCache.Count - 1]; if (lastPoint.SceneID == GameManager.gameManager.RunningScene) { TexTarget.transform.localPosition = GetMapPos(lastPoint.PosX, lastPoint.PosZ); } } } else { TexTarget.transform.localPosition = GetMapPos(100000, 10000); } int curFriendCount = 0; int curNeutralCount = 0; int curEnemyCount = 0; int curOtherCount = 0; foreach (Obj curObj in Singleton <ObjManager> .GetInstance().ObjPools.Values) { //MainPlayer在前面设置过位置,伙伴不显示,所以这两个排除 if (curObj.ObjType == Games.GlobeDefine.GameDefine_Globe.OBJ_TYPE.OBJ_MAIN_PLAYER || curObj.ObjType == Games.GlobeDefine.GameDefine_Globe.OBJ_TYPE.OBJ_FELLOW) { continue; } //只显示如下三种类型 if (curObj.ObjType != Games.GlobeDefine.GameDefine_Globe.OBJ_TYPE.OBJ_CHARACTER && curObj.ObjType != Games.GlobeDefine.GameDefine_Globe.OBJ_TYPE.OBJ_NPC && curObj.ObjType != Games.GlobeDefine.GameDefine_Globe.OBJ_TYPE.OBJ_OTHER_PLAYER) { continue; } Obj_Character curChar = curObj as Obj_Character; if (null == curChar) { continue; } if (curObj.ObjType == Games.GlobeDefine.GameDefine_Globe.OBJ_TYPE.OBJ_NPC) { if (Singleton <ObjManager> .GetInstance().DeleteNPCList != null) { if (Singleton <ObjManager> .GetInstance().DeleteNPCList.ContainsKey(curObj.ServerID.ToString())) { continue; } } } float xPosDiff = curChar.transform.localPosition.x - curPlayer.transform.localPosition.x; float yPosDiff = curChar.transform.localPosition.z - curPlayer.transform.localPosition.z; if (Mathf.Abs(xPosDiff) * m_scale > MapScreenHalfWidth || Mathf.Abs(yPosDiff) * m_scale > MapScreenHalfHeight) { continue; } CharacterDefine.REPUTATION_TYPE type = Reputation.GetObjReputionType(curChar); if (CharacterDefine.REPUTATION_TYPE.REPUTATION_FRIEND == type) { AddDotToList(TexListFriend, curFriendCount, FriendPoint, curObj.gameObject, CharacterDefine.NPC_COLOR_FRIEND); curFriendCount++; } else if (CharacterDefine.REPUTATION_TYPE.REPUTATION_NEUTRAL == type) { AddDotToList(TexListNeutral, curNeutralCount, NeutralPoint, curObj.gameObject, CharacterDefine.NPC_COLOR_NEUTRAL); curNeutralCount++; } else if (CharacterDefine.REPUTATION_TYPE.REPUTATION_HOSTILE == type) { AddDotToList(TexListEnemy, curEnemyCount, EnemyPoint, curObj.gameObject, CharacterDefine.NPC_COLOR_ENEMY); curEnemyCount++; } else { AddDotToList(TexListOther, curOtherCount, OtherPoint, curObj.gameObject, Color.white); curOtherCount++; } } DeActiveList(curFriendCount, TexListFriend, arrowPos); DeActiveList(curNeutralCount, TexListNeutral, arrowPos); DeActiveList(curEnemyCount, TexListEnemy, arrowPos); DeActiveList(curOtherCount, TexListOther, arrowPos); }