send move mand processing and testing correct pos player
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
|
||||
@@ -18,9 +18,10 @@ namespace PerfectWorld.Scripts.Managers
|
||||
public int HandlerId => (int)MANAGER_INDEX.MAN_PLAYER;
|
||||
public bool ProcessMessage(ECMSG Msg)
|
||||
{
|
||||
Debug.LogWarning("ProcessMessage");
|
||||
if (Msg.iSubID == 0)
|
||||
{
|
||||
|
||||
GameController.Instance.GetHostPlayer().ProcessMessage(Msg);
|
||||
}
|
||||
else if (Msg.iSubID < 0)
|
||||
{
|
||||
@@ -95,6 +96,7 @@ namespace PerfectWorld.Scripts.Managers
|
||||
{
|
||||
bool isDoneWorldRender = false;
|
||||
bool isDoneNPCRender = false;
|
||||
Debug.Log("HostPlayerInfo1HostPlayerInfo1");
|
||||
Action actLoadChar = () =>
|
||||
{
|
||||
if(!isDoneNPCRender || !isDoneWorldRender)
|
||||
@@ -104,13 +106,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();
|
||||
|
||||
@@ -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;
|
||||
@@ -14,7 +19,6 @@ public class CECHostPlayer : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TextMeshPro txtName;
|
||||
[SerializeField] private CharacterController controller;
|
||||
[SerializeField] private Animator animator;
|
||||
|
||||
[SerializeField] private Joystick joystick;
|
||||
[SerializeField] private Button btnJump;
|
||||
@@ -31,7 +35,7 @@ public class CECHostPlayer : MonoBehaviour
|
||||
Vector3 playerVelocity;
|
||||
bool isGrounded = false;
|
||||
bool isRun = false;
|
||||
GameObject modle;
|
||||
GameObject modle;
|
||||
Vector3 m_vLastSevPos;
|
||||
|
||||
// ====== Ground cast config ======
|
||||
@@ -116,12 +120,9 @@ public class CECHostPlayer : MonoBehaviour
|
||||
if (move != Vector3.zero)
|
||||
{
|
||||
transform.forward = move;
|
||||
if (isRun) SetAnimRun();
|
||||
else SetAnimWalk();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetAnimIdle();
|
||||
}
|
||||
|
||||
Vector3 finalMove = (move * playerSpeed) + (playerVelocity.y * Vector3.up);
|
||||
@@ -171,16 +172,32 @@ public class CECHostPlayer : MonoBehaviour
|
||||
if (isGrounded)
|
||||
{
|
||||
playerVelocity.y = Mathf.Sqrt(jumpHeight * -2f * gravityValue);
|
||||
SetAnimJump();
|
||||
}
|
||||
}
|
||||
private void OnMsgHstCorrectPos()
|
||||
public void ProcessMessage(in ECMSG Msg)
|
||||
{
|
||||
|
||||
switch ((int)Msg.dwMsg)
|
||||
{
|
||||
case int value when value == EC_MsgDef.MSG_HST_CORRECTPOS: OnMsgHstCorrectPos(Msg); break;
|
||||
}
|
||||
}
|
||||
private void SetPos()
|
||||
private void c2s_CmdPlayerMove(in Vector3 vCurPos, in Vector3 vDest,
|
||||
int iTime, float fSpeed, int iMoveMode, ushort wStamp)
|
||||
{
|
||||
|
||||
gamedatasend gamedatasend = new gamedatasend();
|
||||
//gamedatasend.Data = C2SCommandFactory.CreatePlayerMove();
|
||||
UnityGameSession.SendProtocol(gamedatasend);
|
||||
}
|
||||
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)
|
||||
{
|
||||
@@ -191,7 +208,6 @@ public class CECHostPlayer : MonoBehaviour
|
||||
}
|
||||
isRun = value;
|
||||
}
|
||||
|
||||
public void InitCharacter(cmd_self_info_1 role)
|
||||
{
|
||||
string roleName = "(Error decoding name)";
|
||||
@@ -204,35 +220,7 @@ public class CECHostPlayer : 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>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using CSNetwork.GPDataType;
|
||||
using UnityEngine;
|
||||
|
||||
struct cmd_player_move
|
||||
@@ -9,3 +10,8 @@ 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;
|
||||
};
|
||||
@@ -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;
|
||||
|
||||
@@ -35,5 +35,4 @@ public class PlayerStateMachine
|
||||
_state.Update();
|
||||
}
|
||||
|
||||
//TODO: tìm OnMsgHstCorrectPos bên C++
|
||||
}
|
||||
|
||||
@@ -17,6 +17,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