public override void Die() { if (dead) { return; } this.health = 0; if (Network.peerType != NetworkPeerType.Server) { GameObject explinst = Instantiate(ExplosionGraphic, gameObject.transform.position, Quaternion.identity) as GameObject; explinst.transform.localScale *= ExplosionScale; AudioSource.PlayClipAtPoint(ExplosionSound, gameObject.transform.position); } if (!GlobalSettings.SinglePlayer) { MatchControl matchControl = GameObject.Find(GlobalSettings.MatchControlName).GetComponent <MatchControl>(); matchControl.ObjectDestroyed(this.gameObject); } ObjectSync objSync = this.GetComponent <ObjectSync>(); if (objSync != null && !GlobalSettings.SinglePlayer) { objSync.Dispose(); } dead = true; base.IsDead = true; Destroy(gameObject, 5); }
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); }
protected void AddToObjectTables(GameObject obj, NetworkViewID playerID, int objectID) { ObjectSync objSync = obj.GetComponent <ObjectSync>(); Player player = this.NetworkControl.Players[playerID]; objSync.AssignID(player, objectID); this.ObjectTables.AddPlayerObject(player, objectID, obj); }
/// <summary> /// Initializes the server-side objects. /// </summary> private void createServerSideObjects() { Player server = new Player(base.NetworkControl.LocalViewID, Network.player); base.NetworkControl.Players.Add(server.ID, server); base.ObjectTables.AddPlayerTable(server); Debug.Log("Created server player: " + server.ID); Player serverPlayer = base.NetworkControl.ThisPlayer; // Initialize the starting positions of the motherships. Vector3 team1MothershipPos = new Vector3(2000, 0, 0); Vector3 team2MothershipPos = new Vector3(-2000, 0, 0); // Initialize te motherships. GameObject team1Mothership = (GameObject)GameObject.Instantiate( this.MothershipPrefab, team1MothershipPos, Quaternion.identity ); GameObject team2Mothership = (GameObject)GameObject.Instantiate( this.MothershipPrefab, team2MothershipPos, Quaternion.identity ); // Assign teams to the motherships. TeamHelper.PropagateLayer(team1Mothership, (int)Layers.Team1Mothership); TeamHelper.PropagateLayer(team2Mothership, (int)Layers.Team2Mothership); team1Mothership.name = "Team1Mothership"; team2Mothership.name = "Team2Mothership"; // Generate object IDs for the motherships. int team1MothershipID = base.GUIDGenerator.GenerateID(); int team2MothershipID = base.GUIDGenerator.GenerateID(); // Assign some values. ObjectSync team1MSObjSync = team1Mothership.GetComponent <ObjectSync>(); team1MSObjSync.Type = ObjectSyncType.Mothership; team1MSObjSync.AssignID(serverPlayer, team1MothershipID); HealthControl team1MSHealthControl = team1Mothership.GetComponent <HealthControl>(); team1MSHealthControl.DrawHealthInfo = false; ObjectSync team2MSObjSync = team2Mothership.GetComponent <ObjectSync>(); team2MSObjSync.Type = ObjectSyncType.Mothership; team2MSObjSync.AssignID(serverPlayer, team2MothershipID); HealthControl team2MSHealthControl = team2Mothership.GetComponent <HealthControl>(); team2MSHealthControl.DrawHealthInfo = false; base.ObjectTables.AddPlayerObject(serverPlayer, team1MothershipID, team1Mothership); base.ObjectTables.AddPlayerObject(serverPlayer, team2MothershipID, team2Mothership); }
public void ObjectDestroyed(GameObject obj) { ObjectSync objSync = obj.GetComponent <ObjectSync>(); if (objSync == null) { throw new UnityException("Given GameObject must contain an ObjectSync component"); } if (objSync.Type == ObjectSyncType.Mothership) { MatchResult result = TeamHelper.GetTeamNumber(obj.layer) == 1 ? MatchResult.Team2Win : MatchResult.Team1Win; this.EndMatch(result); } }
private void CreatePlayerShipRPC(NetworkViewID playerID, int objectID, NetworkMessageInfo info) { Debug.Log("Create player ship RPC received!"); Player owner = base.NetworkControl.Players[playerID]; // Create the player ship. GameObject playerShip = (GameObject)GameObject.Instantiate(this.PlayerPrefab); TeamHelper.PropagateLayer(playerShip, (int)owner.Team); if (base.NetworkControl.LocalViewID == playerID) { // Set variables for when this ship is controlled by the client receiving the RPC. base.ObjectTables.ThisPlayerObjects.PlayerShipID = objectID; playerShip.GetComponentInChildren <Camera>().enabled = true; } else { // Disable components that mostly has to do with interface and controls for when the // ship is controlled by another player. playerShip.GetComponentInChildren <Camera>().enabled = false; playerShip.GetComponentInChildren <AudioListener>().enabled = false; playerShip.GetComponent <ShipControl>().enabled = false; playerShip.GetComponent <SoftwareMouse>().enabled = false; playerShip.GetComponent <HUD>().enabled = false; playerShip.GetComponent <PlayerHealthControl>().DrawHealthInfo = false; playerShip.GetComponentInChildren <ThirdPersonCrosshair>().enabled = false; } // Set object type. ObjectSync objSync = playerShip.GetComponent <ObjectSync>(); objSync.Type = ObjectSyncType.PlayerShip; // Set spawn point reference. Player player = this.NetworkControl.Players[playerID]; int spawnPointID = this.ObjectTables.PlayerObjects[player].PlayerSpawnPointID; GameObject spawnPoint = this.ObjectTables.GetPlayerObject(player, spawnPointID); playerShip.GetComponent <PlayerHealthControl>().RespawnPoint = spawnPoint.GetComponent <PlayerRespawner>(); spawnPoint.GetComponent <PlayerRespawner>().AttachPlayer(playerShip); // Add to global object tables. base.ObjectTables.PlayerObjects[owner].PlayerShipID = objectID; base.AddToObjectTables(playerShip, playerID, objectID); }
void Update() { //If outside, count the time if (outside) { curOutsideTime += Time.deltaTime; //Check for death if (curOutsideTime > maxOutsideTime) { ObjectSync objSync = this.GetComponent <ObjectSync>(); ObjectRPC.KillObject(objSync.Owner, objSync.GlobalID); Debug.Log("Out of boundary call."); //healthControl.Die(); outside = false; } } }
private void CreatePlayerSpawnpointRPC(NetworkViewID owner, int objectID, Vector3 position, NetworkMessageInfo info) { Debug.Log("Create player spawn point RPC received."); Player player = base.NetworkControl.Players[owner]; GameObject spawnPoint = (GameObject)GameObject.Instantiate(this.PlayerSpawnPointPrefab, position, Quaternion.identity); ObjectSync spawnPointSync = spawnPoint.GetComponent <ObjectSync>(); spawnPointSync.Type = ObjectSyncType.PlayerSpawnPoint; spawnPoint.layer = (int)player.Team; GameObject mothership = base.GetMothership(player.Team); spawnPoint.transform.parent = mothership.transform; base.ObjectTables.PlayerObjects[base.Players[owner]].PlayerSpawnPointID = objectID; base.AddToObjectTables(spawnPoint, owner, objectID); }
public virtual void Die() { if (this.IsDead) { return; } this.health = 0; this.shieldStrength = 0; ObjectSync objSync = this.GetComponent <ObjectSync>(); if (objSync != null && !GlobalSettings.SinglePlayer) { objSync.Dispose(); } this.IsDead = true; Destroy(gameObject); }
public void Setup(SyncObject syncObject) { audioSource = gameObject.AddComponent <AudioSource>(); obj = syncObject; objectSync = GetComponent <ObjectSync>(); // Ensure Unity's output sampling rate is same as Mondeto's internal sampling rate (48kHz) if (AudioSettings.outputSampleRate != SyncObject.AudioSamplingRate) { Logger.Error("AudioSourceTag", $"Output sample rate is not {SyncObject.AudioSamplingRate} Hz (actual value = {AudioSettings.outputSampleRate} Hz)"); return; } audioSource.spatialize = true; audioSource.spatialBlend = 1.0f; audioSource.clip = AudioClip.Create("", SyncObject.AudioSamplingRate, 1, SyncObject.AudioSamplingRate, false); audioSource.loop = true; obj.AudioReceived += OnAudioReceived; audioSource.Play(); }
public void CreateAsteroid(Vector3 position, Vector3 localScale, string name, Player owner, int id) { GameObject asteroid = (GameObject)GameObject.Instantiate(templateAsteroid, position, Random.rotation); asteroid.SetActive(true); asteroid.transform.localScale = localScale; asteroid.transform.name = name; asteroid.transform.parent = this.transform; if (!GlobalSettings.SinglePlayer) { if (Network.peerType == NetworkPeerType.Server) { ObjectSync objSync = asteroid.GetComponent <ObjectSync>(); objSync.Type = ObjectSyncType.Asteroid; objSync.AssignID(owner, id); } base.ObjectTables.AddPlayerObject(owner, id, asteroid); } asteroidCount++; }
// This is also used for grabbing void StartClicking(SyncObject thisObj, ObjectSync clickedObj, string eventName, List <ObjectSync> objectList) { objectList.Add(clickedObj); clickedObj.SyncObject.SendEvent(eventName, thisObj.Id, new IValue[0]); }
// Use this for initialization void Start() { // The total of drones should be divisible by the number of spawn locations; if (drone_number % spawn_locations.Length == 0) { drones_per_location = drone_number / spawn_locations.Length; } else { Debug.LogError("Number of Drones is not devisable by amount of spawn locations"); } destination = new Transform[spawn_locations.Length]; //Find the corresponding destination locations // In case we have a checkpoint, the destination becomes that checkpoint, // Else we will just use end position if (checkpoint == null) { GameObject[] candidates = GameObject.FindGameObjectsWithTag("Mothership"); if (candidates.Length > 1) { DroneSpawn s; // Check for both objects if it is the mothership we want if (candidates[0].transform == this.transform) { s = candidates[1].GetComponent<DroneSpawn>(); } else { s = candidates[0].GetComponent<DroneSpawn>(); } Transform[] temp_spawn = s.spawn_locations; // Copy the spawn locations on the opposing mothership // as the destination of our mothership for (int i = 0; i < temp_spawn.Length; i++) { destination[temp_spawn.Length - 1 - i] = temp_spawn[i]; } } else { Debug.LogError("No Destination Mothership in scene"); } } else { for (int i = 0; i < destination.Length; i++) { destination[i] = checkpoint.transform; } } // Start the spawn calls in startTime seconds InvokeRepeating("SpawnDrones", startTime, repeatTime); /// /// Network Code Below /// if (!GlobalSettings.SinglePlayer) { this.networkControl = GameObject.Find("NetworkControl").GetComponent<NetworkControl>(); this.guidGenerator = this.networkControl.GetComponent<GUIDGenerator>(); this.ownObjectSync = this.GetComponent<ObjectSync>(); this.objectTables = GameObject.Find("PlayerObjectTable").GetComponent<PlayerObjectTable>(); } /// /// End Network Code /// }
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); }
void Awake() { _rigid = GetComponent <Rigidbody>(); _objectSync = GetComponent <ObjectSync>(); }
private void Awake() { this.objSync = this.GetComponent <ObjectSync>(); }
private void Awake() { this.objSync = this.GetComponent<ObjectSync>(); }
void StartClicking(SyncObject thisObj, ObjectSync clickedObj) => StartClicking(thisObj, clickedObj, "clickStart", clickedObjects);
void Start() { // Radius in which drone follows the player for attacking desiredDistance = 100; currentState = Behaviours.GoTo; // initialize gunScripts array gunScripts = new Shooter[gun.Length]; first = true; // Add the prevent collision code pc = this.gameObject.AddComponent<PreventCollision>(); pc.setActor(this.transform); // Spawn positon is transform at creation spawnPosition = this.transform; /// /// Network Code /// this.objectSync = this.GetComponent<ObjectSync>(); /// /// End Network Code /// }