From 8729b82472d39c1253a0f2e131f514149e115024 Mon Sep 17 00:00:00 2001 From: huyulong <1838407198@qq.com> Date: Fri, 6 Dec 2024 11:29:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9B=B8=E5=85=B3=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BB=A5=E5=8F=8A=E4=BB=BB=E5=8A=A1=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Prefabs/HYLPrefabs/Task.prefab | 26 +++++++++--- .../Assets/Prefabs/HYLPrefabs/TaskItem.cs | 41 +++++++++++++++++++ .../Prefabs/HYLPrefabs/TaskItem.cs.meta | 11 +++++ xiaofang/Assets/ProtoBuf/test.cs | 37 +++++++++++++++-- xiaofang/Assets/Res/HYLUI/TaskPanel.cs | 20 +++++++-- xiaofang/Assets/Scenes/Tmap 1.unity | 24 +++++++++-- xiaofang/Assets/Script/Item/Fire.cs | 9 ++-- .../Assets/Script/JSONReader/JSONReader.cs | 2 +- xiaofang/Assets/Script/npc/FireHydrant.cs | 3 ++ 9 files changed, 152 insertions(+), 21 deletions(-) create mode 100644 xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs create mode 100644 xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs.meta diff --git a/xiaofang/Assets/Prefabs/HYLPrefabs/Task.prefab b/xiaofang/Assets/Prefabs/HYLPrefabs/Task.prefab index d91fc219..c0d1cfdc 100644 --- a/xiaofang/Assets/Prefabs/HYLPrefabs/Task.prefab +++ b/xiaofang/Assets/Prefabs/HYLPrefabs/Task.prefab @@ -36,7 +36,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 164, y: -14} + m_AnchoredPosition: {x: 164, y: -26} m_SizeDelta: {x: 328, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &3645880154395566473 @@ -108,6 +108,7 @@ GameObject: - component: {fileID: 3645880154619645284} - component: {fileID: 557942137187336893} - component: {fileID: 6218000086705861260} + - component: {fileID: 6335157935193920567} m_Layer: 5 m_Name: Task m_TagString: Untagged @@ -131,9 +132,9 @@ RectTransform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 164, y: -25} + m_AnchorMin: {x: 0.5, y: 1} + m_AnchorMax: {x: 0.5, y: 1} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 328, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &3645880154619645285 @@ -205,7 +206,7 @@ MonoBehaviour: m_Right: 0 m_Top: 0 m_Bottom: 0 - m_ChildAlignment: 0 + m_ChildAlignment: 4 m_Spacing: 0 m_ChildForceExpandWidth: 1 m_ChildForceExpandHeight: 1 @@ -214,3 +215,18 @@ MonoBehaviour: m_ChildScaleWidth: 0 m_ChildScaleHeight: 0 m_ReverseArrangement: 0 +--- !u!114 &6335157935193920567 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3645880154619645306} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 38588f1b7a4315d4fb6983d86e935d19, type: 3} + m_Name: + m_EditorClassIdentifier: + jr: {fileID: 0} + id: 0 + tasktxt: {fileID: 3645880154395566472} diff --git a/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs b/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs new file mode 100644 index 00000000..4ffeb2a8 --- /dev/null +++ b/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class TaskItem : MonoBehaviour +{ + public JSONReader jr; + + public int id; + + public Text tasktxt; + + // Start is called before the first frame update + void Start() + { + + } + + public void SetInfo(int id,JSONReader js) + { + this.id = id; + jr = js; + UpdateTxt(); + } + + void UpdateTxt() + { + + Language info = jr.GetTaskByID(id,jr.LanguageDictionary); + + tasktxt.text = info.Text; + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs.meta b/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs.meta new file mode 100644 index 00000000..6c767b77 --- /dev/null +++ b/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 38588f1b7a4315d4fb6983d86e935d19 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/xiaofang/Assets/ProtoBuf/test.cs b/xiaofang/Assets/ProtoBuf/test.cs index 4c0ede57..58e44436 100644 --- a/xiaofang/Assets/ProtoBuf/test.cs +++ b/xiaofang/Assets/ProtoBuf/test.cs @@ -418,11 +418,40 @@ public class test : MonoBehaviour //广播 case "hall.BroadcastMessage": UserJoinResponse userJoinResponse = ProtoBufffer.DeSerialize(bytes); - Debug.Log("玩家昵称:" + userJoinResponse.NickName + ",房间:" + userJoinResponse.RoomId.ToString() + ",用户角色"+ userJoinResponse.RoleName); + + + Debug.Log(userJoinResponse.IncidentPosition); Debug.Log(userJoinResponse); - - + if(userJoinResponse.MessageType == 1)//用户上线 + { + Debug.Log("玩家:" + userJoinResponse.NickName + "上线"); + } + if(userJoinResponse.MessageType == 2)//用户下线 + { + Debug.Log("玩家:" + userJoinResponse.NickName + "下线"); + } + if(userJoinResponse.MessageType == 3)//加入房间 + { + Debug.Log("玩家" + userJoinResponse.NickName + "加入房间:" + userJoinResponse.RoomId.ToString() + ",用户角色" + userJoinResponse.RoleName); + } + if(userJoinResponse.MessageType == 4)//事故发生 + { + + } + if(userJoinResponse.MessageType == 5)//火势 + { + + } + if(userJoinResponse.MessageType == 6)//任务 + { + TaskInfoResponse taskInfoResponse = userJoinResponse.TaskResponse; + if (long.Parse(taskInfoResponse.ToUserId) == userJoinResponse.UserId)//当这个任务是这个玩家的时显示任务 + { + TaskPanel.instance.SetInfo(int.Parse(taskInfoResponse.TaskId)); + } + + } break; @@ -469,7 +498,7 @@ public class test : MonoBehaviour Debug.Log("-----------task.TaskTrigger"); TaskTrigger taskTrigger = ProtoBufffer.DeSerialize(bytes); Debug.Log(taskTrigger); - + break; //更新任务 diff --git a/xiaofang/Assets/Res/HYLUI/TaskPanel.cs b/xiaofang/Assets/Res/HYLUI/TaskPanel.cs index 89819747..ee7388f2 100644 --- a/xiaofang/Assets/Res/HYLUI/TaskPanel.cs +++ b/xiaofang/Assets/Res/HYLUI/TaskPanel.cs @@ -7,6 +7,8 @@ using DG.Tweening; public class TaskPanel : Base { + public static TaskPanel instance; + public List taskId = new List(); public Transform contentTrans; @@ -24,10 +26,10 @@ public class TaskPanel : Base // Start is called before the first frame update void Start() { - + instance = this; closeBtn.onClick.AddListener(CloseBtn); - InitTask(); + } @@ -37,10 +39,19 @@ public class TaskPanel : Base { GameObject go = GameObject.Instantiate(taskPrefab, contentTrans); go.transform.name = "Task_" + i; + TaskItem item = go.GetComponent(); + item.SetInfo(taskId[i], JSONReader); } } + public void SetInfo(int id) + { + taskId.Add(id); + InitTask(); + } + + public void CloseBtn() { if (isOpen)//关闭任务面板 @@ -64,6 +75,9 @@ public class TaskPanel : Base // Update is called once per frame void Update() { - + if(Input.GetKeyDown(KeyCode.J)) + { + SetInfo(11001); + } } } diff --git a/xiaofang/Assets/Scenes/Tmap 1.unity b/xiaofang/Assets/Scenes/Tmap 1.unity index b221e481..e211f028 100644 --- a/xiaofang/Assets/Scenes/Tmap 1.unity +++ b/xiaofang/Assets/Scenes/Tmap 1.unity @@ -6806,6 +6806,7 @@ MonoBehaviour: m_EditorClassIdentifier: retbutton: {fileID: 0} ClosureObj: {fileID: 0} + taskId: contentTrans: {fileID: 1889829591} taskPrefab: {fileID: 3645880154619645306, guid: 1a0185fc1549da647943a21145debe29, type: 3} JSONReader: {fileID: 1526740604} @@ -9267,7 +9268,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Content: {fileID: 1889829591} - m_Horizontal: 1 + m_Horizontal: 0 m_Vertical: 1 m_MovementType: 1 m_Elasticity: 0.1 @@ -21078,6 +21079,7 @@ GameObject: m_Component: - component: {fileID: 1889829591} - component: {fileID: 1889829592} + - component: {fileID: 1889829593} m_Layer: 5 m_Name: Content m_TagString: Untagged @@ -21120,17 +21122,31 @@ MonoBehaviour: m_Padding: m_Left: 0 m_Right: 0 - m_Top: 0 + m_Top: 20 m_Bottom: 0 - m_ChildAlignment: 1 + m_ChildAlignment: 4 m_Spacing: 8 m_ChildForceExpandWidth: 1 m_ChildForceExpandHeight: 1 - m_ChildControlWidth: 0 + m_ChildControlWidth: 1 m_ChildControlHeight: 0 m_ChildScaleWidth: 0 m_ChildScaleHeight: 0 m_ReverseArrangement: 0 +--- !u!114 &1889829593 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1889829590} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3} + m_Name: + m_EditorClassIdentifier: + m_HorizontalFit: 0 + m_VerticalFit: 2 --- !u!1 &1891011313 GameObject: m_ObjectHideFlags: 0 diff --git a/xiaofang/Assets/Script/Item/Fire.cs b/xiaofang/Assets/Script/Item/Fire.cs index 42950f13..1d27c475 100644 --- a/xiaofang/Assets/Script/Item/Fire.cs +++ b/xiaofang/Assets/Script/Item/Fire.cs @@ -43,15 +43,16 @@ public class Fire : MonoBehaviour HurtPeople(); - if (us.currentItem.transform.name != "NoFire" || us.currentItem == null) + if (us.currentItem == null) { return; } - else + else if(us.currentItem.transform.name != "NoFire") { - MieFire(); + return; } - + MieFire(); + } public void HurtPeople() diff --git a/xiaofang/Assets/Script/JSONReader/JSONReader.cs b/xiaofang/Assets/Script/JSONReader/JSONReader.cs index f815c329..4d772969 100644 --- a/xiaofang/Assets/Script/JSONReader/JSONReader.cs +++ b/xiaofang/Assets/Script/JSONReader/JSONReader.cs @@ -206,7 +206,7 @@ public class JSONReader : MonoBehaviour if (info.Note == "任务") { Debug.Log($"Found Language: ID = {info.ID}, Text = {info.Text}, Note = {info.Note}"); - dic.Add(id, info); + //dic.Add(id, info); return info; // 返回符合条件的 Language 数据 } else diff --git a/xiaofang/Assets/Script/npc/FireHydrant.cs b/xiaofang/Assets/Script/npc/FireHydrant.cs index 70c93d0d..d9d75a33 100644 --- a/xiaofang/Assets/Script/npc/FireHydrant.cs +++ b/xiaofang/Assets/Script/npc/FireHydrant.cs @@ -19,6 +19,9 @@ public class FireHydrant : MonoBehaviour } + + + private void OnTriggerEnter(Collider other) { xfs.gameObject.SetActive(true);