Moved prefabs to NetworkConfig
This commit is contained in:
parent
b1c4cae028
commit
b66a351859
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using MLAPI.MonoBehaviours.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -42,6 +43,14 @@ namespace MLAPI.Data
|
||||
/// </summary>
|
||||
public List<string> RegisteredScenes = new List<string>();
|
||||
/// <summary>
|
||||
/// A list of spawnable prefabs
|
||||
/// </summary>
|
||||
public List<GameObject> SpawnablePrefabs = new List<GameObject>();
|
||||
/// <summary>
|
||||
/// The default player prefab
|
||||
/// </summary>
|
||||
public GameObject PlayerPrefab;
|
||||
/// <summary>
|
||||
/// The size of the receive message buffer. This is the max message size.
|
||||
/// </summary>
|
||||
public int MessageBufferSize = 65535;
|
||||
@ -166,6 +175,10 @@ namespace MLAPI.Data
|
||||
writer.Write(EncryptedChannels[i]);
|
||||
}
|
||||
}
|
||||
if(HandleObjectSpawning)
|
||||
{
|
||||
writer.Write(SpawnablePrefabs.Count);
|
||||
}
|
||||
writer.Write(HandleObjectSpawning);
|
||||
writer.Write(EnableEncryption);
|
||||
writer.Write(AllowPassthroughMessages);
|
||||
|
@ -14,7 +14,7 @@ namespace MLAPI.Data
|
||||
poolId = poolIndex;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
GameObject go = Object.Instantiate(NetworkingManager.singleton.SpawnablePrefabs[prefabIndex], Vector3.zero, Quaternion.identity);
|
||||
GameObject go = Object.Instantiate(NetworkingManager.singleton.NetworkConfig.SpawnablePrefabs[prefabIndex], Vector3.zero, Quaternion.identity);
|
||||
go.GetComponent<NetworkedObject>()._isPooledObject = true;
|
||||
go.GetComponent<NetworkedObject>().poolId = poolId;
|
||||
go.GetComponent<NetworkedObject>().Spawn();
|
||||
|
@ -38,14 +38,6 @@ namespace MLAPI.MonoBehaviours.Core
|
||||
/// </summary>
|
||||
public bool RunInBackground = true;
|
||||
/// <summary>
|
||||
/// A list of spawnable prefabs
|
||||
/// </summary>
|
||||
public List<GameObject> SpawnablePrefabs;
|
||||
/// <summary>
|
||||
/// The default prefab to give to players
|
||||
/// </summary>
|
||||
public GameObject DefaultPlayerPrefab;
|
||||
/// <summary>
|
||||
/// The singleton instance of the NetworkingManager
|
||||
/// </summary>
|
||||
public static NetworkingManager singleton
|
||||
@ -158,24 +150,24 @@ namespace MLAPI.MonoBehaviours.Core
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if (SpawnablePrefabs != null)
|
||||
if (NetworkConfig.SpawnablePrefabs != null)
|
||||
{
|
||||
for (int i = 0; i < SpawnablePrefabs.Count; i++)
|
||||
for (int i = 0; i < NetworkConfig.SpawnablePrefabs.Count; i++)
|
||||
{
|
||||
if (SpawnablePrefabs[i] == null)
|
||||
if (NetworkConfig.SpawnablePrefabs[i] == null)
|
||||
continue;
|
||||
NetworkedObject netObject = SpawnablePrefabs[i].GetComponentInChildren<NetworkedObject>();
|
||||
NetworkedObject netObject = NetworkConfig.SpawnablePrefabs[i].GetComponentInChildren<NetworkedObject>();
|
||||
if (netObject == null)
|
||||
{
|
||||
Debug.LogWarning("MLAPI: All SpawnablePrefabs need a NetworkedObject component. Please add one to the prefab " + SpawnablePrefabs[i].gameObject.name);
|
||||
Debug.LogWarning("MLAPI: All SpawnablePrefabs need a NetworkedObject component. Please add one to the prefab " + NetworkConfig.SpawnablePrefabs[i].gameObject.name);
|
||||
continue;
|
||||
}
|
||||
netObject.spawnablePrefabIndex = i;
|
||||
}
|
||||
}
|
||||
if (DefaultPlayerPrefab != null)
|
||||
if (NetworkConfig.PlayerPrefab != null)
|
||||
{
|
||||
NetworkedObject netObject = DefaultPlayerPrefab.GetComponentInChildren<NetworkedObject>();
|
||||
NetworkedObject netObject = NetworkConfig.PlayerPrefab.GetComponentInChildren<NetworkedObject>();
|
||||
if (netObject == null)
|
||||
{
|
||||
Debug.LogWarning("MLAPI: The player object needs a NetworkedObject component.");
|
||||
|
@ -89,7 +89,9 @@ namespace MLAPI.NetworkingManagerComponents.Core
|
||||
|
||||
internal static GameObject SpawnObject(int spawnablePrefabIndex, uint networkId, int ownerId, Vector3 position, Quaternion rotation)
|
||||
{
|
||||
GameObject go = MonoBehaviour.Instantiate(netManager.SpawnablePrefabs[spawnablePrefabIndex]);
|
||||
if (spawnablePrefabIndex >= netManager.NetworkConfig.SpawnablePrefabs.Count)
|
||||
return null;
|
||||
GameObject go = MonoBehaviour.Instantiate(netManager.NetworkConfig.SpawnablePrefabs[spawnablePrefabIndex]);
|
||||
NetworkedObject netObject = go.GetComponent<NetworkedObject>();
|
||||
if (netObject == null)
|
||||
{
|
||||
@ -117,7 +119,9 @@ namespace MLAPI.NetworkingManagerComponents.Core
|
||||
|
||||
internal static GameObject SpawnPlayerObject(int clientId, uint networkId)
|
||||
{
|
||||
GameObject go = MonoBehaviour.Instantiate(netManager.DefaultPlayerPrefab);
|
||||
if (netManager.NetworkConfig.PlayerPrefab == null)
|
||||
return null;
|
||||
GameObject go = MonoBehaviour.Instantiate(netManager.NetworkConfig.PlayerPrefab);
|
||||
NetworkedObject netObject = go.GetComponent<NetworkedObject>();
|
||||
if (netObject == null)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user