From e1942ce8f5c07eb98886d8dad07d899141aa3bd0 Mon Sep 17 00:00:00 2001 From: huyulong <1838407198@qq.com> Date: Fri, 13 Dec 2024 17:19:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=8F=8A=E7=9B=B8=E5=85=B3=E8=84=9A=E6=9C=AC=E7=9A=84=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=EF=BC=8CNPC=E7=A7=BB=E5=8A=A8=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Prefabs/HYLPrefabs/TaskItem.cs | 109 ++++++------- xiaofang/Assets/ProtoBuf/test.cs | 25 ++- xiaofang/Assets/Res/HYLUI/TaskPanel.cs | 151 ++++++------------ xiaofang/Assets/Scenes/Tmap 1.unity | 15 ++ .../Assets/Script/hylScripts/TaskTarget.cs | 45 ++++++ .../Script/hylScripts/TaskTarget.cs.meta | 11 ++ .../Assets/Script/hylScripts/TestButton.cs | 1 + xiaofang/Assets/Script/npc/RecuseNpc.cs | 35 ++-- 8 files changed, 203 insertions(+), 189 deletions(-) create mode 100644 xiaofang/Assets/Script/hylScripts/TaskTarget.cs create mode 100644 xiaofang/Assets/Script/hylScripts/TaskTarget.cs.meta diff --git a/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs b/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs index 36240f90..910089e3 100644 --- a/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs +++ b/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs @@ -1,94 +1,77 @@ using System; -using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; -public enum TaskStatus +public enum TaskState { - NotAccepted, // 未接受 - InProgress, // 进行中 - Completed, // 已完成 - Failed // 失败 + NotStarted, // 未开始 + InProgress, // 进行中 + Completed, // 已完成 + Failed // 失败 } + public class TaskItem : MonoBehaviour { - public int taskId; - public string taskName; - public TaskStatus status; - public List triggers; // 存储任务触发条件 + public int taskId; // 任务ID + public string taskName; // 任务名称 + public TaskState state; // 任务状态 + public Text taskTxt; // 任务描述文本 - public JSONReader jr; + public List Targets = new List(); // 任务目标1列表 + private JSONReader jsonReader; // JSON 数据读取器 - public Text tasktxt; - - - - - - // Start is called before the first frame update - void Start() - { - - } - - //构造函数 - public TaskItem(int id, string name) + public void SetInfo(int id, JSONReader reader) { taskId = id; - taskName = name; - status = TaskStatus.NotAccepted; - triggers = new List(); + jsonReader = reader; + LoadTaskData(); } - // 设置任务状态 - public void SetStatus(TaskStatus newStatus) + private void LoadTaskData() { - status = newStatus; - } + Task_ info = jsonReader.GetTaskByID(taskId); + taskName = info.Note; + state = TaskState.NotStarted; - private void OnClickButton() - { - - } - - //初始化任务的属性 - public void SetInfo(int id,JSONReader js) - { - taskId = id; - jr = js; + //// 从JSON加载目标 + //foreach (var target in info.Targets) + //{ + // Targets.Add(new TaskTarget((TargetType)target.TargetType, target.TargetID, target.Description, target.RequiredProgress)); + //} UpdateTxt(); } - //更新Text - void UpdateTxt() + // 更新任务描述文本 + public void UpdateTxt() { + string progressInfo = ""; + foreach (var target in Targets) + { + progressInfo += $"{target.Description}: {target.CurrentProgress}/{target.RequiredProgress}\n"; + } - Task_ info = jr.GetTaskByID(taskId); - //Debug.Log(info); - tasktxt.text = info.Note; - + taskTxt.text = $"{taskName}\n{progressInfo}"; } - // 添加触发条件 - public void AddTrigger(int triggerType, string value) + // 更新任务进度 + public void UpdateProgress(TargetType targetType, string targetId, int value) { - triggers.Add(triggerType); - } + TaskTarget target = Targets.Find(t => t.Type == targetType && t.TargetID == targetId); + if (target != null) + { + target.UpdateProgress(value); + UpdateTxt(); - - // 任务完成时调用的函数 - public void OnTaskCompleted() - { - TaskPanel.instance.RemoveTask(taskId); - } - - // Update is called once per frame - void Update() - { - + // 检查是否所有目标已完成 + if (Targets.TrueForAll(t => t.IsCompleted)) + { + state = TaskState.Completed; + TaskPanel.instance.RemoveTask(taskId); + } + } } } diff --git a/xiaofang/Assets/ProtoBuf/test.cs b/xiaofang/Assets/ProtoBuf/test.cs index 67331ea7..fb1526fa 100644 --- a/xiaofang/Assets/ProtoBuf/test.cs +++ b/xiaofang/Assets/ProtoBuf/test.cs @@ -346,7 +346,24 @@ public class test : MonoBehaviour wEBScriptListener.SendMessageByte(sendData); } - + public void CreateNpcHandler() + { + NpcCreateRequest data = new NpcCreateRequest(); + data.RoomId = "168888"; + data.SceneId = "9003"; + data.TemplateId = 2; + WSMessage msg = new WSMessage(); + msg.Module = "move"; + msg.ServiceName = "CreateNpcHandler"; + msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data)); + byte[] sendData = ProtoBufffer.Serialize(msg); + WSMessage deinfo = ProtoBufffer.DeSerialize(sendData); + NpcCreateRequest login = ProtoBufffer.DeSerialize(deinfo.Data.ToByteArray()); + Debug.Log("==========消息转发函数调用"); + //BroadcastFrameMsg.FramesFieldNumber + + wEBScriptListener.SendMessageByte(sendData); + } // Start is called before the first frame update @@ -492,7 +509,7 @@ public class test : MonoBehaviour TaskInfoResponse taskInfoResponse = userJoinResponse.TaskResponse; if (long.Parse(taskInfoResponse.ToUserId) == userJoinResponse.UserId)//当这个任务是当前玩家的任务时显示任务 { - TaskPanel.instance.SetInfo(int.Parse(taskInfoResponse.TaskId)); + //TaskPanel.instance.SetInfo(int.Parse(taskInfoResponse.TaskId)); } } @@ -533,13 +550,11 @@ public class test : MonoBehaviour Vector3 position = new Vector3(x, y, z); NPCController.instance.InitNPC(position, npcData); - - } if(npcData.Type == 2)//npc移动 { Vector3 v = new Vector3(-float.Parse(npcData.X.ToString()), float.Parse(npcData.Y.ToString()), float.Parse(npcData.Z.ToString())); - foreach(var item in NPCController.instance.npcsList) + foreach(RecuseNpc item in NPCController.instance.npcsList) { if(npcData.UserId == item.npcId) { diff --git a/xiaofang/Assets/Res/HYLUI/TaskPanel.cs b/xiaofang/Assets/Res/HYLUI/TaskPanel.cs index d45f8eb4..785f185e 100644 --- a/xiaofang/Assets/Res/HYLUI/TaskPanel.cs +++ b/xiaofang/Assets/Res/HYLUI/TaskPanel.cs @@ -8,155 +8,94 @@ using System.Threading.Tasks; public class TaskPanel : Base { - - public static TaskPanel instance; - public List taskIds = new List(); + public Transform contentTrans; // 任务列表容器 + public GameObject taskPrefab; // 任务项预制体 + public JSONReader JSONReader; // JSON 数据读取类 - public Transform contentTrans; + public RectTransform buttonRect; // 按钮 RectTransform + public Button hideBtn; // 隐藏按钮 - public GameObject taskPrefab; + private bool isHidden = false; // 是否隐藏状态 + public float moveDuration = 0.5f; + public float hidePositionX = 125f; + public float showPositionX = -198f; - public JSONReader JSONReader; + private List taskItems = new List(); // 当前显示的任务列表 - public Dictionary taskDic = new Dictionary(); - - public RectTransform buttonRect; // 你的按钮 RectTransform - - - public Button hideBtn; - - private bool isHidden = false; // 用来判断按钮是否已经隐藏 - - public float moveDuration = 0.5f; // 动画持续时间 - public float hidePositionX = 125f; // 隐藏到右边的 X 坐标值,具体值根据屏幕大小调整 - public float showPositionX = -198f; // 显示时按钮的 X 坐标值 - - public List