protected override bool Initialize(Vehicle vehicle) { if (!base.Initialize(vehicle)) { return(false); } weapons = vehicle.GetComponent <Weapons>(); if (weapons == null) { return(false); } triggerablesManager = vehicle.GetComponent <TriggerablesManager>(); if (triggerablesManager == null) { return(false); } engines = vehicle.GetComponent <VehicleEngines3D>(); if (engines == null) { return(false); } rBody = vehicle.GetComponent <Rigidbody>(); if (rBody == null) { return(false); } return(engines != null); }
/// <summary> /// Called when a new vehicle is selected in the loadout menu, to update the vehicle stats UI. /// </summary> void UpdateVehicleInfo() { VehicleEngines3D engines = displayVehicles[selectedVehicleIndex].GetComponentInChildren <VehicleEngines3D>(); if (engines == null) { Debug.LogError("Attempting to calculate ship performance metrics for a vehicle which does not contain" + " a SpaceVehicleEngines component."); } shipSpeedBar.SetValue(engines.GetDefaultMaxSpeedByAxis(false).z / maxVehicleSpeed); float averageAxisTorque = (engines.MaxRotationForces.x + engines.MaxRotationForces.y + engines.MaxRotationForces.z) / 3f; shipAgilityBar.SetValue(averageAxisTorque / maxVehicleAgility); Health health = displayVehicles[selectedVehicleIndex].GetComponent <Health>(); if (health != null) { shipShieldsBar.SetValue(health.GetMaxHealthByType(HealthType.Shield) / maxVehicleShields); shipArmorBar.SetValue(health.GetMaxHealthByType(HealthType.Armor) / maxVehicleArmor); } }
/// <summary> /// Get the maximum values for all of the vehicle metrics so that vehicle performance can be displayed /// as a relative value in a bar. /// </summary> /// <param name="vehicles">A list of all the vehicles available in the loadout menu.</param> /// <param name="maxShipThrust">Return the maximum thrust found for any of the vehicles.</param> /// <param name="maxShipAgility">Return the maximum agility found for any of the vehicles.</param> /// <param name="maxShipArmor">Return the maximum armor health value for any of the vehicles.</param> /// <param name="maxShipShields">Return the maximum shield health value for any of the vehicles.</param> public static void GetShipMetricsReferenceValues(List <Vehicle> vehicles, out float maxShipSpeed, out float maxShipAgility, out float maxShipArmor, out float maxShipShields) { maxShipSpeed = 0; maxShipAgility = 0; maxShipArmor = 0; maxShipShields = 0; for (int i = 0; i < vehicles.Count; ++i) { VehicleEngines3D vehicleEngines = vehicles[i].GetComponentInChildren <VehicleEngines3D>(); if (vehicleEngines == null) { Debug.LogError("Attempting to calculate ship performance metrics for a vehicle which does not contain" + " a SpaceVehicleEngines component."); } maxShipSpeed = Mathf.Max(vehicleEngines.GetDefaultMaxSpeedByAxis(false).z, maxShipSpeed); float averageAxisTorque = (vehicleEngines.MaxRotationForces.x + vehicleEngines.MaxRotationForces.y + vehicleEngines.MaxRotationForces.z) / 3f; maxShipAgility = averageAxisTorque > maxShipAgility ? averageAxisTorque : maxShipAgility; Health health = vehicles[i].GetComponent <Health>(); if (health != null) { maxShipArmor = Mathf.Max(health.GetMaxHealthByType(HealthType.Armor), maxShipArmor); maxShipShields = Mathf.Max(health.GetMaxHealthByType(HealthType.Shield), maxShipShields); } } }
protected override bool Initialize(Vehicle vehicle) { if (!base.Initialize(vehicle)) { return(false); } engines = vehicle.GetComponent <VehicleEngines3D>(); return(engines != null); }
protected override bool Initialize(Vehicle vehicle) { VehicleEngines3D engines = vehicle.GetComponent <VehicleEngines3D>(); if (engines == null) { return(false); } // Success for (int i = 0; i < behaviours.Count; ++i) { behaviours[i].SetVehicle(vehicle); } return(true); }
// Set a new engines reference protected void SetEngines(VehicleEngines3D newEngines) { if (newEngines == null) { vehicleEngines = null; vehicleEnginesSerializedObject = null; } else { vehicleEngines = newEngines; vehicleEnginesInstanceID = vehicleEngines.GetInstanceID(); vehicleEnginesSerializedObject = new SerializedObject(vehicleEngines); defaultMovementForcesProperty = vehicleEnginesSerializedObject.FindProperty("defaultMovementForces"); defaultBoostForcesProperty = vehicleEnginesSerializedObject.FindProperty("defaultBoostForces"); maxMovementForcesProperty = vehicleEnginesSerializedObject.FindProperty("maxMovementForces"); vehicleRigidbody = vehicleEngines.GetComponent <Rigidbody>(); } }
/// <summary> /// Initialize this input script with a vehicle. /// </summary> /// <param name="vehicle">The new vehicle.</param> /// <returns>Whether the input script succeeded in initializing.</returns> protected override bool Initialize(Vehicle vehicle) { if (!base.Initialize(vehicle)) { return(false); } // Clear dependencies spaceVehicleEngines = null; // Make sure the vehicle has a space vehicle engines component spaceVehicleEngines = vehicle.GetComponent <VehicleEngines3D>(); if (spaceVehicleEngines == null) { return(false); } return(true); }
protected override bool Initialize(Vehicle vehicle) { if (!base.Initialize(vehicle)) { return(false); } weapons = vehicle.GetComponent <Weapons>(); if (weapons == null) { return(false); } engines = vehicle.GetComponent <VehicleEngines3D>(); if (engines == null) { return(false); } return(true); }
protected override bool Initialize(Vehicle vehicle) { if (!base.Initialize(vehicle)) { return(false); } rBody = vehicle.GetComponent <Rigidbody>(); if (rBody == null) { return(false); } engines = vehicle.GetComponent <VehicleEngines3D>(); if (engines == null) { return(false); } return(true); }
protected void UpdateShipStats(List <Vehicle> vehicles) { // Reset ship max stats maxShipSpeed = 0; maxShipAgility = 0; for (int i = 0; i < maxShipHealthByHealthType.Length; ++i) { maxShipHealthByHealthType[i] = 0; } // Update ship max stats for (int i = 0; i < vehicles.Count; ++i) { // Get the engines component VehicleEngines3D engines = vehicles[i].GetComponentInChildren <VehicleEngines3D>(); if (engines == null) { Debug.LogError("Attempting to calculate ship performance metrics for a vehicle which does not contain a VehicleEngines3D component"); } // Update max ship speed maxShipSpeed = Mathf.Max(maxShipSpeed, GetSpeed(engines)); // Update max ship agility maxShipAgility = Mathf.Max(maxShipAgility, GetAgility(engines)); // Get the ships's health component Health health = vehicles[i].GetComponent <Health>(); if (health != null) { // Update max ship health for each health type for (int j = 0; j < shipHealthStatsBars.Count; ++j) { maxShipHealthByHealthType[j] = Mathf.Max(maxShipHealthByHealthType[j], health.GetMaxHealthByType(shipHealthStatsBars[j].HealthType)); } } } }
protected void OnGUI() { GUILayout.Label("Settings", EditorStyles.boldLabel); // Show engines reference in inspector EditorGUI.BeginChangeCheck(); vehicleEngines = EditorGUILayout.ObjectField("Engines", vehicleEngines, typeof(VehicleEngines3D), true) as VehicleEngines3D; // If engines reference changed, update other references if (EditorGUI.EndChangeCheck()) { if (vehicleEngines != null) { SetEngines(vehicleEngines); } else { vehicleEnginesSerializedObject = null; } } // If a vehicle engines serialized object is referenced, update its properties if (vehicleEnginesSerializedObject != null) { vehicleEnginesSerializedObject.Update(); defaultMovementSpeed = EditorGUILayout.Vector3Field("Default Movement Speed", defaultMovementSpeed); defaultBoostSpeed = EditorGUILayout.Vector3Field("Default Boost Speed", defaultBoostSpeed); maxMovementSpeed = EditorGUILayout.Vector3Field("Max Movement Speed", maxMovementSpeed); defaultMovementForcesProperty.vector3Value = ConvertSpeedToForce(defaultMovementSpeed); defaultBoostForcesProperty.vector3Value = ConvertSpeedToForce(defaultBoostSpeed); maxMovementForcesProperty.vector3Value = ConvertSpeedToForce(maxMovementSpeed); vehicleEnginesSerializedObject.ApplyModifiedProperties(); } }
public void ShowStats(Vehicle vehicle) { // Show engine stats VehicleEngines3D engines = vehicle.GetComponentInChildren <VehicleEngines3D>(); if (engines == null) { shipSpeedStatBar.SetFillAmount(GetSpeed(engines) / maxShipSpeed); shipAgilityStatBar.SetFillAmount(GetAgility(engines) / maxShipAgility); } // Show health stats Health health = vehicle.GetComponent <Health>(); if (health != null) { for (int i = 0; i < shipHealthStatsBars.Count; ++i) { shipHealthStatsBars[i].SetFillAmount(health.GetMaxHealthByType(shipHealthStatsBars[i].HealthType) / maxShipHealthByHealthType[i]); } } }
protected float GetSpeed(VehicleEngines3D engines) { return(engines.GetDefaultMaxSpeedByAxis(false).z); }
protected float GetAgility(VehicleEngines3D engines) { return((engines.MaxSteeringForces.x + engines.MaxSteeringForces.y + engines.MaxSteeringForces.z) / 3f); }