diff --git a/.yamato/project.metafile b/.yamato/project.metafile index a19c1dec..3030e604 100644 --- a/.yamato/project.metafile +++ b/.yamato/project.metafile @@ -28,4 +28,6 @@ projects: - name: invaders path: Basic/Invaders - name: clientdriven - path: Basic/ClientDriven \ No newline at end of file + path: Basic/ClientDriven + - name: dynamicaddressablesnetworkprefabs + path: Basic/DynamicAddressablesNetworkPrefabs \ No newline at end of file diff --git a/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/02_Server Authoritative Load All Async/ServerAuthoritativeLoadAllAsync.cs b/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/02_Server Authoritative Load All Async/ServerAuthoritativeLoadAllAsync.cs index cc42d400..41888602 100644 --- a/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/02_Server Authoritative Load All Async/ServerAuthoritativeLoadAllAsync.cs +++ b/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/02_Server Authoritative Load All Async/ServerAuthoritativeLoadAllAsync.cs @@ -172,14 +172,19 @@ namespace Game.ServerAuthoritativeLoadAllAsync Debug.Log("Loading dynamic prefab on the clients..."); LoadAddressableClientRpc(assetGuid); - // server is starting to load a prefab, update UI - m_InGameUI.ClientLoadedPrefabStatusChanged(NetworkManager.ServerClientId, assetGuid.GetHashCode(), "Undefined", InGameUI.LoadStatus.Loading); - await DynamicPrefabLoadingUtilities.LoadDynamicPrefab(assetGuid, m_InGameUI.ArtificialDelayMilliseconds); // server loaded a prefab, update UI with the loaded asset's name DynamicPrefabLoadingUtilities.TryGetLoadedGameObjectFromGuid(assetGuid, out var loadedGameObject); - m_InGameUI.ClientLoadedPrefabStatusChanged(NetworkManager.ServerClientId, assetGuid.GetHashCode(), loadedGameObject.Result.name, InGameUI.LoadStatus.Loaded); + + // every client loaded dynamic prefab, their respective ClientUIs in case they loaded first + foreach (var client in m_NetworkManager.ConnectedClients.Keys) + { + m_InGameUI.ClientLoadedPrefabStatusChanged(client, + assetGuid.GetHashCode(), + loadedGameObject.Result.name, + InGameUI.LoadStatus.Loading); + } } } @@ -214,13 +219,20 @@ namespace Game.ServerAuthoritativeLoadAllAsync DynamicPrefabLoadingUtilities.RecordThatClientHasLoadedAPrefab(prefabHash, rpcParams.Receive.SenderClientId); // a quick way to grab a matching prefab reference's name via its prefabHash - var loadedPrefabName = prefabHash.ToString(); + var loadedPrefabName = "Undefined"; foreach (var prefabReference in m_DynamicPrefabReferences) { var prefabReferenceGuid = new AddressableGUID() { Value = prefabReference.AssetGUID }; if (prefabReferenceGuid.GetHashCode() == prefabHash) { - loadedPrefabName = prefabReference.editorAsset.name; + // found the matching prefab reference + if (DynamicPrefabLoadingUtilities.LoadedDynamicPrefabResourceHandles.TryGetValue( + prefabReferenceGuid, + out var loadedGameObject)) + { + // if it is loaded on the server, update the name on the ClientUI + loadedPrefabName = loadedGameObject.Result.name; + } break; } } diff --git a/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/03_Server Authoritative Synchronous Spawning/ServerAuthoritativeSynchronousSpawning.cs b/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/03_Server Authoritative Synchronous Spawning/ServerAuthoritativeSynchronousSpawning.cs index ee37dd93..38d1ed5b 100644 --- a/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/03_Server Authoritative Synchronous Spawning/ServerAuthoritativeSynchronousSpawning.cs +++ b/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/03_Server Authoritative Synchronous Spawning/ServerAuthoritativeSynchronousSpawning.cs @@ -220,6 +220,16 @@ namespace Game.ServerAuthoritativeSynchronousSpawning var obj = Instantiate(prefab.Result, position, rotation).GetComponent(); obj.Spawn(); Debug.Log("Spawned dynamic prefab"); + + // every client loaded dynamic prefab, their respective ClientUIs in case they loaded first + foreach (var client in m_NetworkManager.ConnectedClients.Keys) + { + m_InGameUI.ClientLoadedPrefabStatusChanged(client, + assetGuid.GetHashCode(), + prefab.Result.name, + InGameUI.LoadStatus.Loading); + } + return obj; } } @@ -257,13 +267,20 @@ namespace Game.ServerAuthoritativeSynchronousSpawning rpcParams.Receive.SenderClientId); // a quick way to grab a matching prefab reference's name via its prefabHash - var loadedPrefabName = prefabHash.ToString(); + var loadedPrefabName = "Undefined"; foreach (var prefabReference in m_DynamicPrefabReferences) { var prefabReferenceGuid = new AddressableGUID() { Value = prefabReference.AssetGUID }; if (prefabReferenceGuid.GetHashCode() == prefabHash) { - loadedPrefabName = prefabReference.editorAsset.name; + // found the matching prefab reference + if (DynamicPrefabLoadingUtilities.LoadedDynamicPrefabResourceHandles.TryGetValue( + prefabReferenceGuid, + out var loadedGameObject)) + { + // if it is loaded on the server, update the name on the ClientUI + loadedPrefabName = loadedGameObject.Result.name; + } break; } } diff --git a/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/04_Server Authoritative Network-Visibility Spawning/ServerAuthoritativeNetworkVisibilitySpawning.cs b/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/04_Server Authoritative Network-Visibility Spawning/ServerAuthoritativeNetworkVisibilitySpawning.cs index b6d10ad4..4b391df2 100644 --- a/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/04_Server Authoritative Network-Visibility Spawning/ServerAuthoritativeNetworkVisibilitySpawning.cs +++ b/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/04_Server Authoritative Network-Visibility Spawning/ServerAuthoritativeNetworkVisibilitySpawning.cs @@ -280,13 +280,20 @@ namespace Game.ServerAuthoritativeNetworkVisibilitySpawning } // a quick way to grab a matching prefab reference's name via its prefabHash - var loadedPrefabName = prefabHash.ToString(); + var loadedPrefabName = "Undefined"; foreach (var prefabReference in m_DynamicPrefabReferences) { var prefabReferenceGuid = new AddressableGUID() { Value = prefabReference.AssetGUID }; if (prefabReferenceGuid.GetHashCode() == prefabHash) { - loadedPrefabName = prefabReference.editorAsset.name; + // found the matching prefab reference + if (DynamicPrefabLoadingUtilities.LoadedDynamicPrefabResourceHandles.TryGetValue( + prefabReferenceGuid, + out var loadedGameObject)) + { + // if it is loaded on the server, update the name on the ClientUI + loadedPrefabName = loadedGameObject.Result.name; + } break; } } diff --git a/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/05_API Playground/APIPlayground.cs b/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/05_API Playground/APIPlayground.cs index 8a3d23c4..43161703 100644 --- a/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/05_API Playground/APIPlayground.cs +++ b/Basic/DynamicAddressablesNetworkPrefabs/Assets/Scripts/05_API Playground/APIPlayground.cs @@ -226,20 +226,28 @@ namespace Game.APIPlayground // update UI for each client that is requested to load a certain prefab foreach (var client in m_NetworkManager.ConnectedClients.Keys) { - m_InGameUI.ClientLoadedPrefabStatusChanged(client, assetGuid.GetHashCode(), "Undefined", InGameUI.LoadStatus.Loading); + m_InGameUI.ClientLoadedPrefabStatusChanged(client, + assetGuid.GetHashCode(), + "Undefined", + InGameUI.LoadStatus.Loading); } Debug.Log("Loading dynamic prefab on the clients..."); LoadAddressableClientRpc(assetGuid); - - // server is starting to load a prefab, update UI - m_InGameUI.ClientLoadedPrefabStatusChanged(NetworkManager.ServerClientId, assetGuid.GetHashCode(), "Undefined", InGameUI.LoadStatus.Loading); await DynamicPrefabLoadingUtilities.LoadDynamicPrefab(assetGuid, m_InGameUI.ArtificialDelayMilliseconds); // server loaded a prefab, update UI with the loaded asset's name DynamicPrefabLoadingUtilities.TryGetLoadedGameObjectFromGuid(assetGuid, out var loadedGameObject); - m_InGameUI.ClientLoadedPrefabStatusChanged(NetworkManager.ServerClientId, assetGuid.GetHashCode(), loadedGameObject.Result.name, InGameUI.LoadStatus.Loaded); + + // every client loaded dynamic prefab, their respective ClientUIs in case they loaded first + foreach (var client in m_NetworkManager.ConnectedClients.Keys) + { + m_InGameUI.ClientLoadedPrefabStatusChanged(client, + assetGuid.GetHashCode(), + loadedGameObject.Result.name, + InGameUI.LoadStatus.Loading); + } } } @@ -322,6 +330,16 @@ namespace Game.APIPlayground var obj = Instantiate(prefab.Result, position, rotation).GetComponent(); obj.Spawn(); Debug.Log("Spawned dynamic prefab"); + + // every client loaded dynamic prefab, their respective ClientUIs in case they loaded first + foreach (var client in m_NetworkManager.ConnectedClients.Keys) + { + m_InGameUI.ClientLoadedPrefabStatusChanged(client, + assetGuid.GetHashCode(), + prefab.Result.name, + InGameUI.LoadStatus.Loading); + } + return obj; } } @@ -462,13 +480,20 @@ namespace Game.APIPlayground } // a quick way to grab a matching prefab reference's name via its prefabHash - var loadedPrefabName = prefabHash.ToString(); + var loadedPrefabName = "Undefined"; foreach (var prefabReference in m_DynamicPrefabReferences) { var prefabReferenceGuid = new AddressableGUID() { Value = prefabReference.AssetGUID }; if (prefabReferenceGuid.GetHashCode() == prefabHash) { - loadedPrefabName = prefabReference.editorAsset.name; + // found the matching prefab reference + if (DynamicPrefabLoadingUtilities.LoadedDynamicPrefabResourceHandles.TryGetValue( + prefabReferenceGuid, + out var loadedGameObject)) + { + // if it is loaded on the server, update the name on the ClientUI + loadedPrefabName = loadedGameObject.Result.name; + } break; } }