Minor updates to AdditiveScenes example

This commit is contained in:
MrGadget1024 2021-09-29 11:28:56 -04:00
parent 1f1d13ed42
commit 3afd54e182
2 changed files with 14 additions and 16 deletions

View File

@ -25,6 +25,16 @@ public override void OnStartServer()
Instantiate(Zone); Instantiate(Zone);
} }
public override void OnStopServer()
{
StartCoroutine(UnloadScenes());
}
public override void OnStopClient()
{
StartCoroutine(UnloadScenes());
}
IEnumerator LoadSubScenes() IEnumerator LoadSubScenes()
{ {
Debug.Log("Loading Scenes"); Debug.Log("Loading Scenes");
@ -36,16 +46,6 @@ IEnumerator LoadSubScenes()
} }
} }
public override void OnStopServer()
{
StartCoroutine(UnloadScenes());
}
public override void OnStopClient()
{
StartCoroutine(UnloadScenes());
}
IEnumerator UnloadScenes() IEnumerator UnloadScenes()
{ {
Debug.Log("Unloading Subscenes"); Debug.Log("Unloading Subscenes");

View File

@ -14,22 +14,20 @@ public class ZoneHandler : MonoBehaviour
[Tooltip("Assign the sub-scene to load for this zone")] [Tooltip("Assign the sub-scene to load for this zone")]
public string subScene; public string subScene;
[ServerCallback]
void OnTriggerEnter(Collider other) void OnTriggerEnter(Collider other)
{ {
if (!NetworkServer.active) return; // Debug.Log($"Loading {subScene}");
// Debug.LogFormat(LogType.Log, "Loading {0}", subScene);
NetworkIdentity networkIdentity = other.gameObject.GetComponent<NetworkIdentity>(); NetworkIdentity networkIdentity = other.gameObject.GetComponent<NetworkIdentity>();
SceneMessage message = new SceneMessage{ sceneName = subScene, sceneOperation = SceneOperation.LoadAdditive }; SceneMessage message = new SceneMessage{ sceneName = subScene, sceneOperation = SceneOperation.LoadAdditive };
networkIdentity.connectionToClient.Send(message); networkIdentity.connectionToClient.Send(message);
} }
[ServerCallback]
void OnTriggerExit(Collider other) void OnTriggerExit(Collider other)
{ {
if (!NetworkServer.active) return; // Debug.Log($"Unloading {subScene}");
// Debug.LogFormat(LogType.Log, "Unloading {0}", subScene);
NetworkIdentity networkIdentity = other.gameObject.GetComponent<NetworkIdentity>(); NetworkIdentity networkIdentity = other.gameObject.GetComponent<NetworkIdentity>();
SceneMessage message = new SceneMessage{ sceneName = subScene, sceneOperation = SceneOperation.UnloadAdditive }; SceneMessage message = new SceneMessage{ sceneName = subScene, sceneOperation = SceneOperation.UnloadAdditive };