private void networkSyncDroneSpawn(GameObject droneInstance) { if (GlobalSettings.SinglePlayer) { return; } if (Network.peerType != NetworkPeerType.Server) { throw new UnityException("Function may only be used by the server."); } //Debug.Log("Spawned and network sycned a drone:"); int id = this.guidGenerator.GenerateID(); ObjectSync objSync = droneInstance.GetComponent <ObjectSync>(); //Debug.Log(ownObjectSync.Owner == null); objSync.AssignID(ownObjectSync.Owner, id); objSync.Type = ObjectSyncType.Drone; this.objectTables.AddPlayerObject(objSync.Owner, id, droneInstance); ObjectRPC.CreateDrone(this.networkControl.ThisPlayer, id, droneInstance.transform.position, droneInstance.layer); }
public override void SyncNewPlayer(Player newPlayer) { base.SyncNewPlayer(newPlayer); // Sync the objects that are not associated with any player. ObjectTable serverTable = base.ObjectTables.GetPlayerTable(base.NetworkControl.ThisPlayer); ICollection <GameObject> serverObjects = serverTable.GetAllObjects(); Debug.Log("Number of server objects: " + serverObjects.Count); foreach (GameObject obj in serverObjects) { ObjectSync objSync = obj.GetComponent <ObjectSync>(); switch (objSync.Type) { case ObjectSyncType.Mothership: ObjectRPC.CreateMothership(newPlayer.NetworkPlayerInfo, objSync.Owner, objSync.GlobalID, obj.layer); // Temporary mothership positions. if (obj.layer == (int)Layers.Team1Mothership) { ObjectRPC.ObjectPosition(objSync.Owner, objSync.GlobalID, new Vector3(1000, 0, 0), Vector3.zero); } else { ObjectRPC.ObjectPosition(objSync.Owner, objSync.GlobalID, new Vector3(-1000, 0, 0), Vector3.zero); } break; case ObjectSyncType.Drone: ObjectRPC.CreateDrone(newPlayer.NetworkPlayerInfo, objSync.Owner, objSync.GlobalID, obj.transform.position, obj.layer); break; case ObjectSyncType.Asteroid: ObjectRPC.CreateAsteroid(newPlayer.NetworkPlayerInfo, objSync.Owner, objSync.GlobalID, obj.transform.position, obj.transform.localScale, obj.name); break; } } // Sync the objects that belong to other players. foreach (Player p in base.Players.Values) { // Skip all objects for the server player (already synced) and the new player (empty). if (!(p.ID == base.NetworkControl.LocalViewID || p.ID == newPlayer.ID)) { // Sync player ships and player spawnpoints PlayerObjects playerObjects = base.ObjectTables.PlayerObjects[p]; GameObject spawnPoint = base.GetObject(p, playerObjects.PlayerSpawnPointID); ObjectRPC.CreatePlayerSpawnpoint( newPlayer.NetworkPlayerInfo , p , playerObjects.PlayerSpawnPointID , spawnPoint.transform.position); GameObject playerShip = base.GetObject(p, playerObjects.PlayerShipID); PlayerShipRPC.CreatePlayerShip(newPlayer.NetworkPlayerInfo, p, playerObjects.PlayerShipID); //ObjectRPC.SetObjectLayer(newPlayer.NetworkPlayerInfo, p, playerObjects.PlayerShipID, (Layers)playerShip.layer); } } // Create the objects for the new player. int spawnPointID = base.GUIDGenerator.GenerateID(); int playerShipID = base.GUIDGenerator.GenerateID(); GameObject mothership = base.GetMothership(newPlayer.Team); Vector3 spawnPointPos = mothership.transform.position + new Vector3(0, 500, 0); // The order in which the following RPCs are sent is critical! ObjectRPC.CreatePlayerSpawnpoint(newPlayer, spawnPointID, spawnPointPos); PlayerShipRPC.CreatePlayerShip(newPlayer, playerShipID); PlayerShipRPC.SpawnPlayerShip(newPlayer, spawnPointID, playerShipID); }