168 lines
5.0 KiB
C#
168 lines
5.0 KiB
C#
/*
|
|
* 主要处理场景中显示一条路径的逻辑,比喻 跨服押镖中马车的路径
|
|
*/
|
|
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Games.GlobeDefine;
|
|
using GCGame.Table;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class SignPostManager : Singleton<SignPostManager>
|
|
{
|
|
private readonly UnityEvent Listens = new UnityEvent();
|
|
private GameObject SignCloneObj;
|
|
private readonly List<SignPost> SignPostRoots = new List<SignPost>(); //只保存每个路径的首个点 该列表一个点代表着一条路径
|
|
private GameObject SignRoadShowRoot;
|
|
private int UpdateFrameSpace; //
|
|
|
|
public GameObject Instantiate()
|
|
{
|
|
if (SignCloneObj == null)
|
|
{
|
|
InitSignGameObject();
|
|
return null;
|
|
}
|
|
|
|
if (SignRoadShowRoot == null)
|
|
SignRoadShowRoot = new GameObject("SignRoadShowRoot");
|
|
|
|
var CloneNew = Object.Instantiate(SignCloneObj);
|
|
CloneNew.transform.SetParent(SignRoadShowRoot.transform);
|
|
|
|
return CloneNew;
|
|
}
|
|
|
|
private void InitSignGameObject()
|
|
{
|
|
LoadAssetBundle.Instance.LoadGameObject(LoadAssetBundle.BUNDLE_PATH_EFFECT, "tx_ui_lubiao",
|
|
delegate(string assetName, GameObject resObj, Hashtable hashParam) { SignCloneObj = resObj; },
|
|
new Hashtable());
|
|
}
|
|
|
|
public void LeaveScene()
|
|
{
|
|
for (var i = 0; i < SignPostRoots.Count; i++) SignPostRoots[i].ClearUp();
|
|
SignPostRoots.Clear();
|
|
Listens.RemoveAllListeners();
|
|
if (SignRoadShowRoot != null)
|
|
{
|
|
Object.Destroy(SignRoadShowRoot);
|
|
SignRoadShowRoot = null;
|
|
}
|
|
|
|
GhattyCurrPosition = Vector3.zero;
|
|
GhattyCurrDestent = Vector3.zero;
|
|
GhattyCurrPathID = -1;
|
|
}
|
|
|
|
public bool CreateSignPost(int SignPostID, Vector3 TargetPos, Vector3 TargetDestant)
|
|
{
|
|
if (SignCloneObj == null)
|
|
InitSignGameObject();
|
|
for (var i = 0; i < SignPostRoots.Count; i++)
|
|
if (SignPostRoots[i].SignPostID == SignPostID)
|
|
return SignPostRoots[i].CreateSign(null, TargetDestant);
|
|
var point = new SignPost(SignPostID);
|
|
if (point.SignPostID != -1)
|
|
if (point.CreateSign(null, TargetDestant))
|
|
{
|
|
SignPostRoots.Add(point);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void TargetMove(int SignPostRootID, Vector3 TargetPosition, Vector3 TargetDestentPos,
|
|
bool CreateIfNotFind = false)
|
|
{
|
|
for (var i = 0; i < SignPostRoots.Count; i++)
|
|
if (SignPostRoots[i].SignPostID == SignPostRootID)
|
|
{
|
|
if (SignCloneObj != null)
|
|
SignPostRoots[i].ShowSign();
|
|
return;
|
|
}
|
|
|
|
if (CreateIfNotFind) CreateSignPost(SignPostRootID, TargetPosition, TargetDestentPos);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (SignCloneObj == null)
|
|
return;
|
|
if (UpdateFrameSpace > 0)
|
|
{
|
|
UpdateFrameSpace--;
|
|
return;
|
|
}
|
|
|
|
Listens.Invoke();
|
|
UpdateFrameSpace = 5; //5帧更新一次
|
|
for (var i = 0; i < SignPostRoots.Count; i++) SignPostRoots[i].Update();
|
|
}
|
|
|
|
#region //跨服押镖增加的
|
|
|
|
public Vector3 GhattyCurrPosition = Vector3.zero;
|
|
public Vector3 GhattyCurrDestent = Vector3.zero;
|
|
public int GhattyCurrPathID = -1;
|
|
|
|
public void CrossServerPost(int missionID, bool Remove)
|
|
{
|
|
if (Remove)
|
|
{
|
|
var cross = TableManager.GetCrossSerEscortConfigByID(GhattyCurrPathID);
|
|
if (cross == null)
|
|
return;
|
|
if (cross.MissionID == missionID)
|
|
{
|
|
ClearPath();
|
|
Listens.RemoveListener(ReqGharryPos);
|
|
GhattyCurrPosition = Vector3.zero;
|
|
GhattyCurrDestent = Vector3.zero;
|
|
if (CrossServerMap.Instance != null)
|
|
CrossServerMap.Instance.GharryPos();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var CrossSerEscortConfigs = TableManager.GetCrossSerEscortConfig().Values;
|
|
foreach (var config in CrossSerEscortConfigs)
|
|
if (config.MissionID == missionID)
|
|
{
|
|
ClearPath();
|
|
ReqGharryPos();
|
|
Listens.AddListener(ReqGharryPos);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ClearPath()
|
|
{
|
|
var cross = TableManager.GetCrossSerEscortConfigByID(GhattyCurrPathID);
|
|
if (cross == null)
|
|
return;
|
|
|
|
for (var i = 0; i < SignPostRoots.Count; i++)
|
|
if (SignPostRoots[i].SignPostID == cross.SignPostPath)
|
|
{
|
|
SignPostRoots[i].ClearUp();
|
|
SignPostRoots.RemoveAt(i);
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void ReqGharryPos()
|
|
{
|
|
if (GameManager.gameManager.RunningScene != GlobeVar.CROSSSERVER_SIGNPOSTSCENE)
|
|
return;
|
|
var req = new ReqCrossSerEscortInfo();
|
|
req.Flag = 1;
|
|
req.SendMsg();
|
|
}
|
|
|
|
#endregion
|
|
} |