npc寻路逻辑完成
This commit is contained in:
parent
609550513f
commit
d46b3e56de
@ -26,7 +26,7 @@ public class test : MonoBehaviour
|
|||||||
//{
|
//{
|
||||||
// auth_login auth_Login = new auth_login();
|
// auth_login auth_Login = new auth_login();
|
||||||
// string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(auth_Login));
|
// string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(auth_Login));
|
||||||
|
|
||||||
// // 解析服务器返回的数据
|
// // 解析服务器返回的数据
|
||||||
// server serverData = JsonConvert.DeserializeObject<server>(response);
|
// server serverData = JsonConvert.DeserializeObject<server>(response);
|
||||||
// token = serverData.data.access_token;
|
// token = serverData.data.access_token;
|
||||||
@ -40,7 +40,7 @@ public class test : MonoBehaviour
|
|||||||
LoginRequest data = new LoginRequest();
|
LoginRequest data = new LoginRequest();
|
||||||
data.UserId = "1845037177556934657";
|
data.UserId = "1845037177556934657";
|
||||||
data.Account = "17311259169";
|
data.Account = "17311259169";
|
||||||
|
|
||||||
|
|
||||||
WSMessage msg = new WSMessage();
|
WSMessage msg = new WSMessage();
|
||||||
msg.Module = "hall";
|
msg.Module = "hall";
|
||||||
@ -153,7 +153,7 @@ public class test : MonoBehaviour
|
|||||||
|
|
||||||
wEBScriptListener.SendMessageByte(sendData);
|
wEBScriptListener.SendMessageByte(sendData);
|
||||||
}
|
}
|
||||||
|
|
||||||
//使用道具
|
//使用道具
|
||||||
void StartUseProp()
|
void StartUseProp()
|
||||||
{
|
{
|
||||||
@ -351,7 +351,7 @@ public class test : MonoBehaviour
|
|||||||
NpcCreateRequest data = new NpcCreateRequest();
|
NpcCreateRequest data = new NpcCreateRequest();
|
||||||
data.RoomId = "168888";
|
data.RoomId = "168888";
|
||||||
data.SceneId = "9003";
|
data.SceneId = "9003";
|
||||||
data.TemplateId = 2;
|
data.TemplateId = 2;
|
||||||
WSMessage msg = new WSMessage();
|
WSMessage msg = new WSMessage();
|
||||||
msg.Module = "move";
|
msg.Module = "move";
|
||||||
msg.ServiceName = "CreateNpcHandler";
|
msg.ServiceName = "CreateNpcHandler";
|
||||||
@ -386,7 +386,7 @@ public class test : MonoBehaviour
|
|||||||
//Location();
|
//Location();
|
||||||
//TaskTrigger();
|
//TaskTrigger();
|
||||||
//TaskUpdateRequest();
|
//TaskUpdateRequest();
|
||||||
|
|
||||||
}
|
}
|
||||||
//int index = 0;
|
//int index = 0;
|
||||||
//while (true)
|
//while (true)
|
||||||
@ -452,7 +452,7 @@ public class test : MonoBehaviour
|
|||||||
void callback(byte[] data)
|
void callback(byte[] data)
|
||||||
{
|
{
|
||||||
WSResponse deinfo = ProtoBufffer.DeSerialize<WSResponse>(data);
|
WSResponse deinfo = ProtoBufffer.DeSerialize<WSResponse>(data);
|
||||||
Debug.Log("返回数据类型:"+deinfo.MessageType);
|
Debug.Log("返回数据类型:" + deinfo.MessageType);
|
||||||
byte[] bytes = deinfo.Data.ToByteArray();
|
byte[] bytes = deinfo.Data.ToByteArray();
|
||||||
switch (deinfo.MessageType)
|
switch (deinfo.MessageType)
|
||||||
{
|
{
|
||||||
@ -463,7 +463,7 @@ public class test : MonoBehaviour
|
|||||||
LoginResponse user = ProtoBufffer.DeSerialize<LoginResponse>(bytes);
|
LoginResponse user = ProtoBufffer.DeSerialize<LoginResponse>(bytes);
|
||||||
Debug.Log(user);
|
Debug.Log(user);
|
||||||
//这里是测试阶段用的,在登录之后调用加入房间,后续会删掉
|
//这里是测试阶段用的,在登录之后调用加入房间,后续会删掉
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//进入房间
|
//进入房间
|
||||||
@ -471,7 +471,7 @@ public class test : MonoBehaviour
|
|||||||
JoinRoomResponse joinRoomResponse = ProtoBufffer.DeSerialize<JoinRoomResponse>(bytes);
|
JoinRoomResponse joinRoomResponse = ProtoBufffer.DeSerialize<JoinRoomResponse>(bytes);
|
||||||
byte[] joinByte = joinRoomResponse.Data.ToByteArray();
|
byte[] joinByte = joinRoomResponse.Data.ToByteArray();
|
||||||
PlayerJoinResponse playerJoinResponse = ProtoBufffer.DeSerialize<PlayerJoinResponse>(joinByte);
|
PlayerJoinResponse playerJoinResponse = ProtoBufffer.DeSerialize<PlayerJoinResponse>(joinByte);
|
||||||
Debug.Log("玩家:"+playerJoinResponse.UserName+"加入房间:"+playerJoinResponse.RoomId.ToString());
|
Debug.Log("玩家:" + playerJoinResponse.UserName + "加入房间:" + playerJoinResponse.RoomId.ToString());
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -481,30 +481,30 @@ public class test : MonoBehaviour
|
|||||||
UserJoinResponse userJoinResponse = ProtoBufffer.DeSerialize<UserJoinResponse>(bytes);
|
UserJoinResponse userJoinResponse = ProtoBufffer.DeSerialize<UserJoinResponse>(bytes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Debug.Log(userJoinResponse.IncidentPosition);
|
//Debug.Log(userJoinResponse.IncidentPosition);
|
||||||
Debug.Log(userJoinResponse);
|
Debug.Log(userJoinResponse);
|
||||||
if(userJoinResponse.MessageType == 1)//用户上线
|
if (userJoinResponse.MessageType == 1)//用户上线
|
||||||
{
|
{
|
||||||
Debug.Log("玩家:" + userJoinResponse.NickName + "上线");
|
Debug.Log("玩家:" + userJoinResponse.NickName + "上线");
|
||||||
}
|
}
|
||||||
if(userJoinResponse.MessageType == 2)//用户下线
|
if (userJoinResponse.MessageType == 2)//用户下线
|
||||||
{
|
{
|
||||||
Debug.Log("玩家:" + userJoinResponse.NickName + "下线");
|
Debug.Log("玩家:" + userJoinResponse.NickName + "下线");
|
||||||
}
|
}
|
||||||
if(userJoinResponse.MessageType == 3)//加入房间
|
if (userJoinResponse.MessageType == 3)//加入房间
|
||||||
{
|
{
|
||||||
Debug.Log("玩家" + userJoinResponse.NickName + "加入房间:" + userJoinResponse.RoomId.ToString() + ",用户角色" + userJoinResponse.RoleName);
|
Debug.Log("玩家" + userJoinResponse.NickName + "加入房间:" + userJoinResponse.RoomId.ToString() + ",用户角色" + userJoinResponse.RoleName);
|
||||||
}
|
}
|
||||||
if(userJoinResponse.MessageType == 4)//事故发生
|
if (userJoinResponse.MessageType == 4)//事故发生
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
if(userJoinResponse.MessageType == 5)//火势
|
if (userJoinResponse.MessageType == 5)//火势
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
if(userJoinResponse.MessageType == 6)//任务
|
if (userJoinResponse.MessageType == 6)//任务
|
||||||
{
|
{
|
||||||
TaskInfoResponse taskInfoResponse = userJoinResponse.TaskResponse;
|
TaskInfoResponse taskInfoResponse = userJoinResponse.TaskResponse;
|
||||||
if (long.Parse(taskInfoResponse.ToUserId) == userJoinResponse.UserId)//当这个任务是当前玩家的任务时显示任务
|
if (long.Parse(taskInfoResponse.ToUserId) == userJoinResponse.UserId)//当这个任务是当前玩家的任务时显示任务
|
||||||
@ -518,7 +518,7 @@ public class test : MonoBehaviour
|
|||||||
//
|
//
|
||||||
case "fps.UpFps":
|
case "fps.UpFps":
|
||||||
InputData inputData = ProtoBufffer.DeSerialize<InputData>(bytes);
|
InputData inputData = ProtoBufffer.DeSerialize<InputData>(bytes);
|
||||||
Debug.Log("Id:" + inputData.Id + ",sId :" + inputData.SId + ",X:"+ inputData.X.ToString() + ",Y:" + inputData.Y.ToString() + ",roomSeatId :" + inputData.RoomSeatId + ",z:" + inputData.Z.ToString() + ",roomId:" + inputData.RoomId);
|
Debug.Log("Id:" + inputData.Id + ",sId :" + inputData.SId + ",X:" + inputData.X.ToString() + ",Y:" + inputData.Y.ToString() + ",roomSeatId :" + inputData.RoomSeatId + ",z:" + inputData.Z.ToString() + ",roomId:" + inputData.RoomId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "prop.PickUpProp":
|
case "prop.PickUpProp":
|
||||||
@ -528,7 +528,7 @@ public class test : MonoBehaviour
|
|||||||
|
|
||||||
case "prop.StartUseProp":
|
case "prop.StartUseProp":
|
||||||
PropResponse useProp = ProtoBufffer.DeSerialize<PropResponse>(bytes);
|
PropResponse useProp = ProtoBufffer.DeSerialize<PropResponse>(bytes);
|
||||||
|
|
||||||
Debug.Log("PropId:" + useProp);
|
Debug.Log("PropId:" + useProp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -542,7 +542,7 @@ public class test : MonoBehaviour
|
|||||||
//Debug.Log("move.Location接受到了");
|
//Debug.Log("move.Location接受到了");
|
||||||
NpcData npcData = ProtoBufffer.DeSerialize<NpcData>(bytes);
|
NpcData npcData = ProtoBufffer.DeSerialize<NpcData>(bytes);
|
||||||
//Debug.Log(npcData);
|
//Debug.Log(npcData);
|
||||||
if(npcData.Type == 1)//npc创建
|
if (npcData.Type == 1)//npc创建
|
||||||
{
|
{
|
||||||
float x = -float.Parse(npcData.X.ToString());
|
float x = -float.Parse(npcData.X.ToString());
|
||||||
float y = float.Parse(npcData.Y.ToString());
|
float y = float.Parse(npcData.Y.ToString());
|
||||||
@ -551,19 +551,19 @@ public class test : MonoBehaviour
|
|||||||
|
|
||||||
NPCController.instance.InitNPC(position, npcData);
|
NPCController.instance.InitNPC(position, npcData);
|
||||||
}
|
}
|
||||||
if(npcData.Type == 2)//npc移动
|
if (npcData.Type == 2)//npc移动
|
||||||
{
|
{
|
||||||
Vector3 v = new Vector3(-float.Parse(npcData.X.ToString()), float.Parse(npcData.Y.ToString()), float.Parse(npcData.Z.ToString()));
|
Vector3 v = new Vector3(float.Parse(npcData.X.ToString()), float.Parse(npcData.Y.ToString()) + 0.5f, float.Parse(npcData.Z.ToString()));
|
||||||
foreach(RecuseNpc item in NPCController.instance.npcsList)
|
foreach (RecuseNpc item in NPCController.instance.npcsList)
|
||||||
{
|
{
|
||||||
if(npcData.UserId == item.npcId)
|
if (npcData.UserId == item.npcId)
|
||||||
{
|
{
|
||||||
Debug.Log("================" + v);
|
Debug.Log("================" + v);
|
||||||
item.SetNpcDes(v);
|
item.SetNpcDes(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//npc.transform.name = npcData.UserId;
|
//npc.transform.name = npcData.UserId;
|
||||||
//npc.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
|
//npc.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
|
||||||
//npc.transform.position = new Vector3(x, y + 0.25f, z);
|
//npc.transform.position = new Vector3(x, y + 0.25f, z);
|
||||||
@ -572,8 +572,8 @@ public class test : MonoBehaviour
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "task.InitStart":
|
case "task.InitStart":
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@ -582,7 +582,7 @@ public class test : MonoBehaviour
|
|||||||
Debug.Log("-----------task.TaskTrigger");
|
Debug.Log("-----------task.TaskTrigger");
|
||||||
TaskTrigger taskTrigger = ProtoBufffer.DeSerialize<TaskTrigger>(bytes);
|
TaskTrigger taskTrigger = ProtoBufffer.DeSerialize<TaskTrigger>(bytes);
|
||||||
Debug.Log(taskTrigger);
|
Debug.Log(taskTrigger);
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
//更新任务
|
//更新任务
|
||||||
@ -608,7 +608,7 @@ public class test : MonoBehaviour
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//case "prop.CreateNpc":
|
//case "prop.CreateNpc":
|
||||||
|
@ -111,7 +111,7 @@ NavMeshSettings:
|
|||||||
agentClimb: 0.4
|
agentClimb: 0.4
|
||||||
ledgeDropHeight: 0
|
ledgeDropHeight: 0
|
||||||
maxJumpAcrossDistance: 0
|
maxJumpAcrossDistance: 0
|
||||||
minRegionArea: 2
|
minRegionArea: 0.1
|
||||||
manualCellSize: 0
|
manualCellSize: 0
|
||||||
cellSize: 0.016666668
|
cellSize: 0.016666668
|
||||||
manualTileSize: 0
|
manualTileSize: 0
|
||||||
|
@ -61,7 +61,7 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
if (other.tag == "Player")
|
if (other.tag == "Player")
|
||||||
recusebtn.gameObject.SetActive(true);
|
recusebtn.gameObject.SetActive(true);
|
||||||
if (statebool) return;
|
if (statebool) return;
|
||||||
other.GetComponent<CharacterInturn>().cha = this.gameObject;
|
// other.GetComponent<CharacterInturn>().cha = this.gameObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTriggerExit(Collider other)
|
private void OnTriggerExit(Collider other)
|
||||||
@ -106,7 +106,7 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
|
||||||
// 继续处理NPC的状态和动画
|
// 继续处理NPC的状态和动画
|
||||||
switch (nstate)
|
switch (nstate)
|
||||||
{
|
{
|
||||||
@ -121,7 +121,7 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
SetAni(0);
|
SetAni(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log("++++++++++++++++++++++++++++" + targetPoints.Count);
|
Debug.Log("++++++++++++++++++++++++++++" + targetPoints.Count);
|
||||||
if (targetPoints.Count > 0 && currentTarget != null)
|
if (targetPoints.Count > 0 && currentTarget != null)
|
||||||
{
|
{
|
||||||
@ -172,24 +172,24 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
|
|
||||||
public void Run(Vector3 target)
|
public void Run(Vector3 target)
|
||||||
{
|
{
|
||||||
|
if (!navMeshAgent.enabled)
|
||||||
|
{
|
||||||
|
Debug.LogError("NavMeshAgent 未启用!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (navMeshAgent.isStopped)
|
if (navMeshAgent.isStopped)
|
||||||
{
|
{
|
||||||
navMeshAgent.isStopped = false; // 取消停止状态
|
navMeshAgent.isStopped = false; // 取消停止状态
|
||||||
}
|
}
|
||||||
Debug.Log("进入奔跑");
|
|
||||||
|
Debug.Log("进入奔跑状态");
|
||||||
if (movebool)
|
if (movebool)
|
||||||
{
|
{
|
||||||
// 确保目标点在 NavMesh 上
|
NavMeshPath path = new NavMeshPath();
|
||||||
NavMeshHit hit;
|
navMeshAgent.SetDestination(target);
|
||||||
if (NavMesh.SamplePosition(target, out hit, 1.0f, NavMesh.AllAreas))
|
|
||||||
{
|
SetAni(1); // 设置奔跑动画
|
||||||
navMeshAgent.SetDestination(hit.position);
|
|
||||||
SetAni(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError($"目标点 {target} 不在导航网格上");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user