Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
e1f20cd
added an implementation of two dynamic prefabs usage strategies
pdeschain Nov 3, 2022
677d9e6
Added brief readme
pdeschain Nov 3, 2022
2c803c3
Update Basic/DyanmicPrefabs/Assets/Scripts/01_Sparse loading with no …
pdeschain Nov 7, 2022
a0adc17
Update Basic/DyanmicPrefabs/Assets/Scripts/01_Sparse loading with no …
pdeschain Nov 7, 2022
c395fd4
slimmed down the package manifest
pdeschain Nov 7, 2022
233f715
swapped awake for async start, added more comments to help the user u…
pdeschain Nov 7, 2022
ad67a9b
sparse loading now ensures clients ack the prefab load before spawning
pdeschain Nov 8, 2022
1a07308
added server-side logic to not delay the spawn of a prefab that has a…
pdeschain Nov 9, 2022
ee6d50f
formatting
pdeschain Nov 9, 2022
320dc4a
wip adding latejoin support
pdeschain Nov 16, 2022
0c4b9fe
fixing some exceptions
pdeschain Nov 17, 2022
981af51
#
pdeschain Nov 17, 2022
7980ca6
#
pdeschain Nov 17, 2022
dc6071f
sparse loading works with latejoins
pdeschain Nov 21, 2022
192c0e9
Added functionality for spawning prefabs and keeping them hidden with…
pdeschain Nov 28, 2022
77d48c5
added a slightly better visual for prefab spawning
pdeschain Nov 28, 2022
886c58a
#
pdeschain Nov 28, 2022
a167a93
added better ui for controlling the spawning
pdeschain Nov 28, 2022
9cf2e8b
#
pdeschain Nov 28, 2022
ca9bc9c
#
pdeschain Nov 28, 2022
e66bf06
spawn methods now require initial position and rotation
pdeschain Nov 29, 2022
e157e8e
naming adjustments and cleanup
pdeschain Nov 29, 2022
9b3481a
Apply suggestions from code review
pdeschain Nov 30, 2022
98ca264
Update Basic/DyanmicPrefabs/README.md
pdeschain Nov 30, 2022
208583e
updated readmer
pdeschain Nov 30, 2022
ea597a5
Merge branch 'pdeschain/dynamic-prefabs-exploration' of github.com:Un…
pdeschain Nov 30, 2022
a953b2d
delay for addressable loadings, fix for latejoiners during synchrnono…
pdeschain Nov 30, 2022
64c09d2
added suggestions for further improvements
pdeschain Nov 30, 2022
94f340c
editor update to 2021.3.15f1 & NGO 1.2.0
fernando-cortez Jan 5, 2023
a5427b4
refactored the custommessage usage to use NGO's DisconnectReason
fernando-cortez Jan 9, 2023
e1cfec7
UI toolkit visual assets
jilfranco-unity Jan 16, 2023
dc855e3
connection flow converted to a state machine
fernando-cortez Jan 17, 2023
8cc293e
comments
fernando-cortez Jan 17, 2023
4a6fe8d
disconnection logic on connected states & logging
fernando-cortez Jan 19, 2023
9f3b5fc
comments
fernando-cortez Jan 20, 2023
6529353
restructuring of scripts and scenes
fernando-cortez Feb 1, 2023
b09fc5f
UI updates, pushing to grab latest changes
jilfranco-unity Feb 4, 2023
bc67470
Merge branch 'develop' into pdeschain/dynamic-prefabs-exploration
fernando-cortez Feb 6, 2023
99702d8
added UI hookups, testing methods, and fixed a visual bug with the in…
jilfranco-unity Feb 6, 2023
2e3ce03
updated sort order of the UI
jilfranco-unity Feb 6, 2023
46916da
Merge branch 'pdeschain/dynamic-prefabs-exploration' into feat/dp-uit…
jilfranco-unity Feb 6, 2023
b7507c7
Bit of UI structural refactor, added functionality for sliders, check…
jilfranco-unity Feb 7, 2023
2ab3082
further restructuring WIP (previous methods working, outstanding is c…
fernando-cortez Feb 7, 2023
88b2620
dynamic prefab status utilities made into static class, reconnection …
fernando-cortez Feb 8, 2023
cbaf97f
formatting and added a scripting define for artificial delay
fernando-cortez Feb 8, 2023
ac571b9
refactoring/comments of all use cases
fernando-cortez Feb 9, 2023
28584c9
Merge branch 'fernando/dynamic-prefabs-restructuring' into pdeschain/…
fernando-cortez Feb 9, 2023
9071eda
Merge branch 'develop' into pdeschain/dynamic-prefabs-exploration
fernando-cortez Feb 9, 2023
abdc697
removing unnecessary async operation on already loaded prefab
fernando-cortez Feb 9, 2023
62e18d2
Merge remote-tracking branch 'origin/pdeschain/dynamic-prefabs-explor…
jilfranco-unity Feb 10, 2023
e7fc21f
deleted an unused package and addressed some feedback on the HostJoin…
jilfranco-unity Feb 10, 2023
5bdf2bc
renaming cleanup, AddressableGUID dictionary lookups don't create all…
fernando-cortez Feb 10, 2023
4d93f70
parity of use case scene names and scripts
fernando-cortez Feb 10, 2023
bcaa76f
addressing a few more PR comments
fernando-cortez Feb 10, 2023
6f5fdc6
a few more PR comments addressed
fernando-cortez Feb 10, 2023
7861d1a
more PR feedback addressed, AddressableGUIDCollection no longer neces…
fernando-cortez Feb 13, 2023
f0f6c57
AppController didn't need to be NetworkBehaviour, comments
fernando-cortez Feb 13, 2023
dff67c3
fix on last commit for in-scene networkbehaviours on shutdown
fernando-cortez Feb 13, 2023
ee38388
removing debug comment
fernando-cortez Feb 13, 2023
3458709
removing remarks that will go inside of readme
fernando-cortez Feb 13, 2023
51aa3fb
Added a namespace to these UI scripts and also moved them to a new UI…
jilfranco-unity Feb 13, 2023
36de5fe
more remarks added to the use cases
fernando-cortez Feb 13, 2023
81fa4c7
grammar fix
fernando-cortez Feb 13, 2023
a177762
renamed these files with more accurate names
jilfranco-unity Feb 13, 2023
9eefd42
harmonizing visibility terminology in docs
fernando-cortez Feb 13, 2023
e49a5cb
deleted some unused methods and an unused button, and updated a varia…
jilfranco-unity Feb 13, 2023
aafec48
these lines no longer needed because this button has been removed
jilfranco-unity Feb 13, 2023
c88ae27
added a public getter to and renamed these variables
jilfranco-unity Feb 13, 2023
e79d338
deleted a debug.log
jilfranco-unity Feb 13, 2023
83f4a84
upgrade to 2021.3.18f1 LTS
fernando-cortez Feb 13, 2023
f1f0ab8
comment fix
fernando-cortez Feb 13, 2023
a2ebb0e
updated the UI scripts to not handle any networking logic, but to rat…
jilfranco-unity Feb 14, 2023
0b601ef
renamed project to DynamicAddressablesNetworkPrefabs
fernando-cortez Feb 14, 2023
113aaf1
comments
fernando-cortez Feb 14, 2023
c655065
Merge remote-tracking branch 'origin/pdeschain/dynamic-prefabs-explor…
jilfranco-unity Feb 14, 2023
19dfc2e
Removed uxml schemas from the old folder structure and generated ui t…
jilfranco-unity Feb 14, 2023
25d9106
Merge branch 'develop' into feat/dp-uitoolkit-ui
jilfranco-unity Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
264 changes: 264 additions & 0 deletions Basic/DynamicAddressablesNetworkPrefabs/Assets/Prefabs/UI.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4061078000728451377
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4484396944538767948}
- component: {fileID: 1868617790277435607}
m_Layer: 0
m_Name: ConnectionType
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4484396944538767948
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4061078000728451377}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5916229021262027593}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1868617790277435607
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4061078000728451377}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_PanelSettings: {fileID: 11400000, guid: c023b7db6d50c9e45b6a080ccc23874f, type: 2}
m_ParentUI: {fileID: 0}
sourceAsset: {fileID: 9197481963319205126, guid: 720681dc71c9789408a1fab0f21e0f93, type: 3}
m_SortingOrder: 1
--- !u!1 &5916229021262027592
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5916229021262027593}
- component: {fileID: 1216736892}
- component: {fileID: 1085470603439750153}
m_Layer: 0
m_Name: UI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5916229021262027593
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5916229021262027592}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5916229021887624318}
- {fileID: 5916229022476518943}
- {fileID: 5916229022061089010}
- {fileID: 4484396944538767948}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1216736892
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5916229021262027592}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6c1ed03cc3b245b4ca88b95ef9bea14e, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ConnectionsUIDoc: {fileID: 5916229021887624317}
m_InGameUIDoc: {fileID: 5916229022476518942}
m_ConnectionTemplatePrefab: {fileID: 9197481963319205126, guid: 559dc6bda8f869d4b828b29a963e1e89, type: 3}
m_RowTemplatePrefab: {fileID: 9197481963319205126, guid: e61c0a6ba4a28444da358d17a074172f, type: 3}
m_ShowLoadAllAsyncButton: 1
m_ShowTrySpawnSynchronouslyButton: 1
m_ShowSpawnUsingVisibilityButton: 1
--- !u!114 &1085470603439750153
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5916229021262027592}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ada9189cf150a904bb8090bcb9e80a6c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IPMenuUIDocument: {fileID: 5916229022061089011}
m_ConnectionTypeUIDocument: {fileID: 1868617790277435607}
--- !u!1 &5916229021887624316
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5916229021887624318}
- component: {fileID: 5916229021887624317}
m_Layer: 0
m_Name: Connections
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5916229021887624318
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5916229021887624316}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5916229021262027593}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5916229021887624317
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5916229021887624316}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_PanelSettings: {fileID: 11400000, guid: c023b7db6d50c9e45b6a080ccc23874f, type: 2}
m_ParentUI: {fileID: 0}
sourceAsset: {fileID: 9197481963319205126, guid: aa2f8502baa527549a2a096d7db99736, type: 3}
m_SortingOrder: 1
--- !u!1 &5916229022061089009
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5916229022061089010}
- component: {fileID: 5916229022061089011}
m_Layer: 0
m_Name: IPMenu
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5916229022061089010
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5916229022061089009}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5916229021262027593}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5916229022061089011
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5916229022061089009}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_PanelSettings: {fileID: 11400000, guid: c023b7db6d50c9e45b6a080ccc23874f, type: 2}
m_ParentUI: {fileID: 0}
sourceAsset: {fileID: 9197481963319205126, guid: f34559e6fa10dd7498466b9da1869b6d, type: 3}
m_SortingOrder: 0
--- !u!1 &5916229022476518941
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5916229022476518943}
- component: {fileID: 5916229022476518942}
m_Layer: 0
m_Name: InGameUI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5916229022476518943
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5916229022476518941}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5916229021262027593}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5916229022476518942
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5916229022476518941}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_PanelSettings: {fileID: 11400000, guid: c023b7db6d50c9e45b6a080ccc23874f, type: 2}
m_ParentUI: {fileID: 0}
sourceAsset: {fileID: 9197481963319205126, guid: 16051812210b8ab4bb7c93577ca1410b, type: 3}
m_SortingOrder: 1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Threading.Tasks;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AddressableAssets;

