//This simply instantiates a network prefab. //The objct should already exist on the database. public GameObject SpawnObject(ushort objectID) { if (meshnet == null) { Debug.LogError("Trying to spawn object when underlying mesh network not intialized."); return(null); } if (meshnet.database.LookupObject(objectID) == null) { Debug.LogError("Trying to spawn network object without presence on the database"); return(null); } MeshNetworkIdentity localIdentity = meshnet.database.LookupObject(objectID); localIdentity.SetMeshnetReference(meshnet); //set a reference to the mesh network if (networkPrefabs.ContainsKey(localIdentity.GetPrefabID()) == false) { Debug.LogError("NetworkPrefab registry error: Requested prefab ID does not exist."); return(null); } GameObject g = Instantiate(networkPrefabs[localIdentity.GetPrefabID()]); IdentityContainer c = g.GetComponent <IdentityContainer>(); if (c == null) { Debug.LogError("NetworkPrefab error: spawned prefab does not contain IdentityContainer"); return(null); } c.SetIdentity(localIdentity); activeObjects.Add(objectID, g); return(g); }
public GameObject SpawnDatabase(MeshNetworkIdentity i) { if (meshnet == null) { Debug.LogError("Trying to spawn object when underlying mesh network not intialized."); return(null); } if (i.GetObjectID() != (ushort)ReservedObjectIDs.DatabaseObject) { Debug.LogError("Trying to use database spawning method for non-database object"); return(null); } i.SetMeshnetReference(meshnet); //set a reference to the mesh network if (networkPrefabs.ContainsKey(i.GetPrefabID()) == false) { Debug.LogError("NetworkPrefab registry error: Requested prefab ID does not exist."); return(null); } GameObject g = Instantiate(networkPrefabs[i.GetPrefabID()]); IdentityContainer c = g.GetComponent <IdentityContainer>(); if (c == null) { Debug.LogError("NetworkPrefab error: spawned prefab does not contain IdentityContainer"); return(null); } c.SetIdentity(i); activeObjects.Add(i.GetObjectID(), g); return(g); }