diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs b/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs index 326f5c8132..ed496e0451 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs @@ -13,14 +13,18 @@ namespace PerfectWorld.Scripts.Managers { namespace BrewMonster.Managers { + [Serializable] public class EC_ManPlayer : IMsgHandler { public int HandlerId => (int)MANAGER_INDEX.MAN_PLAYER; public bool ProcessMessage(ECMSG Msg) { + Debug.LogWarning("HoangDev : EC_ManPlayerProcessMessage"); if (Msg.iSubID == 0) { - //EC_HostPlayer.ProcessMessage(Msg); + Debug.LogWarning("HoangDev : EC_ManPlayerEC_ManPlayerEC_ManPlayer"); + if (GameController.Instance == null) return true; + GameController.Instance.GetHostPlayer().ProcessMessage(Msg); } else if (Msg.iSubID < 0) { @@ -47,6 +51,7 @@ namespace PerfectWorld.Scripts.Managers public void OnMsgPlayerInfo(ECMSG Msg) { + Debug.LogWarning("OnMsgPlayerInfo "); int iHostID = Convert.ToInt32(Msg.dwParam3); int lenghtByte = Marshal.SizeOf(); byte[] byteArray = new byte[lenghtByte]; @@ -95,6 +100,7 @@ namespace PerfectWorld.Scripts.Managers { bool isDoneWorldRender = false; bool isDoneNPCRender = false; + Debug.Log("HostPlayerInfo1HostPlayerInfo1"); Action actLoadChar = () => { if(!isDoneNPCRender || !isDoneWorldRender) @@ -104,13 +110,18 @@ namespace PerfectWorld.Scripts.Managers GameController.Instance.InitCharacter(info); }; string nameScene = "NPCRender"; - UnityGameSession.Instance.LoadScene(nameScene, LoadSceneMode.Single, (value) => + /* UnityGameSession.Instance.LoadScene(nameScene, LoadSceneMode.Single, (value) => { isDoneNPCRender = value; actLoadChar?.Invoke(); }); nameScene = "WorldRender"; - UnityGameSession.Instance.LoadScene(nameScene, LoadSceneMode.Additive, (value) => + UnityGameSession.Instance.LoadScene(nameScene, LoadSceneMode.Additive, (value) => + { + isDoneWorldRender = value; + actLoadChar?.Invoke(); + });*/ + UnityGameSession.Instance.LoadScene("HoangTest", LoadSceneMode.Single, (value) => { isDoneWorldRender = value; actLoadChar?.Invoke(); diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index 500e26dfe7..6dfd402806 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -14,6 +14,7 @@ using UnityEngine.InputSystem; using UnityEngine.SceneManagement; using UnityEngine.UI; using Scene = UnityEngine.SceneManagement.Scene; +using System.Runtime.InteropServices; public class CECHostPlayer : MonoBehaviour { @@ -186,17 +187,26 @@ public class CECHostPlayer : MonoBehaviour switch ((int)Msg.dwMsg) { case int value when value == EC_MsgDef.MSG_HST_CORRECTPOS: OnMsgHstCorrectPos(Msg); break; + case int value when value == EC_MsgDef.MSG_HST_GOTO: OnMsgHstGoto(Msg); break; } } - - public void OnMsgHstCorrectPos(in ECMSG Msg) { Debug.Log("OnMsgHstCorrectPos"); - cmd_host_correct_pos pCmd = (cmd_host_correct_pos)Msg.dwParam1; + byte[] buf = (byte[]) Msg.dwParam1; // chỗ bạn lưu pDataBuf + GCHandle handle = GCHandle.Alloc(buf, GCHandleType.Pinned); + cmd_host_correct_pos pCmd = (cmd_host_correct_pos)Marshal.PtrToStructure( + handle.AddrOfPinnedObject(), typeof(cmd_host_correct_pos)); + handle.Free(); Debug.LogWarning("pCmd.pos " + pCmd.pos); SetPos(pCmd.pos); } + public void OnMsgHstGoto(in ECMSG Msg) + { + Debug.Log("OnMsgHstGoto"); + cmd_notify_hostpos pCmd = (cmd_notify_hostpos)Msg.dwParam1; + + } private void SetPos(Vector3 pos) { transform.position = pos; diff --git a/Assets/Scripts/EC_GPDataType.cs b/Assets/Scripts/EC_GPDataType.cs index eb2c5fc390..e9701173eb 100644 --- a/Assets/Scripts/EC_GPDataType.cs +++ b/Assets/Scripts/EC_GPDataType.cs @@ -15,6 +15,12 @@ struct cmd_host_correct_pos public Vector3 pos; public ushort stamp; }; +struct cmd_notify_hostpos +{ + public Vector3 vPos; + public int tag; + public int line; +}; enum MoveMode { GP_MOVE_WALK = 0, diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index 30029b448b..fc92235afb 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -26,10 +26,6 @@ public class GameController : MonoBehaviour } private void Awake() { - if(instance == null) - { - instance = this; - } } private void Start() @@ -43,6 +39,11 @@ public class GameController : MonoBehaviour } public CECHostPlayer GetHostPlayer() { + if(hostPlayer == null) + { + hostPlayer = FindAnyObjectByType(); + } + Debug.Log("hostPlayer " + hostPlayer); return hostPlayer; } public void InitCharacter(cmd_self_info_1 info) @@ -62,4 +63,8 @@ public class GameController : MonoBehaviour //posGround.y -= 2f; //ground.transform.position = posGround; } + private void OnDestroy() + { + instance = null; + } }