di chuyen nhu cc
This commit is contained in:
58
.idea/.idea.HALLUCINATE/.idea/workspace.xml
generated
58
.idea/.idea.HALLUCINATE/.idea/workspace.xml
generated
@@ -5,11 +5,18 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="f9183c68-daf0-43b8-be4c-fad79983f91b" name="Changes" comment="">
|
<list default="true" id="f9183c68-daf0-43b8-be4c-fad79983f91b" name="Changes" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/indexLayout.xml" beforeDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Assets/Prefabs/Player.prefab" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Prefabs/Player.prefab" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Assets/Scenes/Lobby.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scenes/Lobby.unity" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Assets/Scove/Player Movement.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scove/Player Movement.unity" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Assets/Scenes/Main Scene.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scenes/Main Scene.unity" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Interactables/LampInteractable.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Interactables/LampInteractable.cs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Assets/Scove/DEMO FUSION.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scove/DEMO FUSION.unity" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/MyUIDisplay.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/MyUIDisplay.cs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerAirDashState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerAirDashState.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDashState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDashState.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDodgeState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerDodgeState.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerFallState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerFallState.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerJumpState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerJumpState.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerMoveState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerMoveState.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerRunState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerRunState.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerStateMachine.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player Controller/PlayerStateMachine.cs" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -40,27 +47,27 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
"RunOnceActivity.MCP Project settings loaded": "true",
|
"RunOnceActivity.MCP Project settings loaded": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
||||||
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
|
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "Tuan",
|
||||||
"junie.onboarding.icon.badge.shown": "true",
|
"junie.onboarding.icon.badge.shown": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"settings.editor.selected.configurable": "preferences.pluginManager",
|
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||||
"to.speed.mode.migration.done": "true",
|
"to.speed.mode.migration.done": "true",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RunManager" selected="Attach to Unity Editor.Attach to Unity Editor">
|
<component name="RunManager" selected="Attach to Unity Editor.Attach to Unity Editor">
|
||||||
<configuration name="Standalone Player" type="RunUnityExe" factoryName="Unity Executable">
|
<configuration name="Standalone Player" type="RunUnityExe" factoryName="Unity Executable">
|
||||||
<option name="EXE_PATH" value="$PROJECT_DIR$/../BAI MUTIPLAY\HALLUCINATE.exe" />
|
<option name="EXE_PATH" value="$PROJECT_DIR$/../BAI MUTIPLAY\HALLUCINATE.exe" />
|
||||||
@@ -133,6 +140,7 @@
|
|||||||
<workItem from="1775106342316" duration="15040000" />
|
<workItem from="1775106342316" duration="15040000" />
|
||||||
<workItem from="1775313757656" duration="8722000" />
|
<workItem from="1775313757656" duration="8722000" />
|
||||||
<workItem from="1776130728673" duration="7161000" />
|
<workItem from="1776130728673" duration="7161000" />
|
||||||
|
<workItem from="1776255558934" duration="1896000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -3158,7 +3158,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: ca752d01bdc2c5e42938776307031da3, type: 3}
|
m_Script: {fileID: 11500000, guid: ca752d01bdc2c5e42938776307031da3, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::BasicSpawner
|
m_EditorClassIdentifier: Assembly-CSharp::BasicSpawner
|
||||||
LobbyManager: {fileID: 0}
|
LobbyManager: {fileID: 2023167162}
|
||||||
_playerPrefab:
|
_playerPrefab:
|
||||||
RawGuidValue: 761bdf2e5c0cff4488527355acb975e5
|
RawGuidValue: 761bdf2e5c0cff4488527355acb975e5
|
||||||
--- !u!1660057539 &9223372036854775807
|
--- !u!1660057539 &9223372036854775807
|
||||||
|
|||||||
@@ -704,8 +704,10 @@ GameObject:
|
|||||||
serializedVersion: 6
|
serializedVersion: 6
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 2116497667}
|
- component: {fileID: 2116497667}
|
||||||
|
- component: {fileID: 2116497669}
|
||||||
|
- component: {fileID: 2116497668}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: _MANAGER
|
m_Name: Lobby Manager
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
@@ -726,6 +728,34 @@ Transform:
|
|||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &2116497668
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2116497666}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: b5aeb4670d7bf41499d3aaf409820260, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::LobbyManager
|
||||||
|
roomListContent: {fileID: 2116497667}
|
||||||
|
--- !u!114 &2116497669
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2116497666}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: ca752d01bdc2c5e42938776307031da3, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::_BasicSpawner
|
||||||
|
LobbyManager: {fileID: 0}
|
||||||
|
_playerPrefab:
|
||||||
|
RawGuidValue: 761bdf2e5c0cff4488527355acb975e5
|
||||||
--- !u!1001 &3886963620680427248
|
--- !u!1001 &3886963620680427248
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -893,7 +923,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
|
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
value: -0.12540007
|
value: 5.34
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
|
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
|
||||||
propertyPath: m_LocalPosition.y
|
propertyPath: m_LocalPosition.y
|
||||||
@@ -901,7 +931,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
|
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
|
||||||
propertyPath: m_LocalPosition.z
|
propertyPath: m_LocalPosition.z
|
||||||
value: -0.13893032
|
value: -1.89
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
|
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
|
||||||
propertyPath: m_LocalRotation.w
|
propertyPath: m_LocalRotation.w
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OnlyScove.Scripts
|
|||||||
if (input != Vector2.zero)
|
if (input != Vector2.zero)
|
||||||
{
|
{
|
||||||
dashDirection = new Vector3(input.x, 0, input.y).normalized;
|
dashDirection = new Vector3(input.x, 0, input.y).normalized;
|
||||||
dashDirection = stateMachine.NetworkedCameraRotation * dashDirection;
|
dashDirection = stateMachine.CameraRotation * dashDirection;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace OnlyScove.Scripts
|
|||||||
if (input != Vector2.zero)
|
if (input != Vector2.zero)
|
||||||
{
|
{
|
||||||
dashDirection = new Vector3(input.x, 0f, input.y).normalized;
|
dashDirection = new Vector3(input.x, 0f, input.y).normalized;
|
||||||
dashDirection = stateMachine.NetworkedCameraRotation * dashDirection;
|
dashDirection = stateMachine.CameraRotation * dashDirection;
|
||||||
dashDirection.y = 0;
|
dashDirection.y = 0;
|
||||||
dashDirection.Normalize();
|
dashDirection.Normalize();
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OnlyScove.Scripts
|
|||||||
if (input != Vector2.zero)
|
if (input != Vector2.zero)
|
||||||
{
|
{
|
||||||
dodgeDirection = new Vector3(input.x, 0, input.y).normalized;
|
dodgeDirection = new Vector3(input.x, 0, input.y).normalized;
|
||||||
dodgeDirection = stateMachine.NetworkedCameraRotation * dodgeDirection;
|
dodgeDirection = stateMachine.CameraRotation * dodgeDirection;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OnlyScove.Scripts
|
|||||||
// ĐÚNG: Sử dụng MoveInput đã đồng bộ mạng
|
// ĐÚNG: Sử dụng MoveInput đã đồng bộ mạng
|
||||||
Vector2 input = stateMachine.MoveInput;
|
Vector2 input = stateMachine.MoveInput;
|
||||||
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
|
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
|
||||||
Vector3 moveDirection = stateMachine.NetworkedCameraRotation * inputDir;
|
Vector3 moveDirection = stateMachine.CameraRotation * inputDir;
|
||||||
moveDirection.y = 0;
|
moveDirection.y = 0;
|
||||||
moveDirection.Normalize();
|
moveDirection.Normalize();
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OnlyScove.Scripts
|
|||||||
|
|
||||||
Vector2 input = stateMachine.MoveInput;
|
Vector2 input = stateMachine.MoveInput;
|
||||||
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
|
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
|
||||||
Vector3 moveDirection = stateMachine.NetworkedCameraRotation * inputDir;
|
Vector3 moveDirection = stateMachine.CameraRotation * inputDir;
|
||||||
moveDirection.y = 0;
|
moveDirection.y = 0;
|
||||||
moveDirection.Normalize();
|
moveDirection.Normalize();
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OnlyScove.Scripts
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
|
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
|
||||||
Vector3 moveDirection = stateMachine.NetworkedCameraRotation * inputDir;
|
Vector3 moveDirection = stateMachine.CameraRotation * inputDir;
|
||||||
moveDirection.y = 0;
|
moveDirection.y = 0;
|
||||||
moveDirection.Normalize();
|
moveDirection.Normalize();
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OnlyScove.Scripts
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
|
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
|
||||||
Vector3 moveDirection = stateMachine.NetworkedCameraRotation * inputDir;
|
Vector3 moveDirection = stateMachine.CameraRotation * inputDir;
|
||||||
moveDirection.y = 0;
|
moveDirection.y = 0;
|
||||||
moveDirection.Normalize();
|
moveDirection.Normalize();
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,22 @@ namespace OnlyScove.Scripts
|
|||||||
[field: SerializeField] public LayerMask InteractionMask { get; private set; }
|
[field: SerializeField] public LayerMask InteractionMask { get; private set; }
|
||||||
|
|
||||||
[Networked] public Quaternion NetworkedCameraRotation { get; set; }
|
[Networked] public Quaternion NetworkedCameraRotation { get; set; }
|
||||||
|
|
||||||
|
// Thuộc tính hỗ trợ lấy rotation của Camera an toàn cho cả Online và Offline
|
||||||
|
public Quaternion CameraRotation
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Runner != null && Runner.IsRunning && Object != null)
|
||||||
|
return NetworkedCameraRotation;
|
||||||
|
|
||||||
|
if (Cam != null)
|
||||||
|
return Cam.PlanarRotation;
|
||||||
|
|
||||||
|
return transform.rotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Networked] public Vector2 NetworkedMoveInput { get; set; }
|
[Networked] public Vector2 NetworkedMoveInput { get; set; }
|
||||||
[Networked] public float NetworkedSpeed { get; set; }
|
[Networked] public float NetworkedSpeed { get; set; }
|
||||||
[Networked] public Vector3 NetworkedPosition { get; set; }
|
[Networked] public Vector3 NetworkedPosition { get; set; }
|
||||||
@@ -94,11 +110,39 @@ namespace OnlyScove.Scripts
|
|||||||
velocityZHash = Animator.StringToHash(velocityZParamName);
|
velocityZHash = Animator.StringToHash(velocityZParamName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
// Nếu chạy Offline (kéo prefab vào scene), Spawned() sẽ không được gọi.
|
||||||
|
// Chúng ta khởi tạo tại đây để đảm bảo nhân vật hoạt động.
|
||||||
|
if (Runner == null || !Runner.IsRunning)
|
||||||
|
{
|
||||||
|
InitializePlayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Spawned()
|
public override void Spawned()
|
||||||
{
|
{
|
||||||
SwitchState(new PlayerIdleState(this));
|
// Fusion gọi Spawned khi object được nạp vào mạng.
|
||||||
|
InitializePlayer();
|
||||||
|
|
||||||
if (Object.HasInputAuthority)
|
// Nếu không có quyền điều khiển và đang ở Client, tắt Controller để tránh xung đột
|
||||||
|
if (Object != null && !Object.HasInputAuthority && Runner.IsClient)
|
||||||
|
{
|
||||||
|
if (Controller != null) Controller.enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializePlayer()
|
||||||
|
{
|
||||||
|
if (currentState == null)
|
||||||
|
{
|
||||||
|
SwitchState(new PlayerIdleState(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isOffline = Runner == null || !Runner.IsRunning;
|
||||||
|
bool hasAuthority = Object != null && Object.HasInputAuthority;
|
||||||
|
|
||||||
|
if (isOffline || hasAuthority)
|
||||||
{
|
{
|
||||||
Local = this;
|
Local = this;
|
||||||
|
|
||||||
@@ -112,11 +156,9 @@ namespace OnlyScove.Scripts
|
|||||||
|
|
||||||
Input.OnNextInteractEvent += OnNextInteract;
|
Input.OnNextInteractEvent += OnNextInteract;
|
||||||
Input.OnPreviousInteractEvent += OnPreviousInteract;
|
Input.OnPreviousInteractEvent += OnPreviousInteract;
|
||||||
}
|
|
||||||
else
|
// Đảm bảo Controller được bật
|
||||||
{
|
if (Controller != null) Controller.enabled = true;
|
||||||
// Vô hiệu hóa Controller của người chơi khác trên máy khách để tránh xung đột vật lý
|
|
||||||
if (Runner.IsClient && Controller != null) Controller.enabled = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,19 +178,26 @@ namespace OnlyScove.Scripts
|
|||||||
|
|
||||||
public void Move(Vector3 velocity, float animatorSpeed, float deltaTime)
|
public void Move(Vector3 velocity, float animatorSpeed, float deltaTime)
|
||||||
{
|
{
|
||||||
// CHỈ thực hiện di chuyển nếu có quyền điều khiển hoặc là Server
|
// Cho phép di chuyển nếu:
|
||||||
if (!Object.HasInputAuthority && !Runner.IsServer) return;
|
// 1. Không có mạng (Offline test)
|
||||||
|
// 2. Có quyền điều khiển (Input Authority)
|
||||||
|
// 3. Là Server (State Authority)
|
||||||
|
bool canMove = (Runner == null || !Runner.IsRunning) || Object.HasInputAuthority || Runner.IsServer;
|
||||||
|
if (!canMove) return;
|
||||||
|
|
||||||
if (Controller != null && Controller.enabled)
|
if (Controller != null && Controller.enabled)
|
||||||
{
|
{
|
||||||
Controller.Move(velocity * deltaTime);
|
Controller.Move(velocity * deltaTime);
|
||||||
// Cập nhật vị trí mạng ngay sau khi di chuyển để tick sau quay lại đây
|
// Cập nhật vị trí mạng ngay sau khi di chuyển
|
||||||
NetworkedPosition = transform.position;
|
if (Object != null && Runner != null && Runner.IsRunning)
|
||||||
|
{
|
||||||
|
NetworkedPosition = transform.position;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
localAnimatorSpeed = animatorSpeed;
|
localAnimatorSpeed = animatorSpeed;
|
||||||
|
|
||||||
if (Object.HasStateAuthority)
|
if (Object != null && Object.HasStateAuthority)
|
||||||
{
|
{
|
||||||
NetworkedSpeed = animatorSpeed;
|
NetworkedSpeed = animatorSpeed;
|
||||||
NetworkedMoveInput = MoveInput;
|
NetworkedMoveInput = MoveInput;
|
||||||
@@ -164,7 +213,7 @@ namespace OnlyScove.Scripts
|
|||||||
float speedValue;
|
float speedValue;
|
||||||
Vector2 inputVector;
|
Vector2 inputVector;
|
||||||
|
|
||||||
if (Object.HasInputAuthority)
|
if (Runner == null || !Runner.IsRunning || Object.HasInputAuthority)
|
||||||
{
|
{
|
||||||
speedValue = localAnimatorSpeed;
|
speedValue = localAnimatorSpeed;
|
||||||
inputVector = MoveInput;
|
inputVector = MoveInput;
|
||||||
@@ -183,15 +232,14 @@ namespace OnlyScove.Scripts
|
|||||||
|
|
||||||
public override void FixedUpdateNetwork()
|
public override void FixedUpdateNetwork()
|
||||||
{
|
{
|
||||||
if (Object == null) return;
|
bool isRunning = Runner != null && Runner.IsRunning;
|
||||||
|
if (Object == null && isRunning) return;
|
||||||
|
|
||||||
// ĐỒNG BỘ VỊ TRÍ: Ép nhân vật về vị trí mạng trước khi tính toán tick mới
|
// ĐỒNG BỘ VỊ TRÍ: Ép nhân vật về vị trí mạng trước khi tính toán tick mới
|
||||||
// Điều này cực kỳ quan trọng để CharacterController không bị nhân đôi vận tốc khi Resimulation
|
if (isRunning && NetworkedPosition != Vector3.zero)
|
||||||
if (NetworkedPosition != Vector3.zero)
|
|
||||||
{
|
{
|
||||||
if (Controller != null)
|
if (Controller != null && !Object.HasInputAuthority)
|
||||||
{
|
{
|
||||||
// Tạm thời tắt Controller để dịch chuyển Transform chính xác
|
|
||||||
Controller.enabled = false;
|
Controller.enabled = false;
|
||||||
transform.position = NetworkedPosition;
|
transform.position = NetworkedPosition;
|
||||||
Controller.enabled = true;
|
Controller.enabled = true;
|
||||||
@@ -202,7 +250,15 @@ namespace OnlyScove.Scripts
|
|||||||
{
|
{
|
||||||
MoveInput = data.Direction;
|
MoveInput = data.Direction;
|
||||||
IsSprintHeld = data.sprint;
|
IsSprintHeld = data.sprint;
|
||||||
NetworkedCameraRotation = data.rot;
|
// Chỉ gán biến Networked nếu đang chạy mạng
|
||||||
|
if (isRunning) NetworkedCameraRotation = data.rot;
|
||||||
|
}
|
||||||
|
else if (!isRunning)
|
||||||
|
{
|
||||||
|
// FALLBACK INPUT: Nếu không có Fusion, lấy input trực tiếp từ Unity để Test
|
||||||
|
MoveInput = new Vector2(UnityEngine.Input.GetAxisRaw("Horizontal"), UnityEngine.Input.GetAxisRaw("Vertical"));
|
||||||
|
IsSprintHeld = UnityEngine.Input.GetKey(KeyCode.LeftShift);
|
||||||
|
// Ở chế độ offline, chúng ta không gán vào NetworkedCameraRotation nữa
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -210,7 +266,9 @@ namespace OnlyScove.Scripts
|
|||||||
IsSprintHeld = false;
|
IsSprintHeld = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Object.HasInputAuthority && !Runner.IsServer)
|
bool isSimulating = !isRunning || Object.HasInputAuthority || Runner.IsServer;
|
||||||
|
|
||||||
|
if (!isSimulating)
|
||||||
{
|
{
|
||||||
UpdateAnimator(Runner.DeltaTime);
|
UpdateAnimator(Runner.DeltaTime);
|
||||||
return;
|
return;
|
||||||
@@ -222,7 +280,18 @@ namespace OnlyScove.Scripts
|
|||||||
CheckGround();
|
CheckGround();
|
||||||
UpdateInteractablesList();
|
UpdateInteractablesList();
|
||||||
|
|
||||||
currentState?.Tick(Runner.DeltaTime);
|
float dt = isRunning ? Runner.DeltaTime : Time.fixedDeltaTime;
|
||||||
|
currentState?.Tick(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
// Nếu không có NetworkRunner, Fusion sẽ không gọi FixedUpdateNetwork.
|
||||||
|
// Chúng ta gọi thủ công để logic StateMachine vẫn chạy được khi Test Offline.
|
||||||
|
if (Runner == null || !Runner.IsRunning)
|
||||||
|
{
|
||||||
|
FixedUpdateNetwork();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckGround()
|
private void CheckGround()
|
||||||
|
|||||||
Reference in New Issue
Block a user