diff --git a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scenes/Game.unity b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scenes/Game.unity index 585ca607b..bf1570ec7 100644 --- a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scenes/Game.unity +++ b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scenes/Game.unity @@ -122,86 +122,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &29930032 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 29930035} - - component: {fileID: 29930034} - - component: {fileID: 29930033} - - component: {fileID: 29930036} - m_Layer: 0 - m_Name: Spawner - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &29930033 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 29930032} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9b91ecbcc199f4492b9a91e820070131, type: 3} - m_Name: - m_EditorClassIdentifier: - sceneId: 6047645 - serverOnly: 1 - m_AssetId: - hasSpawned: 0 ---- !u!114 &29930034 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 29930032} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f522bf510b49da44caa9f3ca0ac17f3b, type: 3} - m_Name: - m_EditorClassIdentifier: - syncMode: 0 - syncInterval: 0.1 - prizePrefab: {fileID: 114251241889735402, guid: 8cec47ed46e0eff45966a5173d3aa0d3, - type: 3} ---- !u!4 &29930035 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 29930032} - 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_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &29930036 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 29930032} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b7fdb599e1359924bad6255660370252, type: 3} - m_Name: - m_EditorClassIdentifier: - syncMode: 0 - syncInterval: 0.1 - forceHidden: 0 --- !u!1 &473309615 GameObject: m_ObjectHideFlags: 0 @@ -234,7 +154,7 @@ Transform: - {fileID: 2061474489} - {fileID: 1072549450} m_Father: {fileID: 0} - m_RootOrder: 3 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &535961555 PrefabInstance: @@ -667,7 +587,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &2061474488 PrefabInstance: diff --git a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scenes/Main.unity b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scenes/Main.unity index 05cb8aa2a..00c99c2c2 100644 --- a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scenes/Main.unity +++ b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scenes/Main.unity @@ -312,6 +312,8 @@ MonoBehaviour: playerSpawnMethod: 1 spawnPrefabs: - {fileID: 1139254171913846, guid: 8cec47ed46e0eff45966a5173d3aa0d3, type: 3} + rewardPrefab: {fileID: 1139254171913846, guid: 8cec47ed46e0eff45966a5173d3aa0d3, + type: 3} instances: 2 gameScene: Assets/Mirror/Examples/MultipleAdditiveScenes/Scenes/Game.unity --- !u!4 &69965670 diff --git a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/MultiSceneNetManager.cs b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/MultiSceneNetManager.cs index 6b1f67c53..f94699336 100644 --- a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/MultiSceneNetManager.cs +++ b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/MultiSceneNetManager.cs @@ -8,6 +8,10 @@ namespace Mirror.Examples.MultipleAdditiveScenes [AddComponentMenu("")] public class MultiSceneNetManager : NetworkManager { + [Header("Spawner Setup")] + [Tooltip("Reward Prefab for the Spawner")] + public GameObject rewardPrefab; + [Header("MultiScene Setup")] public int instances = 3; @@ -66,6 +70,7 @@ IEnumerator OnServerAddPlayerDelayed(NetworkConnection conn) /// public override void OnStartServer() { + Spawner.rewardPrefab = rewardPrefab; StartCoroutine(ServerLoadSubScenes()); } @@ -77,7 +82,10 @@ IEnumerator ServerLoadSubScenes() for (int index = 1; index <= instances; index++) { yield return SceneManager.LoadSceneAsync(gameScene, new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive, localPhysicsMode = LocalPhysicsMode.Physics3D }); - subScenes.Add(SceneManager.GetSceneAt(index)); + + Scene newScene = SceneManager.GetSceneAt(index); + subScenes.Add(newScene); + Spawner.InitialSpawn(newScene); } subscenesLoaded = true; diff --git a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Reward.cs b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Reward.cs index d81a6ee13..00675323e 100644 --- a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Reward.cs +++ b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Reward.cs @@ -8,7 +8,6 @@ public class Reward : NetworkBehaviour static readonly ILogger logger = LogFactory.GetLogger(typeof(Reward)); public bool available = true; - public Spawner spawner; public RandomColor randomColor; void OnValidate() @@ -34,18 +33,18 @@ public void ClaimPrize(GameObject player) // First hit turns it off, pending the object being destroyed a few frames later. available = false; - Color prizeColor = randomColor.color; + Color32 color = randomColor.color; // calculate the points from the color ... lighter scores higher as the average approaches 255 // UnityEngine.Color RGB values are float fractions of 255 - uint points = (uint)(((prizeColor.r * 255) + (prizeColor.g * 255) + (prizeColor.b * 255)) / 3); - if (logger.LogEnabled()) logger.LogFormat(LogType.Log, "Scored {0} points R:{1} G:{2} B:{3}", points, prizeColor.r, prizeColor.g, prizeColor.b); + uint points = (uint)(((color.r) + (color.g) + (color.b)) / 3); + if (logger.LogEnabled()) logger.LogFormat(LogType.Log, "Scored {0} points R:{1} G:{2} B:{3}", points, color.r, color.g, color.b); // award the points via SyncVar on the PlayerController player.GetComponent().score += points; // spawn a replacement - spawner.SpawnPrize(); + Spawner.SpawnReward(gameObject.scene); // destroy this one NetworkServer.Destroy(gameObject); diff --git a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Spawner.cs b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Spawner.cs index 79d634532..41f05c69c 100644 --- a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Spawner.cs +++ b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Spawner.cs @@ -1,27 +1,30 @@ using UnityEngine; +using UnityEngine.SceneManagement; +using UnityEngine.Serialization; namespace Mirror.Examples.MultipleAdditiveScenes { - public class Spawner : NetworkBehaviour + internal class Spawner : MonoBehaviour { - public NetworkIdentity prizePrefab; + [FormerlySerializedAs("prizePrefab")] + internal static GameObject rewardPrefab; - public override void OnStartServer() + internal static void InitialSpawn(Scene scene) { + if (!NetworkServer.active) return; + for (int i = 0; i < 10; i++) - SpawnPrize(); + SpawnReward(scene); } - public void SpawnPrize() + internal static void SpawnReward(Scene scene) { + if (!NetworkServer.active) return; + Vector3 spawnPosition = new Vector3(Random.Range(-19, 20), 1, Random.Range(-19, 20)); - - // spawn as child of the spawner that's already in the additive scene at 0,0,0 so we don't have to move it - GameObject newPrize = Instantiate(prizePrefab.gameObject, spawnPosition, Quaternion.identity, transform); - Reward reward = newPrize.gameObject.GetComponent(); - reward.spawner = this; - - NetworkServer.Spawn(newPrize); + GameObject reward = Instantiate(rewardPrefab, spawnPosition, Quaternion.identity); + SceneManager.MoveGameObjectToScene(reward, scene); + NetworkServer.Spawn(reward); } } } diff --git a/Assets/Mirror/Examples/Room/Scripts/Reward.cs b/Assets/Mirror/Examples/Room/Scripts/Reward.cs index c1a0cf18b..fb0ae1a58 100644 --- a/Assets/Mirror/Examples/Room/Scripts/Reward.cs +++ b/Assets/Mirror/Examples/Room/Scripts/Reward.cs @@ -8,8 +8,6 @@ public class Reward : NetworkBehaviour static readonly ILogger logger = LogFactory.GetLogger(typeof(Reward)); public bool available = true; - uint points; - public RandomColor randomColor; void OnValidate() @@ -41,7 +39,7 @@ public void ClaimPrize(GameObject player) // calculate the points from the color ... lighter scores higher as the average approaches 255 // UnityEngine.Color RGB values are float fractions of 255 - points = (uint)(((color.r) + (color.g) + (color.b)) / 3); + uint points = (uint)(((color.r) + (color.g) + (color.b)) / 3); if (logger.LogEnabled()) logger.LogFormat(LogType.Log, "Scored {0} points R:{1} G:{2} B:{3}", points, color.r, color.g, color.b); // award the points via SyncVar on the PlayerController