Merge branch 'develop' into feature/inventory
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8042a2d38498a7d44b8570ef149ec540
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,139 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Unity.BossRoom.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Class that permits auto-loading a bootstrap scene when the editor switches play state. This class is
|
||||
/// initialized when Unity is opened and when scripts are recompiled. This is to be able to subscribe to
|
||||
/// EditorApplication's playModeStateChanged event, which is when we wish to open a new scene.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A critical edge case scenario regarding NetworkManager is accounted for here.
|
||||
/// A NetworkObject's GlobalObjectIdHash value is currently generated in OnValidate() which is invoked during a
|
||||
/// build and when the asset is loaded/viewed in the editor.
|
||||
/// If we were to manually open Bootstrap scene via EditorSceneManager.OpenScene(...) as the editor is exiting play
|
||||
/// mode, Bootstrap scene would be entering play mode within the editor prior to having loaded any assets, meaning
|
||||
/// NetworkManager itself has no entry within the AssetDatabase cache. As a result of this, any referenced Network
|
||||
/// Prefabs wouldn't have any entry either.
|
||||
/// To account for this necessary AssetDatabase step, whenever we're redirecting from a new scene, or a scene
|
||||
/// existing in our EditorBuildSettings, we forcefully stop the editor, open Bootstrap scene, and re-enter play
|
||||
/// mode. This provides the editor the chance to create AssetDatabase cache entries for the Network Prefabs assigned
|
||||
/// to the NetworkManager.
|
||||
/// If we are entering play mode directly from Bootstrap scene, no additional steps need to be taken and the scene
|
||||
/// is loaded normally.
|
||||
/// </remarks>
|
||||
[InitializeOnLoad]
|
||||
public class SceneBootstrapper
|
||||
{
|
||||
const string k_PreviousSceneKey = "PreviousScene";
|
||||
const string k_ShouldLoadBootstrapSceneKey = "LoadMainMenuScene";
|
||||
|
||||
const string k_LoadBootstrapSceneOnPlay = "FirstSceneLoad/Load MainMenu Scene On Play";
|
||||
const string k_DoNotLoadBootstrapSceneOnPlay = "FirstSceneLoad/Don't Load MainMenu Scene On Play";
|
||||
|
||||
const string k_TestRunnerSceneName = "InitTestScene";
|
||||
|
||||
static bool s_RestartingToSwitchScene;
|
||||
|
||||
static string BootstrapScene => EditorBuildSettings.scenes[0].path;
|
||||
|
||||
static string PreviousScene
|
||||
{
|
||||
get => EditorPrefs.GetString(k_PreviousSceneKey);
|
||||
set => EditorPrefs.SetString(k_PreviousSceneKey, value);
|
||||
}
|
||||
|
||||
static bool ShouldLoadBootstrapScene
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!EditorPrefs.HasKey(k_ShouldLoadBootstrapSceneKey))
|
||||
{
|
||||
EditorPrefs.SetBool(k_ShouldLoadBootstrapSceneKey, true);
|
||||
}
|
||||
return EditorPrefs.GetBool(k_ShouldLoadBootstrapSceneKey, true);
|
||||
}
|
||||
set => EditorPrefs.SetBool(k_ShouldLoadBootstrapSceneKey, value);
|
||||
}
|
||||
|
||||
static SceneBootstrapper()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += EditorApplicationOnplayModeStateChanged;
|
||||
}
|
||||
|
||||
[MenuItem(k_LoadBootstrapSceneOnPlay, true)]
|
||||
static bool ShowLoadBootstrapSceneOnPlay() => !ShouldLoadBootstrapScene;
|
||||
|
||||
[MenuItem(k_LoadBootstrapSceneOnPlay)]
|
||||
static void EnableLoadBootstrapSceneOnPlay() => ShouldLoadBootstrapScene = true;
|
||||
|
||||
[MenuItem(k_DoNotLoadBootstrapSceneOnPlay, true)]
|
||||
static bool ShowDoNotLoadBootstrapSceneOnPlay() => ShouldLoadBootstrapScene;
|
||||
|
||||
[MenuItem(k_DoNotLoadBootstrapSceneOnPlay)]
|
||||
static void DisableDoNotLoadBootstrapSceneOnPlay() => ShouldLoadBootstrapScene = false;
|
||||
|
||||
static void EditorApplicationOnplayModeStateChanged(PlayModeStateChange playModeStateChange)
|
||||
{
|
||||
if (IsTestRunnerActive() || !ShouldLoadBootstrapScene)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_RestartingToSwitchScene)
|
||||
{
|
||||
if (playModeStateChange == PlayModeStateChange.EnteredPlayMode)
|
||||
{
|
||||
s_RestartingToSwitchScene = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (playModeStateChange == PlayModeStateChange.ExitingEditMode)
|
||||
{
|
||||
PreviousScene = EditorSceneManager.GetActiveScene().path;
|
||||
|
||||
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
||||
{
|
||||
if (!string.IsNullOrEmpty(BootstrapScene) &&
|
||||
System.Array.Exists(EditorBuildSettings.scenes, scene => scene.path == BootstrapScene))
|
||||
{
|
||||
s_RestartingToSwitchScene = true;
|
||||
EditorApplication.isPlaying = false;
|
||||
|
||||
// Đóng tất cả các scene đang mở
|
||||
for (int i = SceneManager.sceneCount - 1; i >= 0; i--)
|
||||
{
|
||||
Scene scene = SceneManager.GetSceneAt(i);
|
||||
if (scene.isLoaded)
|
||||
{
|
||||
EditorSceneManager.CloseScene(scene, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Mở scene đầu tiên trong danh sách build
|
||||
EditorSceneManager.OpenScene(BootstrapScene);
|
||||
|
||||
EditorApplication.isPlaying = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorApplication.isPlaying = false;
|
||||
}
|
||||
}
|
||||
else if (playModeStateChange == PlayModeStateChange.EnteredEditMode && !string.IsNullOrEmpty(PreviousScene))
|
||||
{
|
||||
EditorSceneManager.OpenScene(PreviousScene);
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsTestRunnerActive()
|
||||
{
|
||||
return EditorSceneManager.GetActiveScene().name.StartsWith(k_TestRunnerSceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 614cce81bc9884a438600443cd510338
|
||||
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
public class QuickSceneWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("GameObject/Quick Open Adaptive Scene", false, 1)]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
var window = GetWindow<QuickSceneWindow>("Quick Scene");
|
||||
// Kích thước cửa sổ
|
||||
float width = 250;
|
||||
float height = 300;
|
||||
|
||||
// Lấy kích thước màn hình Unity Editor
|
||||
float screenWidth = EditorGUIUtility.GetMainWindowPosition().width;
|
||||
float screenHeight = EditorGUIUtility.GetMainWindowPosition().height;
|
||||
|
||||
// Tính toán vị trí để căn giữa
|
||||
float x = (screenWidth - width) / 2;
|
||||
float y = (screenHeight - height) / 2;
|
||||
|
||||
// Đặt vị trí và kích thước cho cửa sổ
|
||||
window.position = new Rect(x, y, width, height);
|
||||
window.Show();
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
EditorGUILayout.LabelField("Available Scenes:", EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
var scenes = EditorBuildSettings.scenes;
|
||||
string currentScenePath = EditorSceneManager.GetActiveScene().path;
|
||||
|
||||
if (scenes.Length == 0)
|
||||
{
|
||||
EditorGUILayout.HelpBox("No Scenes in Build Settings", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
// Lọc ra các scene không phải scene hiện tại
|
||||
var availableScenes = scenes.Where(scene =>
|
||||
scene.enabled &&
|
||||
!string.Equals(scene.path, currentScenePath, System.StringComparison.OrdinalIgnoreCase)
|
||||
);
|
||||
|
||||
if (!availableScenes.Any())
|
||||
{
|
||||
EditorGUILayout.HelpBox("No other scenes available", MessageType.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var scene in availableScenes)
|
||||
{
|
||||
string sceneName = Path.GetFileNameWithoutExtension(scene.path);
|
||||
if (GUILayout.Button(sceneName, GUILayout.Height(30)))
|
||||
{
|
||||
OpenSceneAdditively(scene.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenSceneAdditively(string path)
|
||||
{
|
||||
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
||||
{
|
||||
EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
|
||||
Debug.Log($"Opened scene additively: {path}");
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1739d340501e2b641b3c8d53dfddce7e
|
||||
@@ -16,7 +16,6 @@ namespace PerfectWorld.Scripts.Managers
|
||||
public class EC_ManPlayer : IMsgHandler
|
||||
{
|
||||
public int HandlerId => (int)MANAGER_INDEX.MAN_PLAYER;
|
||||
//public EC_HostPlayer EC_HostPlayer;
|
||||
public bool ProcessMessage(ECMSG Msg)
|
||||
{
|
||||
if (Msg.iSubID == 0)
|
||||
|
||||
@@ -5,9 +5,10 @@ using PerfectWorld.Scripts.Managers.BrewMonster.Managers;
|
||||
|
||||
namespace BrewMonster
|
||||
{
|
||||
[Serializable]
|
||||
public class EC_ManMessageMono : MonoBehaviour
|
||||
{
|
||||
EC_ManPlayer EC_ManPlayer;
|
||||
public EC_ManPlayer EC_ManPlayer;
|
||||
private void Awake()
|
||||
{
|
||||
//TODO: Remove later
|
||||
|
||||
@@ -5,6 +5,7 @@ using CSNetwork.Protocols;
|
||||
using CSNetwork.Protocols.RPCData;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace BrewMonster.UI
|
||||
|
||||
@@ -99,19 +99,18 @@ MonoBehaviour:
|
||||
m_GameObject: {fileID: 6513559496054861882}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c0525de198450e14f9f6ad854b95ec99, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: c0911af06fee458459c86236ea21b716, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
txtName: {fileID: 0}
|
||||
controller: {fileID: 2967440448469171042}
|
||||
animator: {fileID: 0}
|
||||
joystick: {fileID: 0}
|
||||
btnJump: {fileID: 0}
|
||||
btnRun: {fileID: 0}
|
||||
parentModel: {fileID: 78581589932911603}
|
||||
parentModel: {fileID: 0}
|
||||
extraGroundDistance: 0.05
|
||||
radiusEpsilon: 0.005
|
||||
groundMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 1
|
||||
m_Bits: 0
|
||||
slopeToleranceDeg: 2
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9172bad49fed35e46819504e93c44a84
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +1,11 @@
|
||||
using CSNetwork.GPDataType;
|
||||
using BrewMonster.Network;
|
||||
using CSNetwork;
|
||||
using CSNetwork.GPDataType;
|
||||
using CSNetwork.C2SCommand;
|
||||
using CSNetwork.Protocols;
|
||||
using CSNetwork.Protocols.RPCData;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
using UnityEditor.SearchService;
|
||||
@@ -10,11 +15,10 @@ using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using Scene = UnityEngine.SceneManagement.Scene;
|
||||
|
||||
public class CharacterCtrl : MonoBehaviour
|
||||
public class CECHostPlayer : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TextMeshPro txtName;
|
||||
[SerializeField] private CharacterController controller;
|
||||
[SerializeField] private Animator animator;
|
||||
|
||||
[SerializeField] private Joystick joystick;
|
||||
[SerializeField] private Button btnJump;
|
||||
@@ -23,6 +27,7 @@ public class CharacterCtrl : MonoBehaviour
|
||||
|
||||
PlayerStateMachine playerStateMachine;
|
||||
PlayerMoveState moveState;
|
||||
CECHostMove m_MoveCtrl;
|
||||
|
||||
float playerSpeed = 5.0f;
|
||||
float jumpHeight = 1.5f;
|
||||
@@ -32,6 +37,7 @@ public class CharacterCtrl : MonoBehaviour
|
||||
bool isGrounded = false;
|
||||
bool isRun = false;
|
||||
GameObject modle;
|
||||
Vector3 m_vLastSevPos;
|
||||
|
||||
// ====== Ground cast config ======
|
||||
[Header("Ground Cast")]
|
||||
@@ -52,6 +58,7 @@ public class CharacterCtrl : MonoBehaviour
|
||||
{
|
||||
moveState = new PlayerMoveState(this);
|
||||
playerStateMachine = new PlayerStateMachine();
|
||||
m_MoveCtrl = new CECHostMove(this);
|
||||
|
||||
// Cache: không bắt buộc, nhưng gọn tay và ít gọi property lặp.
|
||||
if (controller != null)
|
||||
@@ -78,6 +85,7 @@ public class CharacterCtrl : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
m_MoveCtrl.Tick(Time.deltaTime);
|
||||
// Nếu có thay đổi runtime, có thể lấy lại mỗi vài giây/Start nếu bạn thích:
|
||||
// ccRadius = controller.radius; ccSkin = controller.skinWidth;
|
||||
|
||||
@@ -115,12 +123,13 @@ public class CharacterCtrl : MonoBehaviour
|
||||
if (move != Vector3.zero)
|
||||
{
|
||||
transform.forward = move;
|
||||
if (isRun) SetAnimRun();
|
||||
else SetAnimWalk();
|
||||
Debug.LogWarning("HoangDev :HandleMovement");
|
||||
m_MoveCtrl.GroundMove(Time.deltaTime);
|
||||
m_MoveCtrl.SendMoveCmd(transform.position, controller.velocity, (int)MoveMode.GP_MOVE_WALK);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetAnimIdle();
|
||||
|
||||
}
|
||||
|
||||
Vector3 finalMove = (move * playerSpeed) + (playerVelocity.y * Vector3.up);
|
||||
@@ -170,10 +179,28 @@ public class CharacterCtrl : MonoBehaviour
|
||||
if (isGrounded)
|
||||
{
|
||||
playerVelocity.y = Mathf.Sqrt(jumpHeight * -2f * gravityValue);
|
||||
SetAnimJump();
|
||||
}
|
||||
}
|
||||
|
||||
public void ProcessMessage(in ECMSG Msg)
|
||||
{
|
||||
switch ((int)Msg.dwMsg)
|
||||
{
|
||||
case int value when value == EC_MsgDef.MSG_HST_CORRECTPOS: OnMsgHstCorrectPos(Msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnMsgHstCorrectPos(in ECMSG Msg)
|
||||
{
|
||||
Debug.Log("OnMsgHstCorrectPos");
|
||||
cmd_host_correct_pos pCmd = (cmd_host_correct_pos)Msg.dwParam1;
|
||||
Debug.LogWarning("pCmd.pos " + pCmd.pos);
|
||||
SetPos(pCmd.pos);
|
||||
}
|
||||
private void SetPos(Vector3 pos)
|
||||
{
|
||||
transform.position = pos;
|
||||
}
|
||||
public void SetStatusRun(bool value)
|
||||
{
|
||||
if (!isGrounded)
|
||||
@@ -183,7 +210,6 @@ public class CharacterCtrl : MonoBehaviour
|
||||
}
|
||||
isRun = value;
|
||||
}
|
||||
|
||||
public void InitCharacter(cmd_self_info_1 role)
|
||||
{
|
||||
string roleName = "(Error decoding name)";
|
||||
@@ -196,35 +222,7 @@ public class CharacterCtrl : MonoBehaviour
|
||||
transform.position = pos;
|
||||
SetModelHostPlayer();
|
||||
Debug.LogError("Pos Character = " + pos);
|
||||
}
|
||||
|
||||
private void SetAnimIdle()
|
||||
{
|
||||
if (stateAnim == StateAnim.Idle || !isGrounded) return;
|
||||
stateAnim = StateAnim.Idle;
|
||||
animator.SetTrigger("Idle");
|
||||
}
|
||||
|
||||
private void SetAnimRun()
|
||||
{
|
||||
if (stateAnim == StateAnim.Run || !isGrounded) return;
|
||||
stateAnim = StateAnim.Run;
|
||||
animator.SetTrigger("Run");
|
||||
}
|
||||
|
||||
private void SetAnimWalk()
|
||||
{
|
||||
if (stateAnim == StateAnim.Walk || !isGrounded) return;
|
||||
stateAnim = StateAnim.Walk;
|
||||
animator.SetTrigger("Walk");
|
||||
}
|
||||
|
||||
private void SetAnimJump()
|
||||
{
|
||||
if (stateAnim == StateAnim.Jump) return;
|
||||
stateAnim = StateAnim.Jump;
|
||||
// Tạm dùng Idle trigger như code cũ của bạn
|
||||
animator.SetTrigger("Idle");
|
||||
joystick = FindAnyObjectByType<Joystick>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0911af06fee458459c86236ea21b716
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0525de198450e14f9f6ad854b95ec99
|
||||
@@ -1,3 +1,4 @@
|
||||
using CSNetwork.GPDataType;
|
||||
using UnityEngine;
|
||||
|
||||
struct cmd_player_move
|
||||
@@ -9,3 +10,30 @@ struct cmd_player_move
|
||||
byte move_mode; // Walk run swim fly .... walk_back run_back
|
||||
ushort stamp; // move command stamp
|
||||
};
|
||||
struct cmd_host_correct_pos
|
||||
{
|
||||
public Vector3 pos;
|
||||
public ushort stamp;
|
||||
};
|
||||
enum MoveMode
|
||||
{
|
||||
GP_MOVE_WALK = 0,
|
||||
GP_MOVE_RUN = 1,
|
||||
GP_MOVE_STAND = 2,
|
||||
GP_MOVE_FALL = 3,
|
||||
GP_MOVE_SLIDE = 4,
|
||||
GP_MOVE_PUSH = 5, // only sent to NPC
|
||||
GP_MOVE_FLYFALL = 6,
|
||||
GP_MOVE_RETURN = 7,
|
||||
GP_MOVE_JUMP = 8,
|
||||
GP_MOVE_PULL = 9, // only sent to NPC
|
||||
GP_MOVE_BLINK = 10, // only sent to NPC£¨Ë²ÒÆ£©
|
||||
GP_MOVE_MASK = 0x0f,
|
||||
|
||||
GP_MOVE_TURN = 0x10, // Turnaround
|
||||
GP_MOVE_DEAD = 0x20,
|
||||
|
||||
GP_MOVE_AIR = 0x40,
|
||||
GP_MOVE_WATER = 0x80,
|
||||
GP_MOVE_ENVMASK = 0xc0,
|
||||
};
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6f8dac8f744ee042aa1d70fb415e353
|
||||
@@ -8,9 +8,9 @@ public class GameController : MonoBehaviour
|
||||
{
|
||||
private static GameController instance;
|
||||
|
||||
[SerializeField] private CharacterCtrl characterPrefab;
|
||||
[SerializeField] private CECHostPlayer characterPrefab;
|
||||
//[SerializeField] private Transform ground;
|
||||
|
||||
CECHostPlayer hostPlayer;
|
||||
Camera camera;
|
||||
|
||||
public static GameController Instance
|
||||
@@ -24,7 +24,6 @@ public class GameController : MonoBehaviour
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if(instance == null)
|
||||
@@ -42,7 +41,10 @@ public class GameController : MonoBehaviour
|
||||
{
|
||||
Debug.LogError(s);
|
||||
}
|
||||
|
||||
public CECHostPlayer GetHostPlayer()
|
||||
{
|
||||
return hostPlayer;
|
||||
}
|
||||
public void InitCharacter(cmd_self_info_1 info)
|
||||
{
|
||||
if(characterPrefab == null)
|
||||
@@ -50,8 +52,8 @@ public class GameController : MonoBehaviour
|
||||
Debug.LogError("null prefab");
|
||||
return;
|
||||
}
|
||||
CharacterCtrl character = Instantiate(characterPrefab, transform);
|
||||
character.InitCharacter(info);
|
||||
hostPlayer = Instantiate(characterPrefab, transform);
|
||||
hostPlayer.InitCharacter(info);
|
||||
//Vector3 pos = new Vector3(info.pos.x, info.pos.y, info.pos.z);
|
||||
//Vector3 posCam = pos;
|
||||
//posCam.z -= 10f;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CECCounter
|
||||
{
|
||||
// Thuộc tính
|
||||
protected float m_dwCounter; // Counter
|
||||
protected float m_dwPeriod; // Count period
|
||||
|
||||
// Constructor
|
||||
public CECCounter()
|
||||
{
|
||||
m_dwCounter = 0;
|
||||
m_dwPeriod = 0;
|
||||
}
|
||||
|
||||
// Set / Get period
|
||||
public void SetPeriod(float dwPeriod) { m_dwPeriod = dwPeriod; }
|
||||
public float GetPeriod() { return m_dwPeriod; }
|
||||
|
||||
// Set / Get counter
|
||||
public void SetCounter(float dwCounter) { m_dwCounter = dwCounter; }
|
||||
public float GetCounter() { return m_dwCounter; }
|
||||
|
||||
// Has counter reached period ?
|
||||
public bool IsFull()
|
||||
{
|
||||
Debug.LogWarning($"HoangDev : {m_dwCounter} {m_dwPeriod} ");
|
||||
return (m_dwCounter >= m_dwPeriod);
|
||||
}
|
||||
|
||||
// Reset counter
|
||||
public void Reset(bool bFull = false)
|
||||
{
|
||||
m_dwCounter = bFull ? m_dwPeriod : 0;
|
||||
}
|
||||
|
||||
// Increase counter
|
||||
public bool IncCounter(float dwCounter)
|
||||
{
|
||||
m_dwCounter += dwCounter;
|
||||
return (m_dwCounter >= m_dwPeriod);
|
||||
}
|
||||
|
||||
// Decrease counter
|
||||
public void DecCounter(float dwCounter)
|
||||
{
|
||||
if (m_dwCounter <= dwCounter)
|
||||
m_dwCounter = 0;
|
||||
else
|
||||
m_dwCounter -= dwCounter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f330a50f34b90341a81715e467a1e7d
|
||||
@@ -1,13 +1,95 @@
|
||||
using System;
|
||||
using BrewMonster.Network;
|
||||
using CSNetwork.C2SCommand;
|
||||
using CSNetwork.GPDataType;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
using CSNetwork.Protocols;
|
||||
using UnityEngine.LightTransport;
|
||||
|
||||
public class CECHostMove
|
||||
{
|
||||
// Giữ reference tới CECHostPlayer – y như bản gốc
|
||||
ushort m_wMoveStamp;
|
||||
float m_fMoveTime;
|
||||
CECHostPlayer m_pHost;
|
||||
CECCounter m_CmdTimeCnt;
|
||||
bool m_bStop;
|
||||
const float MOVECMD_INTERVAL = .5f;
|
||||
Vector3 m_vLastSevPos;
|
||||
|
||||
public CECHostMove(CECHostPlayer pHost)
|
||||
{
|
||||
m_wMoveStamp = 0;
|
||||
m_fMoveTime = 0.0f;
|
||||
m_pHost = pHost;
|
||||
m_bStop = true;
|
||||
m_CmdTimeCnt = new CECCounter();
|
||||
m_CmdTimeCnt.SetPeriod(MOVECMD_INTERVAL);
|
||||
}
|
||||
public void Tick(float dwDeltaTime)
|
||||
{
|
||||
m_CmdTimeCnt.IncCounter(dwDeltaTime);
|
||||
}
|
||||
public void SendMoveCmd(in Vector3 vCurPos, in Vector3 vVel, int iMoveMode, bool bForceSend = false)
|
||||
{
|
||||
Vector3 vMoveDir = vVel;
|
||||
float fSpeed = vMoveDir.magnitude;
|
||||
SendMoveCmd(vCurPos, fSpeed, iMoveMode, bForceSend);
|
||||
}
|
||||
void SendMoveCmd(in Vector3 vCurPos,
|
||||
float fSpeed, int iMoveMode, bool bForceSend)
|
||||
{
|
||||
if (m_bStop)
|
||||
{
|
||||
// m_CmdTimeCnt.Reset();
|
||||
m_CmdTimeCnt.SetCounter((m_fMoveTime * 1000));
|
||||
m_bStop = false;
|
||||
}
|
||||
|
||||
if (!bForceSend && !m_CmdTimeCnt.IsFull())
|
||||
return;
|
||||
|
||||
int iTime = (int)(m_fMoveTime * 1000);
|
||||
|
||||
if (iTime < 200)
|
||||
{
|
||||
if (iTime == 0 || !bForceSend)
|
||||
{
|
||||
// if time is too little, wait again
|
||||
m_CmdTimeCnt.SetCounter(iTime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_CmdTimeCnt.Reset();
|
||||
|
||||
c2s_CmdPlayerMove(vCurPos, vCurPos, iTime/* MOVECMD_INTERVAL */, fSpeed, iMoveMode, m_wMoveStamp++);
|
||||
|
||||
m_vLastSevPos = vCurPos;
|
||||
}
|
||||
private void Reset()
|
||||
{
|
||||
m_bStop = true;
|
||||
}
|
||||
private void c2s_CmdPlayerMove(in Vector3 vCurPos, in Vector3 vDest,
|
||||
int iTime, float fSpeed, int iMoveMode, ushort wStamp)
|
||||
{
|
||||
gamedatasend gamedatasend = new gamedatasend();
|
||||
|
||||
//TODO: tim cach convert vector 3 unity sang System.Numerics.Vector3
|
||||
Debug.LogWarning("vCurPos " + vCurPos);
|
||||
gamedatasend.Data = C2SCommandFactory.CreatePlayerMove(ToSysVec3(vCurPos), ToSysVec3(vDest), (ushort)iTime, (short)fSpeed, (byte)iMoveMode, wStamp);
|
||||
UnityGameSession.SendProtocol(gamedatasend);
|
||||
Debug.LogWarning("HoangDev : SendProtocolSendProtocolSendProtocol");
|
||||
}
|
||||
public void GroundMove(float ftime)
|
||||
{
|
||||
m_fMoveTime += ftime;
|
||||
}
|
||||
public System.Numerics.Vector3 ToSysVec3(UnityEngine.Vector3 v)
|
||||
=> new System.Numerics.Vector3(v.x, v.y, v.z);
|
||||
}
|
||||
public struct CDR_INFO
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@ using UnityEngine;
|
||||
|
||||
public class PlayerMoveState : PlayerState
|
||||
{
|
||||
public PlayerMoveState(CharacterCtrl characterCtrl) : base(characterCtrl)
|
||||
public PlayerMoveState(CECHostPlayer characterCtrl) : base(characterCtrl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ using UnityEngine;
|
||||
|
||||
public abstract class PlayerState
|
||||
{
|
||||
protected readonly CharacterCtrl _characterCtrl;
|
||||
public PlayerState(CharacterCtrl characterCtrl)
|
||||
protected readonly CECHostPlayer _characterCtrl;
|
||||
public PlayerState(CECHostPlayer characterCtrl)
|
||||
{
|
||||
_characterCtrl = characterCtrl;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using UnityEngine;
|
||||
public class PlayerStateMachine
|
||||
{
|
||||
PlayerState _state;
|
||||
CharacterCtrl _characterCtrl;
|
||||
CECHostPlayer _characterCtrl;
|
||||
|
||||
public void InitState(PlayerState state)
|
||||
{
|
||||
@@ -35,5 +35,4 @@ public class PlayerStateMachine
|
||||
_state.Update();
|
||||
}
|
||||
|
||||
//TODO: tìm OnMsgHstCorrectPos bên C++
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using UnityEngine.InputSystem;
|
||||
|
||||
namespace StarterAssets
|
||||
{
|
||||
[RequireComponent(typeof(CharacterCtrl))]
|
||||
[RequireComponent(typeof(CECHostPlayer))]
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
[RequireComponent(typeof(PlayerInput))]
|
||||
#endif
|
||||
@@ -102,7 +102,7 @@ namespace StarterAssets
|
||||
private PlayerInput _playerInput;
|
||||
#endif
|
||||
private Animator _animator;
|
||||
private CharacterCtrl _controller;
|
||||
private CECHostPlayer _controller;
|
||||
private StarterAssetsInputs _input;
|
||||
private GameObject _mainCamera;
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace StarterAssets
|
||||
_cinemachineTargetYaw = CinemachineCameraTarget.transform.rotation.eulerAngles.y;
|
||||
|
||||
_hasAnimator = TryGetComponent(out _animator);
|
||||
_controller = GetComponent<CharacterCtrl>();
|
||||
_controller = GetComponent<CECHostPlayer>();
|
||||
_input = GetComponent<StarterAssetsInputs>();
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
_playerInput = GetComponent<PlayerInput>();
|
||||
|
||||
+82
-66
@@ -2,20 +2,24 @@
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2180264
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: LiberationSans SDF Material
|
||||
m_Shader: {fileID: 4800000, guid: fe393ace9b354375a9cb14cdbbc28be4, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 1
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
@@ -67,6 +71,7 @@ Material:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _Ambient: 0.5
|
||||
- _Bevel: 0.5
|
||||
@@ -148,6 +153,8 @@ Material:
|
||||
- _ReflectOutlineColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecularColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _UnderlayColor: {r: 0, g: 0, b: 0, a: 0.5}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -161,11 +168,6 @@ MonoBehaviour:
|
||||
m_Name: LiberationSans SDF - Fallback
|
||||
m_EditorClassIdentifier:
|
||||
m_Version: 1.1.0
|
||||
m_Material: {fileID: 2180264}
|
||||
m_SourceFontFileGUID: e3265ab4bf004d28a9537516768c1c75
|
||||
m_SourceFontFile: {fileID: 12800000, guid: e3265ab4bf004d28a9537516768c1c75, type: 3}
|
||||
m_AtlasPopulationMode: 1
|
||||
InternalDynamicOS: 0
|
||||
m_FaceInfo:
|
||||
m_FaceIndex: 0
|
||||
m_FamilyName: Liberation Sans
|
||||
@@ -188,57 +190,8 @@ MonoBehaviour:
|
||||
m_StrikethroughOffset: 18
|
||||
m_StrikethroughThickness: 6.298828
|
||||
m_TabWidth: 24
|
||||
m_GlyphTable: []
|
||||
m_CharacterTable: []
|
||||
m_AtlasTextures:
|
||||
- {fileID: 28268798066460806}
|
||||
m_AtlasTextureIndex: 0
|
||||
m_IsMultiAtlasTexturesEnabled: 1
|
||||
m_ClearDynamicDataOnBuild: 1
|
||||
m_UsedGlyphRects: []
|
||||
m_FreeGlyphRects:
|
||||
- m_X: 0
|
||||
m_Y: 0
|
||||
m_Width: 511
|
||||
m_Height: 511
|
||||
m_fontInfo:
|
||||
Name: Liberation Sans
|
||||
PointSize: 86
|
||||
Scale: 1
|
||||
CharacterCount: 250
|
||||
LineHeight: 98.90625
|
||||
Baseline: 0
|
||||
Ascender: 77.84375
|
||||
CapHeight: 59.1875
|
||||
Descender: -18.21875
|
||||
CenterLine: 0
|
||||
SuperscriptOffset: 77.84375
|
||||
SubscriptOffset: -12.261719
|
||||
SubSize: 0.5
|
||||
Underline: -12.261719
|
||||
UnderlineThickness: 6.298828
|
||||
strikethrough: 23.675
|
||||
strikethroughThickness: 0
|
||||
TabWidth: 239.0625
|
||||
Padding: 9
|
||||
AtlasWidth: 1024
|
||||
AtlasHeight: 1024
|
||||
atlas: {fileID: 0}
|
||||
m_AtlasWidth: 512
|
||||
m_AtlasHeight: 512
|
||||
m_AtlasPadding: 9
|
||||
m_AtlasRenderMode: 4169
|
||||
m_glyphInfoList: []
|
||||
m_KerningTable:
|
||||
kerningPairs: []
|
||||
m_FontFeatureTable:
|
||||
m_MultipleSubstitutionRecords: []
|
||||
m_LigatureSubstitutionRecords: []
|
||||
m_GlyphPairAdjustmentRecords: []
|
||||
m_MarkToBaseAdjustmentRecords: []
|
||||
m_MarkToMarkAdjustmentRecords: []
|
||||
fallbackFontAssets: []
|
||||
m_FallbackFontAssetTable: []
|
||||
m_Material: {fileID: 2180264}
|
||||
m_SourceFontFileGUID: e3265ab4bf004d28a9537516768c1c75
|
||||
m_CreationSettings:
|
||||
sourceFontFileName:
|
||||
sourceFontFileGUID: e3265ab4bf004d28a9537516768c1c75
|
||||
@@ -258,6 +211,36 @@ MonoBehaviour:
|
||||
fontStyleModifier: 0
|
||||
renderMode: 4169
|
||||
includeFontFeatures: 1
|
||||
m_SourceFontFile: {fileID: 12800000, guid: e3265ab4bf004d28a9537516768c1c75, type: 3}
|
||||
m_SourceFontFilePath:
|
||||
m_AtlasPopulationMode: 1
|
||||
InternalDynamicOS: 0
|
||||
m_GlyphTable: []
|
||||
m_CharacterTable: []
|
||||
m_AtlasTextures:
|
||||
- {fileID: 28268798066460806}
|
||||
m_AtlasTextureIndex: 0
|
||||
m_IsMultiAtlasTexturesEnabled: 1
|
||||
m_GetFontFeatures: 1
|
||||
m_ClearDynamicDataOnBuild: 1
|
||||
m_AtlasWidth: 512
|
||||
m_AtlasHeight: 512
|
||||
m_AtlasPadding: 9
|
||||
m_AtlasRenderMode: 4169
|
||||
m_UsedGlyphRects: []
|
||||
m_FreeGlyphRects:
|
||||
- m_X: 0
|
||||
m_Y: 0
|
||||
m_Width: 511
|
||||
m_Height: 511
|
||||
m_FontFeatureTable:
|
||||
m_MultipleSubstitutionRecords: []
|
||||
m_LigatureSubstitutionRecords: []
|
||||
m_GlyphPairAdjustmentRecords: []
|
||||
m_MarkToBaseAdjustmentRecords: []
|
||||
m_MarkToMarkAdjustmentRecords: []
|
||||
m_ShouldReimportFontFeatures: 0
|
||||
m_FallbackFontAssetTable: []
|
||||
m_FontWeightTable:
|
||||
- regularTypeface: {fileID: 0}
|
||||
italicTypeface: {fileID: 0}
|
||||
@@ -306,6 +289,33 @@ MonoBehaviour:
|
||||
boldSpacing: 7
|
||||
italicStyle: 35
|
||||
tabSize: 10
|
||||
m_fontInfo:
|
||||
Name: Liberation Sans
|
||||
PointSize: 86
|
||||
Scale: 1
|
||||
CharacterCount: 250
|
||||
LineHeight: 98.90625
|
||||
Baseline: 0
|
||||
Ascender: 77.84375
|
||||
CapHeight: 59.1875
|
||||
Descender: -18.21875
|
||||
CenterLine: 0
|
||||
SuperscriptOffset: 77.84375
|
||||
SubscriptOffset: -12.261719
|
||||
SubSize: 0.5
|
||||
Underline: -12.261719
|
||||
UnderlineThickness: 6.298828
|
||||
strikethrough: 23.675
|
||||
strikethroughThickness: 0
|
||||
TabWidth: 239.0625
|
||||
Padding: 9
|
||||
AtlasWidth: 1024
|
||||
AtlasHeight: 1024
|
||||
m_glyphInfoList: []
|
||||
m_KerningTable:
|
||||
kerningPairs: []
|
||||
fallbackFontAssets: []
|
||||
atlas: {fileID: 0}
|
||||
--- !u!28 &28268798066460806
|
||||
Texture2D:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -316,17 +326,21 @@ Texture2D:
|
||||
m_ImageContentsHash:
|
||||
serializedVersion: 2
|
||||
Hash: 00000000000000000000000000000000
|
||||
m_ForcedFallbackFormat: 4
|
||||
m_DownscaleFallback: 0
|
||||
serializedVersion: 2
|
||||
m_Width: 0
|
||||
m_Height: 0
|
||||
m_CompleteImageSize: 0
|
||||
m_IsAlphaChannelOptional: 0
|
||||
serializedVersion: 3
|
||||
m_Width: 1
|
||||
m_Height: 1
|
||||
m_CompleteImageSize: 1
|
||||
m_MipsStripped: 0
|
||||
m_TextureFormat: 1
|
||||
m_MipCount: 1
|
||||
m_IsReadable: 1
|
||||
m_IsPreProcessed: 0
|
||||
m_IgnoreMipmapLimit: 0
|
||||
m_MipmapLimitGroupName:
|
||||
m_StreamingMipmaps: 0
|
||||
m_StreamingMipmapsPriority: 0
|
||||
m_VTOnly: 0
|
||||
m_AlphaIsTransparency: 0
|
||||
m_ImageCount: 1
|
||||
m_TextureDimension: 2
|
||||
@@ -340,9 +354,11 @@ Texture2D:
|
||||
m_WrapW: 0
|
||||
m_LightmapFormat: 0
|
||||
m_ColorSpace: 0
|
||||
image data: 0
|
||||
_typelessdata:
|
||||
m_PlatformBlob:
|
||||
image data: 1
|
||||
_typelessdata: 00
|
||||
m_StreamData:
|
||||
serializedVersion: 2
|
||||
offset: 0
|
||||
size: 0
|
||||
path:
|
||||
|
||||
@@ -20,6 +20,9 @@ EditorBuildSettings:
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/WorldRender.unity
|
||||
guid: 6d5fa77a0ed1542c8a76520fd198c7f1
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/HoangTest.unity
|
||||
guid: 9172bad49fed35e46819504e93c44a84
|
||||
m_configObjects:
|
||||
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 052faaac586de48259a63d0c4782560b, type: 3}
|
||||
m_UseUCBPForAssetBundles: 0
|
||||
|
||||
Reference in New Issue
Block a user