From 003fcf6b6feb1b1059a151d84fc5588e27a21827 Mon Sep 17 00:00:00 2001 From: Tran Nguyen Phuong Date: Thu, 25 Jun 2026 16:27:34 +0700 Subject: [PATCH] update --- .idea/.idea.BABA_YAGA/.idea/workspace.xml | 76 ++++++++----- .../Resources/Materials 1/meleeLogo.mat | 5 +- .../Editors/Resources/Materials/basicLogo.mat | 5 +- Assets/Scenes/Main Scene.unity | 2 +- Assets/Scripts/Network/BasicSpawner.cs | 40 ++++++- .../Network/FusionClientMovementBridge.cs | 71 +++++++++--- ...niversalRenderPipelineGlobalSettings.asset | 17 ++- ProjectSettings/BuildReportToolOptions.xml | 104 ++++++++++++++++++ ProjectSettings/EditorBuildSettings.asset | 6 +- ProjectSettings/ProjectSettings.asset | 5 +- ProjectSettings/UnityConnectSettings.asset | 2 +- 11 files changed, 276 insertions(+), 57 deletions(-) create mode 100644 ProjectSettings/BuildReportToolOptions.xml diff --git a/.idea/.idea.BABA_YAGA/.idea/workspace.xml b/.idea/.idea.BABA_YAGA/.idea/workspace.xml index ead077d5..489ad370 100644 --- a/.idea/.idea.BABA_YAGA/.idea/workspace.xml +++ b/.idea/.idea.BABA_YAGA/.idea/workspace.xml @@ -10,7 +10,20 @@ - + + + + + + + + + + + + + + - { + "keyToString": { + "ModuleVcsDetector.initialDetectionPerformed": "true", + "RunOnceActivity.MCP Project settings loaded": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true", + "RunOnceActivity.cidr.known.project.marker": "true", + "RunOnceActivity.git.unshallow": "true", + "RunOnceActivity.readMode.enableVisualFormatting": "true", + "RunOnceActivity.typescript.service.memoryLimit.init": "true", + "cidr.known.project.marker": "true", + "codeWithMe.voiceChat.enabledByDefault": "false", + "com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true", + "git-widget-placeholder": "main", + "junie.onboarding.icon.badge.shown": "true", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "preferences.lookFeel", + "to.speed.mode.migration.done": "true", + "vue.rearranger.settings.migration": "true" } -}]]> +} + + diff --git a/Assets/Editors/Resources/Materials 1/meleeLogo.mat b/Assets/Editors/Resources/Materials 1/meleeLogo.mat index dd63e99d..2eddc00e 100644 --- a/Assets/Editors/Resources/Materials 1/meleeLogo.mat +++ b/Assets/Editors/Resources/Materials 1/meleeLogo.mat @@ -25,6 +25,7 @@ Material: disabledShaderPasses: - MOTIONVECTORS - DepthOnly + - SHADOWCASTER m_LockedProperties: m_SavedProperties: serializedVersion: 3 @@ -54,7 +55,7 @@ Material: m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MainTex: - m_Texture: {fileID: 0} + m_Texture: {fileID: 2800000, guid: bd0016d65407db7428ef203c702535b5, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MetallicGlossMap: @@ -123,7 +124,7 @@ Material: - _ZWrite: 0 m_Colors: - _BaseColor: {r: 1, g: 1, b: 1, a: 0.728} - - _Color: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 0.728} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Editors/Resources/Materials/basicLogo.mat b/Assets/Editors/Resources/Materials/basicLogo.mat index 0898cb00..c0065391 100644 --- a/Assets/Editors/Resources/Materials/basicLogo.mat +++ b/Assets/Editors/Resources/Materials/basicLogo.mat @@ -25,6 +25,7 @@ Material: disabledShaderPasses: - MOTIONVECTORS - DepthOnly + - SHADOWCASTER m_LockedProperties: m_SavedProperties: serializedVersion: 3 @@ -54,7 +55,7 @@ Material: m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MainTex: - m_Texture: {fileID: 0} + m_Texture: {fileID: 2800000, guid: f75e2b1809ad796469251378de80ccb1, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MetallicGlossMap: @@ -123,7 +124,7 @@ Material: - _ZWrite: 0 m_Colors: - _BaseColor: {r: 1, g: 1, b: 1, a: 0.703} - - _Color: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 0.703} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Scenes/Main Scene.unity b/Assets/Scenes/Main Scene.unity index ab333a3e..c5290a73 100644 --- a/Assets/Scenes/Main Scene.unity +++ b/Assets/Scenes/Main Scene.unity @@ -591,7 +591,7 @@ MonoBehaviour: _playerPrefab: RawGuidValue: 78cdc99d2fb73904586ae402e642e288 _playerDataManagerPrefab: - RawGuidValue: 00000000000000000000000000000000 + RawGuidValue: 33a4edcf030b02446bd8e4bb9a0fb9f3 --- !u!1 &751090086 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Network/BasicSpawner.cs b/Assets/Scripts/Network/BasicSpawner.cs index f35a2ab1..14133bc4 100644 --- a/Assets/Scripts/Network/BasicSpawner.cs +++ b/Assets/Scripts/Network/BasicSpawner.cs @@ -248,6 +248,15 @@ namespace Hallucinate.UI { SendLocalMetaData(player); } + + // If the server receives a player join event and the scene is already loaded, spawn them immediately + if (runner.IsServer && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "Main Scene") + { + if (!_spawnedCharacters.ContainsKey(player)) + { + SpawnPlayer(runner, player); + } + } } private async void SendLocalMetaData(PlayerRef player) @@ -409,19 +418,40 @@ namespace Hallucinate.UI { foreach (var player in runner.ActivePlayers) { - Vector2 spawnPosition = (player == runner.LocalPlayer) ? new Vector2(-8, 0) : new Vector2(8, 0); - var networkPlayerObject = runner.Spawn(_playerPrefab, spawnPosition, Quaternion.identity, player); - // Give the client State Authority so they can move themselves - // networkPlayerObject.AssignStateAuthority(player); - _spawnedCharacters.Add(player, networkPlayerObject); + if (!_spawnedCharacters.ContainsKey(player)) + { + SpawnPlayer(runner, player); + } } } /*if (currentSceneName == "Main Scene") { UIManager.Instance?.OnGameStarted(); + / + BNM098TYU78I98IU7Y6T57U8I9I8U7Y6T57U8I7Y6T5Y67U8IU7Y6T57U8IU7Y6E4XDER45ESZXSDCER45EDSXZSDCEFR45TTRFGHJUIYTRW }*/ } + private void SpawnPlayer(NetworkRunner runner, PlayerRef player) + { + Vector3 spawnPosition = (player == runner.LocalPlayer) ? new Vector3(-8, 2, 0) : new Vector3(8, 2, 0); + var networkPlayerObject = runner.Spawn(_playerPrefab, spawnPosition, Quaternion.identity, player); + + networkPlayerObject.AssignInputAuthority(player); + + _spawnedCharacters[player] = networkPlayerObject; + } + + private void OnGUI() + { + if (_runner != null && _runner.IsRunning) + { + GUI.color = Color.green; + GUI.Label(new Rect(10, 10, 300, 30), $"[Network] Session: {_runner.SessionInfo?.Name}"); + GUI.Label(new Rect(10, 30, 300, 30), $"[Network] Players in Room: {_runner.ActivePlayers.Count()}"); + GUI.Label(new Rect(10, 50, 300, 30), $"[Network] Am I Server?: {_runner.IsServer}"); + } + } public void OnSceneLoadStart(NetworkRunner runner) { } } diff --git a/Assets/Scripts/Network/FusionClientMovementBridge.cs b/Assets/Scripts/Network/FusionClientMovementBridge.cs index 3ac523e7..683528f3 100644 --- a/Assets/Scripts/Network/FusionClientMovementBridge.cs +++ b/Assets/Scripts/Network/FusionClientMovementBridge.cs @@ -14,9 +14,8 @@ namespace Hallucinate.Network { public override void Spawned() { - // Because we passed State Authority to the client in BasicSpawner, - // HasStateAuthority is true ONLY for the local player. - bool isLocal = Object.HasStateAuthority; + // We use InputAuthority to identify the local player because this is Host mode. + bool isLocal = Object.HasInputAuthority; // 1. Isolate Input: Only the local player should read keyboard/mouse inputs. var locoHandler = GetComponent(); @@ -33,26 +32,68 @@ namespace Hallucinate.Network { cameraController.Character = gameObject; } + + // CRITICAL: Disable NetworkTransform on the local client so Fusion doesn't pull the character back! + var nt = GetComponent(); + if (nt != null) nt.enabled = false; } } // --- INetworkInfo Implementation --- - public bool IsLocalPlayer() => Object.HasStateAuthority; + // We use InputAuthority to identify the local player in Host/Client mode + public bool IsLocalPlayer() => Object.HasInputAuthority; public bool IsServer() => Runner.IsServer; - - // Return FALSE because we are doing Client-Authoritative movement! - public bool IsServerAuthoritative() => false; + public bool IsServerAuthoritative() => false; + // --- Client-Auth Movement Sync via RPC --- + // Since the Server holds State Authority, the client must send its transform to the server. + // The server then broadcasts it to everyone else via NetworkTransform. - // --- INetworkCharacter Implementation --- - // Since we are using Fusion's NetworkTransform to sync position, - // we can leave these methods empty. Opsive will handle the local - // movement, and Fusion's NetworkTransform will drag the remote players. - - public void SetPosition(Vector3 position, bool snapAnimator) { } - public void SetRotation(Quaternion rotation, bool snapAnimator) { } - public void SetPositionAndRotation(Vector3 position, Quaternion rotation, bool snapAnimator) { } + public override void FixedUpdateNetwork() + { + if (Object.HasInputAuthority) + { + RPC_UpdateTransform(transform.position, transform.rotation); + } + } + + public override void Render() + { + // If this is a remote proxy, Fusion's NetworkTransform will update the Unity transform. + // But Opsive maintains its own internal position and will snap it back unless we tell it to update! + if (!Object.HasInputAuthority) + { + var loco = GetComponent(); + if (loco != null) + { + // Feed the NetworkTransform's current position to Opsive so it knows we moved, + // which also allows the Animator to play the correct movement animations! + loco.SetPositionAndRotation(transform.position, transform.rotation, false); + } + } + } + + [Rpc(RpcSources.InputAuthority, RpcTargets.StateAuthority)] + private void RPC_UpdateTransform(Vector3 pos, Quaternion rot) + { + // The Server receives this and applies it. NetworkTransform then syncs it to all other clients. + transform.position = pos; + transform.rotation = rot; + } + + public void SetPosition(Vector3 position, bool snapAnimator) + { + if (Object.HasInputAuthority) transform.position = position; + } + public void SetRotation(Quaternion rotation, bool snapAnimator) + { + if (Object.HasInputAuthority) transform.rotation = rotation; + } + public void SetPositionAndRotation(Vector3 position, Quaternion rotation, bool snapAnimator) + { + if (Object.HasInputAuthority) transform.SetPositionAndRotation(position, rotation); + } public void ResetRotationPosition() { } public void SetActive(bool active, bool uiEvent) { } diff --git a/Assets/Settings/UniversalRenderPipelineGlobalSettings.asset b/Assets/Settings/UniversalRenderPipelineGlobalSettings.asset index 17db4432..b7271adb 100644 --- a/Assets/Settings/UniversalRenderPipelineGlobalSettings.asset +++ b/Assets/Settings/UniversalRenderPipelineGlobalSettings.asset @@ -68,7 +68,22 @@ MonoBehaviour: - rid: 5521631447830495244 - rid: 5521631447830495245 m_RuntimeSettings: - m_List: [] + m_List: + - rid: 6852985685364965378 + - rid: 6852985685364965379 + - rid: 6852985685364965380 + - rid: 6852985685364965381 + - rid: 6852985685364965384 + - rid: 6852985685364965385 + - rid: 6852985685364965392 + - rid: 6852985685364965394 + - rid: 8712630790384254976 + - rid: 5521631447830495233 + - rid: 5521631447830495234 + - rid: 5521631447830495237 + - rid: 5521631447830495238 + - rid: 5521631447830495243 + - rid: 5521631447830495245 m_AssetVersion: 10 m_ObsoleteDefaultVolumeProfile: {fileID: 0} m_RenderingLayerNames: diff --git a/ProjectSettings/BuildReportToolOptions.xml b/ProjectSettings/BuildReportToolOptions.xml new file mode 100644 index 00000000..86e72062 --- /dev/null +++ b/ProjectSettings/BuildReportToolOptions.xml @@ -0,0 +1,104 @@ + + + UnityBuildReports + 0 + true + true + true + false + true + false + true + false + true + true + true + true + true + true + true + true + true + true + true + + Textures + true + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + true + false + false + false + true + false + Models + false + false + true + false + true + false + true + Prefabs + false + true + false + false + false + false + false + true + true + true + true + true + 100 + true + false + true + 100 + 0 + 300 + true + 10000 + false + 0 + true + true + 0 + 256 + 256 + 512 + 512 + 10 + 10 + false + false + true + false + true + false + \ No newline at end of file diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 8ad74c60..82d4b132 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -5,15 +5,15 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 m_Scenes: - - enabled: 1 + - enabled: 0 path: "Assets/Scenes/Cho m\xF4n AI/Only AI.unity" guid: ce9b0298cc4351c4e82ac9f2339113de - - enabled: 1 + - enabled: 0 path: Assets/Scenes/UI.unity guid: 9feda3fec581ecb4aa311e4a937c625a - enabled: 1 path: Assets/Scenes/Main Scene.unity - guid: f6f338855ad36644f8143c150efa4089 + guid: eda5fe9b4dec586498dcf6d3f2e63088 m_configObjects: com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 052faaac586de48259a63d0c4782560b, type: 3} m_UseUCBPForAssetBundles: 0 diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index e2101f1f..a6266bf5 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -484,7 +484,10 @@ PlayerSettings: m_Height: 36 m_Kind: 0 m_SubKind: - m_BuildTargetBatching: [] + m_BuildTargetBatching: + - m_BuildTarget: Standalone + m_StaticBatching: 1 + m_DynamicBatching: 0 m_BuildTargetShaderSettings: [] m_BuildTargetGraphicsJobs: [] m_BuildTargetGraphicsJobMode: [] diff --git a/ProjectSettings/UnityConnectSettings.asset b/ProjectSettings/UnityConnectSettings.asset index 7a17e8f7..029ad8b9 100644 --- a/ProjectSettings/UnityConnectSettings.asset +++ b/ProjectSettings/UnityConnectSettings.asset @@ -4,7 +4,7 @@ UnityConnectSettings: m_ObjectHideFlags: 0 serializedVersion: 1 - m_Enabled: 1 + m_Enabled: 0 m_TestMode: 0 m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events m_EventUrl: https://cdp.cloud.unity3d.com/v1/events