Skip to content

Commit 1a65749

Browse files
committed
feat: make it able to disable addressables features by DISABLE_ADDRESSABLES compiling condition
1 parent 7158a17 commit 1a65749

7 files changed

Lines changed: 127 additions & 40 deletions

Scripts/GameApi/AddressableAssets/AssetReferenceLiteNetLibBehaviour.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !DISABLE_ADDRESSABLES
12
using UnityEngine;
23
#if UNITY_EDITOR
34
using UnityEditor;
@@ -82,4 +83,5 @@ public AssetReferenceLiteNetLibBehaviour(LiteNetLibBehaviour behaviour) : base(b
8283
}
8384
#endif
8485
}
85-
}
86+
}
87+
#endif

Scripts/GameApi/AddressableAssets/AssetReferenceLiteNetLibIdentity.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !DISABLE_ADDRESSABLES
12
using Insthync.AddressableAssetTools;
23
using UnityEngine;
34
#if UNITY_EDITOR
@@ -83,4 +84,5 @@ public virtual bool ValidateHashAssetID()
8384
}
8485
#endif
8586
}
86-
}
87+
}
88+
#endif

Scripts/GameApi/AddressableAssets/AssetReferenceSceneExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !DISABLE_ADDRESSABLES
12
using Insthync.AddressableAssetTools;
23

34
namespace LiteNetLibManager
@@ -20,3 +21,4 @@ public static ServerSceneInfo GetServerSceneInfo(this AssetReferenceScene scene)
2021
}
2122
}
2223
}
24+
#endif

Scripts/GameApi/LiteNetLibAdditiveSceneLoader.cs

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,110 @@
11
using Cysharp.Threading.Tasks;
22
using Insthync.AddressableAssetTools;
33
using UnityEngine;
4+
#if !DISABLE_ADDRESSABLES
45
using UnityEngine.AddressableAssets;
6+
#endif
57
using UnityEngine.SceneManagement;
68

79
namespace LiteNetLibManager
810
{
911
public class LiteNetLibAdditiveSceneLoader : MonoBehaviour
1012
{
1113
public SceneField[] scenes = new SceneField[0];
14+
#if !DISABLE_ADDRESSABLES
1215
public AssetReferenceScene[] addressableScenes = new AssetReferenceScene[0];
16+
#endif
1317
#if UNITY_SERVER || UNITY_EDITOR
1418
public SceneField[] serverOnlyScenes = new SceneField[0];
19+
#if !DISABLE_ADDRESSABLES
1520
public AssetReferenceScene[] serverOnlyAddressableScenes = new AssetReferenceScene[0];
1621
#endif
22+
#endif
1723
#if !UNITY_SERVER || UNITY_EDITOR
1824
public SceneField[] clientOnlyScenes = new SceneField[0];
25+
#if !DISABLE_ADDRESSABLES
1926
public AssetReferenceScene[] clientOnlyAddressableScenes = new AssetReferenceScene[0];
2027
#endif
28+
#endif
2129
#if UNITY_EDITOR
2230
public SceneField[] editorOnlyScenes = new SceneField[0];
31+
#if !DISABLE_ADDRESSABLES
2332
public AssetReferenceScene[] editorOnlyAddressableScenes = new AssetReferenceScene[0];
33+
#endif
2434
#endif
2535

2636
public int GetTotalLoadCount()
2737
{
2838
int total = 0;
29-
total += scenes.Length + addressableScenes.Length;
39+
total += scenes.Length;
40+
#if !DISABLE_ADDRESSABLES
41+
total += addressableScenes.Length;
42+
#endif
43+
3044
#if UNITY_SERVER
31-
total += serverOnlyScenes.Length + serverOnlyAddressableScenes.Length;
45+
total += serverOnlyScenes.Length;
46+
#if !DISABLE_ADDRESSABLES
47+
total += serverOnlyAddressableScenes.Length;
3248
#endif
49+
#endif
50+
3351
#if !UNITY_SERVER
34-
total += clientOnlyScenes.Length + clientOnlyAddressableScenes.Length;
52+
total += clientOnlyScenes.Length;
53+
#if !DISABLE_ADDRESSABLES
54+
total += clientOnlyAddressableScenes.Length;
3555
#endif
56+
#endif
57+
3658
#if UNITY_EDITOR
37-
total += editorOnlyScenes.Length + editorOnlyAddressableScenes.Length;
59+
total += editorOnlyScenes.Length;
60+
#if !DISABLE_ADDRESSABLES
61+
total += editorOnlyAddressableScenes.Length;
62+
#endif
3863
#endif
3964
return total;
4065
}
4166

4267
public async UniTask LoadAll(LiteNetLibGameManager manager, string sceneName, bool isOnline)
4368
{
4469
int loadCount = 0;
45-
loadCount = await LoadAll(manager, sceneName, isOnline, scenes, addressableScenes, loadCount);
70+
loadCount = await LoadAll(manager, sceneName, isOnline,
71+
scenes,
72+
#if !DISABLE_ADDRESSABLES
73+
addressableScenes,
74+
#endif
75+
loadCount);
4676
#if UNITY_SERVER
47-
loadCount = await LoadAll(manager, sceneName, isOnline, serverOnlyScenes, serverOnlyAddressableScenes, loadCount);
77+
loadCount = await LoadAll(manager, sceneName, isOnline,
78+
serverOnlyScenes,
79+
#if !DISABLE_ADDRESSABLES
80+
serverOnlyAddressableScenes,
81+
#endif
82+
loadCount);
4883
#endif
4984
#if !UNITY_SERVER
50-
loadCount = await LoadAll(manager, sceneName, isOnline, clientOnlyScenes, clientOnlyAddressableScenes, loadCount);
85+
loadCount = await LoadAll(manager, sceneName, isOnline,
86+
clientOnlyScenes,
87+
#if !DISABLE_ADDRESSABLES
88+
clientOnlyAddressableScenes,
89+
#endif
90+
loadCount);
5191
#endif
5292
#if UNITY_EDITOR
53-
loadCount = await LoadAll(manager, sceneName, isOnline, editorOnlyScenes, editorOnlyAddressableScenes, loadCount);
93+
loadCount = await LoadAll(manager, sceneName, isOnline,
94+
editorOnlyScenes,
95+
#if !DISABLE_ADDRESSABLES
96+
editorOnlyAddressableScenes,
97+
#endif
98+
loadCount);
5499
#endif
55100
}
56101

57-
public async UniTask<int> LoadAll(LiteNetLibGameManager manager, string sceneName, bool isOnline, SceneField[] scenes, AssetReferenceScene[] addressableScenes, int loadCount)
102+
public async UniTask<int> LoadAll(LiteNetLibGameManager manager, string sceneName, bool isOnline,
103+
SceneField[] scenes,
104+
#if !DISABLE_ADDRESSABLES
105+
AssetReferenceScene[] addressableScenes,
106+
#endif
107+
int loadCount)
58108
{
59109
// Load scene
60110
for (int i = 0; i < scenes.Length; ++i)
@@ -76,6 +126,7 @@ public async UniTask<int> LoadAll(LiteNetLibGameManager manager, string sceneNam
76126
manager.LoadedAdditiveScenesCount++;
77127
manager.Assets.onLoadAdditiveSceneProgress.Invoke(manager.LoadedAdditiveScenesCount, manager.TotalAdditiveScensCount);
78128
}
129+
#if !DISABLE_ADDRESSABLES
79130
// Load from addressable
80131
for (int i = 0; i < addressableScenes.Length; ++i)
81132
{
@@ -106,7 +157,8 @@ await AddressableAssetDownloadManager.Download(
106157
manager.LoadedAdditiveScenesCount++;
107158
manager.Assets.onLoadAdditiveSceneProgress.Invoke(manager.LoadedAdditiveScenesCount, manager.TotalAdditiveScensCount);
108159
}
160+
#endif
109161
return loadCount;
110162
}
111163
}
112-
}
164+
}

Scripts/GameApi/LiteNetLibAssets.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class LiteNetLibAssets : MonoBehaviour
1414
private static int s_spawnPositionCounter = 0;
1515

1616
public bool playerSpawnRandomly;
17-
#if !EXCLUDE_PREFAB_REFS
17+
#if !EXCLUDE_PREFAB_REFS || DISABLE_ADDRESSABLES
1818
#region Prefab Refs
1919
public LiteNetLibIdentity playerPrefab;
2020
public LiteNetLibIdentity[] spawnablePrefabs = new LiteNetLibIdentity[0];
@@ -24,6 +24,7 @@ public class LiteNetLibAssets : MonoBehaviour
2424
#endregion
2525
#endif
2626

27+
#if !DISABLE_ADDRESSABLES
2728
#region Addressable Assets Refs
2829
public AssetReferenceLiteNetLibIdentity addressablePlayerPrefab;
2930
public AssetReferenceLiteNetLibIdentity[] addressableSpawnablePrefabs = new AssetReferenceLiteNetLibIdentity[0];
@@ -33,6 +34,7 @@ public class LiteNetLibAssets : MonoBehaviour
3334
[Tooltip("If this is not empty, it will load online scene by this instead of `onlineScene`")]
3435
public AssetReferenceScene addressableOnlineScene;
3536
#endregion
37+
#endif
3638

3739
public UnityEvent onInitialize = new UnityEvent();
3840
public LiteNetLibLoadSceneEvent onLoadSceneStart = new LiteNetLibLoadSceneEvent();
@@ -112,7 +114,9 @@ public void Clear(bool doNotResetObjectId = false)
112114
ResetSpawnPositionCounter();
113115
if (!doNotResetObjectId)
114116
LiteNetLibIdentity.ResetObjectId();
117+
#if !DISABLE_ADDRESSABLES
115118
AddressableAssetsManager.ReleaseAll();
119+
#endif
116120
}
117121

118122
public void RegisterSpawnPoints()
@@ -123,7 +127,7 @@ public void RegisterSpawnPoints()
123127

124128
public async UniTask RegisterPrefabs()
125129
{
126-
#if !EXCLUDE_PREFAB_REFS
130+
#if !EXCLUDE_PREFAB_REFS || DISABLE_ADDRESSABLES
127131
for (int i = 0; i < spawnablePrefabs.Length; ++i)
128132
{
129133
RegisterPrefab(spawnablePrefabs[i]);
@@ -134,6 +138,8 @@ public async UniTask RegisterPrefabs()
134138
RegisterPrefab(playerPrefab);
135139
}
136140
#endif
141+
142+
#if !DISABLE_ADDRESSABLES
137143
List<UniTask<LiteNetLibIdentity>> ops = new List<UniTask<LiteNetLibIdentity>>();
138144
for (int i = 0; i < addressableSpawnablePrefabs.Length; ++i)
139145
{
@@ -147,6 +153,9 @@ public async UniTask RegisterPrefabs()
147153
ops.Add(RegisterAddressablePrefabAsync(addressablePlayerPrefab));
148154
}
149155
await UniTask.WhenAll(ops);
156+
#else
157+
await UniTask.Yield();
158+
#endif
150159
}
151160

152161
public LiteNetLibIdentity RegisterPrefab(LiteNetLibIdentity prefab)
@@ -172,6 +181,7 @@ public bool UnregisterPrefab(LiteNetLibIdentity prefab)
172181
return GuidToPrefabs.Remove(prefab.HashAssetId);
173182
}
174183

184+
#if !DISABLE_ADDRESSABLES
175185
public async UniTask<LiteNetLibIdentity> RegisterAddressablePrefabAsync(AssetReferenceLiteNetLibIdentity addressablePrefab)
176186
{
177187
if (!addressablePrefab.IsDataValid())
@@ -184,7 +194,9 @@ public async UniTask<LiteNetLibIdentity> RegisterAddressablePrefabAsync(AssetRef
184194
GuidToPrefabs[addressablePrefab.HashAssetId] = prefab;
185195
return prefab;
186196
}
197+
#endif
187198

199+
#if !DISABLE_ADDRESSABLES
188200
public bool UnregisterAddressablePrefab(AssetReferenceLiteNetLibIdentity addressablePrefab)
189201
{
190202
if (!addressablePrefab.IsDataValid())
@@ -195,6 +207,7 @@ public bool UnregisterAddressablePrefab(AssetReferenceLiteNetLibIdentity address
195207
if (Manager.LogDev) Logging.Log(LogTag, $"UnregisterAddressablePrefab [{addressablePrefab.HashAssetId}]");
196208
return GuidToPrefabs.Remove(addressablePrefab.HashAssetId);
197209
}
210+
#endif
198211

199212
public void ClearSpawnedObjects()
200213
{

0 commit comments

Comments
 (0)