From 3afd54e18227b36614a5bbc1ce8e70944bf30690 Mon Sep 17 00:00:00 2001 From: MrGadget1024 Date: Wed, 29 Sep 2021 11:28:56 -0400 Subject: [PATCH] Minor updates to AdditiveScenes example --- .../Scripts/AdditiveNetworkManager.cs | 20 +++++++++---------- .../AdditiveScenes/Scripts/ZoneHandler.cs | 10 ++++------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs b/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs index a022c2c8c..d781a951e 100644 --- a/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs +++ b/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs @@ -25,6 +25,16 @@ public override void OnStartServer() Instantiate(Zone); } + public override void OnStopServer() + { + StartCoroutine(UnloadScenes()); + } + + public override void OnStopClient() + { + StartCoroutine(UnloadScenes()); + } + IEnumerator LoadSubScenes() { Debug.Log("Loading Scenes"); @@ -36,16 +46,6 @@ IEnumerator LoadSubScenes() } } - public override void OnStopServer() - { - StartCoroutine(UnloadScenes()); - } - - public override void OnStopClient() - { - StartCoroutine(UnloadScenes()); - } - IEnumerator UnloadScenes() { Debug.Log("Unloading Subscenes"); diff --git a/Assets/Mirror/Examples/AdditiveScenes/Scripts/ZoneHandler.cs b/Assets/Mirror/Examples/AdditiveScenes/Scripts/ZoneHandler.cs index a09bafc5b..a03a3a5ae 100644 --- a/Assets/Mirror/Examples/AdditiveScenes/Scripts/ZoneHandler.cs +++ b/Assets/Mirror/Examples/AdditiveScenes/Scripts/ZoneHandler.cs @@ -14,22 +14,20 @@ public class ZoneHandler : MonoBehaviour [Tooltip("Assign the sub-scene to load for this zone")] public string subScene; + [ServerCallback] void OnTriggerEnter(Collider other) { - if (!NetworkServer.active) return; - - // Debug.LogFormat(LogType.Log, "Loading {0}", subScene); + // Debug.Log($"Loading {subScene}"); NetworkIdentity networkIdentity = other.gameObject.GetComponent(); SceneMessage message = new SceneMessage{ sceneName = subScene, sceneOperation = SceneOperation.LoadAdditive }; networkIdentity.connectionToClient.Send(message); } + [ServerCallback] void OnTriggerExit(Collider other) { - if (!NetworkServer.active) return; - - // Debug.LogFormat(LogType.Log, "Unloading {0}", subScene); + // Debug.Log($"Unloading {subScene}"); NetworkIdentity networkIdentity = other.gameObject.GetComponent(); SceneMessage message = new SceneMessage{ sceneName = subScene, sceneOperation = SceneOperation.UnloadAdditive };