using BrewMonster; using BrewMonster.Network; using BrewMonster.Scripts.World; using BrewMonster.UI; using CSNetwork; using CSNetwork.GPDataType; using CSNetwork.GPDataType; using CSNetwork.Protocols.RPCData; using System.Data; using Unity.Cinemachine; using UnityEngine; public partial class CECGameRun : MonoBehaviour, IMsgHandler { private static CECGameRun instance; [SerializeField] private GameObject characterPrefab; [SerializeField] private CECMonster monsterPrefab; [SerializeField] private CECNPCServer npcServerPrefab; [SerializeField] private CinemachineCamera cinemachineCamera; [SerializeField] private GameObject _testVfxPrefab; //[SerializeField] private Transform ground; CECHostPlayer hostPlayer; public CinemachineFreeLook freeLookCam; public float rotateSpeedX = 300f; // tốc độ xoay ngang public float rotateSpeedY = 2f; // tốc độ xoay dọc private CECWorld m_pWorld; protected CECUIManager m_pUIManager; // UI manager public CECWorld GetWorld() { return m_pWorld; } public bool StartGame(int idInst, Vector3 vHostPos) { if (!JumpToInstance(idInst, vHostPos)) { BMLogger.LogError("CECGameRun::StartGame, Failed to create game world."); return false; } return true; } private bool JumpToInstance(int idInst, Vector3 vHostPos, int iParallelWorldID = 0) { return true; } public static CECGameRun Instance { get { if (instance == null) { instance = FindAnyObjectByType(); } return instance; } } private void Awake() { if (instance == null) { instance = this; } EC_ManMessage.RegisterHandler(this); } public void Log(string s) { Debug.LogError(s); } public CECHostPlayer GetHostPlayer() { if (hostPlayer == null) { hostPlayer = FindAnyObjectByType(); } return hostPlayer; } public void InitCharacter(cmd_self_info_1 info) { if (characterPrefab == null) { Debug.LogError("null prefab"); return; } CECPlayer.InitStaticRes(); hostPlayer = Instantiate(characterPrefab, transform).AddComponent(); hostPlayer.InitCharacter(info); cinemachineCamera.Follow = hostPlayer.transform; cinemachineCamera.ForceCameraPosition(hostPlayer.transform.position, Quaternion.identity); //Vector3 pos = new Vector3(info.pos.x, info.pos.y, info.pos.z); //Vector3 posCam = pos; //posCam.z -= 10f; //camera.transform.position = posCam; //Vector3 posGround = pos; //posGround.y -= 2f; //ground.transform.position = posGround; } public CECMonster GetMonster() { return Instantiate(monsterPrefab, transform); } public CECNPCServer GetNPCServer() { return Instantiate(npcServerPrefab, transform); } public GameObject GetTestVfx() { return Instantiate(_testVfxPrefab, transform); } public void DestroyTestVfx(GameObject go, float delayTime) { Destroy(go,delayTime); } public GameObject InitCharacter(info_player_1 info) { if (characterPrefab == null) { Debug.LogError("null prefab"); return null; } GameObject character = Instantiate(characterPrefab, transform); return character.gameObject; } private void OnDestroy() { instance = null; } public GameObject InstantiateObject(GameObject prefab) { return Instantiate(prefab, transform); } //private void Update() //{ // if (hostPlayer == null || hostPlayer.transform == null) // return; // bool rightClick = Input.GetMouseButton(1); // if (rightClick) // { // // Bật khả năng xoay khi giữ chuột phải // freeLookCam.m_XAxis.m_MaxSpeed = rotateSpeedX; // freeLookCam.m_YAxis.m_MaxSpeed = rotateSpeedY; // // Ghi giá trị chuột thủ công (nếu muốn override Input System cũ) // float mouseX = Input.GetAxis("Mouse X"); // float mouseY = Input.GetAxis("Mouse Y"); // // Xoay camera theo hướng chuột // freeLookCam.m_XAxis.Value += mouseX * Time.deltaTime * rotateSpeedX; // freeLookCam.m_YAxis.Value -= mouseY * Time.deltaTime * (rotateSpeedY / 100f); // } // else // { // // Khi thả chuột thì khoá xoay // freeLookCam.m_XAxis.m_MaxSpeed = 0; // freeLookCam.m_YAxis.m_MaxSpeed = 0; // } //} // Get UI manager public CECUIManager GetUIManager() { if(m_pUIManager == null) { m_pUIManager = CECUIManager.Instance; } return m_pUIManager; } }