namespace Game.PreloadingDynamicPrefabs
{
/// <summary>
/// This is the simplest case of a dynamic prefab - we instruct all game instances to load a network prefab (it can
/// be just one, it could also be a set of network prefabs) and inject them to NetworkManager's NetworkPrefabs list
/// before starting the server. What's important is that it doesn't really matter where the prefab comes from. It
/// could be a simple prefab or it could be an Addressable - it's all the same.
/// </summary>
/// <remarks>
/// Here, we're serializing the AssetReferenceGameObject to this class, but ideally you'd want to authenticate
/// players when your game starts up and have them fetch network prefabs from services such as UGS (see Remote
/// Config). It should also be noted that this is a technique that could serve to decrease the install size of your
/// application, since you'd be streaming in networked game assets dynamically.
/// </remarks>
public sealed class PreloadingDynamicPrefabs : MonoBehaviour
{
[SerializeField] AssetReferenceGameObject m_DynamicPrefabReference;

[SerializeField] NetworkManager m_NetworkManager;

async void Start()
{
await PreloadDynamicPlayerPrefab();
//after we've waited for the prefabs to load - we can start the host or the client
}

// It's important to note that this isn't limited to PlayerPrefab, despite the method name you can add any
// prefab to the list of prefabs that will be spawned.
async Task PreloadDynamicPlayerPrefab()
{
Debug.Log($"Started to load addressable with GUID: {m_DynamicPrefabReference.AssetGUID}");
var op = Addressables.LoadAssetAsync<GameObject>(m_DynamicPrefabReference);
var prefab = await op.Task;
Addressables.Release(op);

//it's important to actually add the player prefab to the list of network prefabs - it doesn't happen
//automatically
m_NetworkManager.AddNetworkPrefab(prefab);
Debug.Log($"Loaded prefab has been assigned to NetworkManager's PlayerPrefab");

// at this point we can easily change the PlayerPrefab
m_NetworkManager.NetworkConfig.PlayerPrefab = prefab;

// Forcing all game instances to load a set of network prefabs and having each game instance inject network
// prefabs to NetworkManager's NetworkPrefabs list pre-connection time guarantees that all players will have
// matching NetworkConfigs. This is why NetworkManager.ForceSamePrefabs is set to true. We let Netcode for
// GameObjects validate the matching NetworkConfigs between clients and the server. If this is set to false
// on the server, clients may join with a mismatching NetworkPrefabs list from the server.
m_NetworkManager.NetworkConfig.ForceSamePrefabs = true;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading