|
1 | 1 | using System; |
2 | 2 | using System.Collections; |
3 | 3 | using System.Collections.Generic; |
4 | | -using System.IO; |
5 | 4 | using System.Linq; |
6 | 5 | using System.Reflection; |
7 | 6 | using System.Runtime.CompilerServices; |
8 | 7 | using System.Text; |
9 | 8 | using NUnit.Framework; |
10 | | -using Unity.Entities; |
11 | 9 | using Unity.NetCode; |
12 | 10 | using Unity.Netcode.RuntimeTests; |
13 | 11 | using Unity.Netcode.Transports.UTP; |
14 | | -using UnityEditor; |
15 | 12 | using UnityEngine; |
16 | 13 | using UnityEngine.SceneManagement; |
17 | 14 | using UnityEngine.TestTools; |
@@ -2210,75 +2207,68 @@ protected GameObject CreateNetworkObjectPrefab(string baseName) |
2210 | 2207 | } |
2211 | 2208 |
|
2212 | 2209 | #if UNIFIED_NETCODE |
2213 | | - |
2214 | 2210 | protected GameObject CreateHybridPrefab(string baseName, bool moveToDDOL = true) |
2215 | 2211 | { |
2216 | 2212 | // Prevent from trying to register/spawn when creating this hybrid prefab |
2217 | | - GhostBehaviour.IsCreatingPrefab = true; |
2218 | 2213 | var gameObject = new GameObject |
2219 | 2214 | { |
2220 | 2215 | name = baseName |
2221 | 2216 | }; |
2222 | 2217 |
|
2223 | | - // Wrap the rest in case a bug (or the like) is introduced and an exception is thrown |
2224 | | - // so we can assure to set IsCreatingPrefab back to false. |
2225 | | - try |
2226 | | - { |
2227 | | - // TODO: We might think if there is a better way to handle this, but GhostBehaviour is dependent |
2228 | | - // upon GhostObject having run through its Awake prior to it and NetworkObject needs to access |
2229 | | - // the NetowrkObjectId GhostField which depends upon GhostBehaviour. |
2230 | | - |
2231 | | - // Order of operations in how these execute is actually important. |
2232 | | - // GhostObject should execute 1st. |
2233 | | - // NetworkObjectBridge 2nd. |
2234 | | - // NetworkObject 3rd. |
2235 | | - // NetworkBehaviours will execute in the order they are arranged unless otherwise specified. |
2236 | | - var adapter = gameObject.AddComponent<GhostAdapter>(); |
2237 | | - var bridge = gameObject.AddComponent<NetworkObjectBridge>(); |
2238 | | - var no = gameObject.AddComponent<NetworkObject>(); |
2239 | | - |
2240 | | - // Ghost specific settings |
2241 | | - no.HasGhost = true; |
2242 | | - no.GhostAdapter = adapter; |
2243 | | - no.HadBridge = true; |
2244 | | - no.NetworkObjectBridge = bridge; |
2245 | | - |
2246 | | - // This gets automatically disabled when NetworkObject is validated. |
2247 | | - no.SynchronizeTransform = false; |
2248 | | - no.SceneMigrationSynchronization = false; |
2249 | | - |
2250 | | - // Make sure this is not a scene object |
2251 | | - no.IsSceneObject = false; |
2252 | | - |
2253 | | - // TODO: This might be part of the CreateHybridPrefab parameters |
2254 | | - // For now, just use normal interpolation until we get integration |
2255 | | - // tests running. |
2256 | | - // Once we have validated prediction works and have a working manual |
2257 | | - // test, we can circle back to this (possibly make that a sub-task |
2258 | | - // with the dependency to prediction manual test). |
2259 | | - adapter.SupportedGhostModes = GhostModeMask.Interpolated; |
2260 | | - |
2261 | | - // Mark the reference as post processing to avoid registering this instance automatically |
2262 | | - GhostPrefabReference.s_IsPostProcessing = true; |
2263 | | - adapter.prefabReference = ScriptableObject.CreateInstance<GhostPrefabReference>(); |
2264 | | - adapter.prefabReference.name = "GhostPrefabReference"; |
2265 | | - adapter.prefabReference.Prefab = gameObject; |
2266 | | - adapter.prefabReference.Ghost = adapter; |
2267 | | - GhostPrefabReference.s_IsPostProcessing = false; |
2268 | | - |
2269 | | - // Turn it into a test prefab |
2270 | | - NetcodeIntegrationTestHelpers.MakeNetworkObjectTestPrefab(no); |
2271 | | - if (moveToDDOL) |
2272 | | - { |
2273 | | - Object.DontDestroyOnLoad(gameObject); |
2274 | | - } |
2275 | | - } |
2276 | | - catch (Exception ex) |
2277 | | - { |
2278 | | - Debug.LogException(ex); |
| 2218 | + // Order of operations in how these execute is actually important. |
| 2219 | + // GhostObject should execute 1st. |
| 2220 | + // NetworkObjectBridge 2nd. |
| 2221 | + // NetworkObject 3rd. |
| 2222 | + // NetworkBehaviours will execute in the order they are arranged unless otherwise specified. |
| 2223 | + |
| 2224 | + // When adding a Hybrid/Ghost prefab: |
| 2225 | + // - We disabled the GameObject prior to adding the GhostPrefabReference (so IsPrefab() == true). |
| 2226 | + // - Add the GhostAdapter and GhostPrefabReference |
| 2227 | + // - Then set it back to active. |
| 2228 | + gameObject.SetActive(false); |
| 2229 | + var adapter = gameObject.AddComponent<GhostAdapter>(); |
| 2230 | + // Mark the reference as post processing to avoid registering this instance automatically. |
| 2231 | + GhostPrefabReference.s_IsPostProcessing = true; |
| 2232 | + adapter.prefabReference = ScriptableObject.CreateInstance<GhostPrefabReference>(); |
| 2233 | + adapter.prefabReference.name = "GhostPrefabReference"; |
| 2234 | + adapter.prefabReference.Prefab = gameObject; |
| 2235 | + adapter.prefabReference.Ghost = adapter; |
| 2236 | + GhostPrefabReference.s_IsPostProcessing = false; |
| 2237 | + |
| 2238 | + // TODO: This might be part of the CreateHybridPrefab parameters |
| 2239 | + // For now, just use normal interpolation until we get integration |
| 2240 | + // tests running. |
| 2241 | + // Once we have validated prediction works and have a working manual |
| 2242 | + // test, we can circle back to this (possibly make that a sub-task |
| 2243 | + // with the dependency to prediction manual test). |
| 2244 | + adapter.SupportedGhostModes = GhostModeMask.Interpolated; |
| 2245 | + |
| 2246 | + // Once done with setting up the GhostAdapter, we can set it back to active in the hierarchy |
| 2247 | + gameObject.SetActive(true); |
| 2248 | + |
| 2249 | + // GhostBehaviours that are part of a prefab will not invoke Ghost.InternalAcquireEntityReference |
| 2250 | + // Add the bridge |
| 2251 | + var bridge = gameObject.AddComponent<NetworkObjectBridge>(); |
| 2252 | + |
| 2253 | + // Now add NGO components |
| 2254 | + var no = gameObject.AddComponent<NetworkObject>(); |
| 2255 | + |
| 2256 | + // NetworkObject Ghost specific settings |
| 2257 | + no.HasGhost = true; |
| 2258 | + no.GhostAdapter = adapter; |
| 2259 | + no.HadBridge = true; |
| 2260 | + no.NetworkObjectBridge = bridge; |
| 2261 | + |
| 2262 | + // Disable transform synchronization for NetworkObject serialization |
| 2263 | + // since that is handled by the GhostAdapter. |
| 2264 | + no.SynchronizeTransform = false; |
| 2265 | + |
| 2266 | + // Turn it into a test prefab |
| 2267 | + NetcodeIntegrationTestHelpers.MakeNetworkObjectTestPrefab(no); |
| 2268 | + if (moveToDDOL) |
| 2269 | + { |
| 2270 | + Object.DontDestroyOnLoad(gameObject); |
2279 | 2271 | } |
2280 | | - // Always reset |
2281 | | - GhostBehaviour.IsCreatingPrefab = false; |
2282 | 2272 | return gameObject; |
2283 | 2273 | } |
2284 | 2274 | #endif |
|
0 commit comments