/// <summary> /// Called when a game agent enters the vehicle. /// </summary> /// <param name="newOccupant">The game agent that entered the vehicle.</param> public virtual void OnEntered(GameAgent newOccupant) { // Check if the game agent is already in the vehicle for (int i = 0; i < occupants.Count; ++i) { if (occupants[i] == newOccupant) { return; } } // Add the new occupant occupants.Add(newOccupant); if (occupants.Count != 0) { for (int i = 0; i < moduleManagers.Count; ++i) { moduleManagers[i].ActivateModuleManager(); } } // Call the event onEntered.Invoke(newOccupant); }
/// <summary> /// Called when a game agent exits a vehicle. /// </summary> /// <param name="exitingOccupant">The game agent exiting.</param> public virtual void OnExited(GameAgent exitingOccupant) { // Find the occupant in the list and remove for (int i = 0; i < occupants.Count; ++i) { if (occupants[i] == exitingOccupant) { // Remove the occupant occupants.RemoveAt(i); // Call the event onExited.Invoke(exitingOccupant); break; } } if (occupants.Count == 0) { for (int i = 0; i < moduleManagers.Count; ++i) { moduleManagers[i].DeactivateModuleManager(); } } }
/// <summary> /// Spawn the object. /// </summary> public override void Spawn() { base.Spawn(); Vector3 spawnPos = transform.position; if (warpIn) { spawnPos = transform.position - transform.forward * warpDistance; } if (usePoolManager) { pilot = PoolManager.Instance.Get(pilotPrefabs[Random.Range(0, pilotPrefabs.Count)].gameObject, spawnPos, transform.rotation).GetComponent <GameAgent>(); vehicle = PoolManager.Instance.Get(vehiclePrefabs[Random.Range(0, vehiclePrefabs.Count)].gameObject, spawnPos, transform.rotation).GetComponent <Vehicle>(); } else { pilot = Instantiate(pilotPrefabs[Random.Range(0, pilotPrefabs.Count)], spawnPos, transform.rotation); vehicle = Instantiate(vehiclePrefabs[Random.Range(0, vehiclePrefabs.Count)], spawnPos, transform.rotation); } pilot.Revive(); vehicle.Restore(); if (warpIn) { StartAnimation(); } pilot.EnterVehicle(vehicle); }
/// <summary> /// Register a new game agent in the scene. /// </summary> /// <param name="newAgent"> New game agent. </param> /// <param name="focusThisAgent"> Whether to focus the scene on this game agent or not. </param> public virtual void Register(GameAgent newAgent, bool focusThisAgent = false) { gameAgents.Add(newAgent); if (focusThisAgent) { SetFocusedGameAgent(newAgent); } }
protected virtual void UpdateTargetSelectors(GameAgent gameAgent) { // Update the vehicle's team Team team = gameAgent == null ? originalTeam : gameAgent.Team; if (team != null) { for (int i = 0; i < targetSelectors.Length; ++i) { targetSelectors[i].SelectableTeams = team.HostileTeams; } } }
/// <summary> /// Deregister a game agent from the scene. /// </summary> /// <param name="gameAgent"> Game agent to be deregistered from the scene. </param> public virtual void Unregister(GameAgent gameAgent) { // Update the focused game agent if (gameAgent == focusedGameAgent) { SetFocusedGameAgent(null); } // Remove this agent from the list int index = gameAgents.IndexOf(gameAgent); if (index != -1) { gameAgents.RemoveAt(index); } }
/// <summary> /// Focus the scene on a different game agent. /// </summary> /// <param name="newFocusedGameAgent"> Game agent to be focused on. </param> public virtual void SetFocusedGameAgent(GameAgent newFocusedGameAgent) { if (this.focusedGameAgent != null) { this.focusedGameAgent.onEnteredVehicle.RemoveListener(OnFocusedVehicleChanged); this.focusedGameAgent.onDied.RemoveListener(OnFocusedGameAgentDied); } // Update the focused game agent this.focusedGameAgent = newFocusedGameAgent; focusedGameAgent.onEnteredVehicle.AddListener(OnFocusedVehicleChanged); focusedGameAgent.onDied.AddListener(OnFocusedGameAgentDied); // Call the event onFocusedGameAgentChanged.Invoke(focusedGameAgent); }
/// <summary> /// Called when a game agent exits a vehicle. /// </summary> /// <param name="exitingOccupant">The game agent exiting.</param> public virtual void OnExited(GameAgent exitingOccupant) { // Find the occupant in the list and remove for (int i = 0; i < occupants.Count; ++i) { if (occupants[i] == exitingOccupant) { // Remove the occupant occupants.RemoveAt(i); // Call the event onExited.Invoke(exitingOccupant); break; } } }
protected virtual void OnVehicleEntered(GameAgent gameAgent) { UpdateTrackables(gameAgent); UpdateTargetSelectors(gameAgent); // Call the event if (gameAgent != null) { if (gameAgent.IsPlayer) { onPlayerEnteredVehicle.Invoke(gameAgent); } else { onAIEnteredVehicle.Invoke(gameAgent); } } }
protected virtual void UpdateTrackables(GameAgent gameAgent) { // Update the vehicle's team Team team = gameAgent == null ? originalTeam : gameAgent.Team; // Update the Team for all the trackables on this vehicle for (int i = 0; i < trackables.Length; ++i) { trackables[i].Team = team; } // Update the label on the root trackable if (overrideRootTrackableLabel && rootTrackable != null) { if (rootTrackable.variablesDictionary.ContainsKey(labelKey)) { LinkableVariable labelVariable = rootTrackable.variablesDictionary[labelKey]; if (labelVariable != null) { labelVariable.StringValue = gameAgent.Label; } } } }
protected virtual void OnVehicleExited(GameAgent gameAgent) { onVehicleExited.Invoke(); }