public virtual void EnterParent(int index = 0) { if (enterableVehicles.Count > index) { parent = enterableVehicles[index]; parent.OnChildEntered(this); gameObject.SetActive(false); onEnteredParent.Invoke(); } }
protected virtual void Awake() { vehicle = GetComponent <Vehicle>(); if (vehicle == null) { Debug.LogError("Vehicle Enter Exit Manager component requires a reference to the vehicle, please set this in the inspector."); } child = startingChildVehicle; }
public virtual void RemoveEnterableVehicle(VehicleEnterExitManager enterableVehicle) { if (enterableVehicle == null) { return; } if (enterableVehicles.Contains(enterableVehicle)) { enterableVehicles.Remove(enterableVehicle); } }
/// <summary> /// Initialize the vehicle input component. /// </summary> /// <param name="vehicle">The vehicle to intialize for.</param> /// <returns>Whether initialization succeeded.</returns> protected override bool Initialize(Vehicle vehicle) { // Update the dependencies vehicleEnterExitManager = vehicle.GetComponent <VehicleEnterExitManager>(); if (vehicleEnterExitManager == null) { return(false); } hudController = vehicle.GetComponentInChildren <HUDVehicleEnterExit>(); return(true); }
/// <summary> /// Called when a collider exits a trigger collider. /// </summary> /// <param name="other">The collider that exited.</param> protected virtual void OnTriggerExit(Collider other) { if (other.attachedRigidbody == null) { return; } // Get other's enter exit manager VehicleEnterExitManager otherEnterExitManager = other.attachedRigidbody.GetComponent <VehicleEnterExitManager>(); // Unset enterable vehicle if (otherEnterExitManager != null) { otherEnterExitManager.RemoveEnterableVehicle(this); } }
public virtual void AddEnterableVehicle(VehicleEnterExitManager enterableVehicle) { if (enterableVehicle == null) { return; } if (enterableVehicles.Contains(enterableVehicle)) { return; } if (enterableVehicleClasses.Contains(enterableVehicle.Vehicle.VehicleClass)) { enterableVehicles.Add(enterableVehicle); } }
public virtual void OnChildEntered(VehicleEnterExitManager child) { this.child = child; onChildEntered.Invoke(); }
public virtual void SetChild(VehicleEnterExitManager child) { this.child = child; }
public virtual bool CanEnter(VehicleEnterExitManager vehicleEnterExitManager) { return(enterableVehicleClasses.Contains(vehicleEnterExitManager.Vehicle.VehicleClass)); }
/// <summary> /// Spawn the vehicle and enter it. /// </summary> public void Spawn() { // Create a reference to the vehicle Vehicle vehicle = null; // Create the vehicle switch (vehicleSpawnType) { case VehicleSpawnType.Loadout: int playerVehicleIndex = PlayerData.GetSelectedVehicleIndex(itemManager); if (playerVehicleIndex == -1) { if (itemManager != null && itemManager.vehicles.Count > 0) { playerVehicleIndex = 0; } } if (playerVehicleIndex != -1) { // Create the vehicle Transform vehicleTransform = ((GameObject)Instantiate(itemManager.vehicles[playerVehicleIndex].gameObject, vehicleSpawnPoint.position, vehicleSpawnPoint.rotation)).transform; vehicle = vehicleTransform.GetComponent <Vehicle>(); vehicle.name = vehicleName; // Get the vehicle loadout List <int> selectedModuleIndexesByMount = PlayerData.GetModuleLoadout(playerVehicleIndex, itemManager); bool hasLoadout = false; for (int i = 0; i < selectedModuleIndexesByMount.Count; ++i) { if (selectedModuleIndexesByMount[i] != -1) { hasLoadout = true; } } // Create the vehicle loadout if (hasLoadout) { for (int i = 0; i < selectedModuleIndexesByMount.Count; ++i) { if (selectedModuleIndexesByMount[i] == -1) { continue; } Module module = GameObject.Instantiate(itemManager.modulePrefabs[selectedModuleIndexesByMount[i]], null); vehicle.ModuleMounts[i].AddMountableModule(module, itemManager.modulePrefabs[selectedModuleIndexesByMount[i]], true); } } else { for (int i = 0; i < vehicle.ModuleMounts.Count; ++i) { vehicle.ModuleMounts[i].createDefaultModulesAtStart = true; } } } break; case VehicleSpawnType.Prefab: vehicle = Instantiate(vehiclePrefab, vehicleSpawnPoint.position, vehicleSpawnPoint.rotation); break; } if (vehicle != null) { // Set child vehicle that the game agent will exit to when exiting this vehicle. VehicleEnterExitManager enterExitManager = vehicle.GetComponent <VehicleEnterExitManager>(); if (startingChildVehicle != null) { if (enterExitManager != null) { if (startingChildVehicle.CanEnter(enterExitManager)) { enterExitManager.SetChild(startingChildVehicle); } } } // Make the starting occupant enter the vehicle if (startingOccupant != null) { GameAgent occupant; if (spawnOccupantFromPrefab) { occupant = Instantiate(startingOccupant, Vector3.zero, Quaternion.identity); } else { occupant = startingOccupant; } occupant.EnterVehicle(vehicle); } // Call the event onVehicleSpawned.Invoke(vehicle); } }