Добавлен HUD интерфейс

This commit is contained in:
Max_Divizion 2024-06-03 17:14:17 +03:00
parent 5fabcc5452
commit 0e4bc21938
9 changed files with 39 additions and 325 deletions

View File

@ -1,45 +1,28 @@
//----------------------------------------------
// Realistic Car Controller
//
// Copyright © 2014 - 2023 BoneCracker Games
// https://www.bonecrackergames.com
// Buğra Özdoğanlar
//
//----------------------------------------------
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Receiving inputs from active vehicle on your scene, and feeds dashboard needles, texts, images.
/// </summary>
[AddComponentMenu("BoneCracker Games/Realistic Car Controller/UI/RCC UI Dashboard Inputs")]
public class RCC_DashboardInputs : MonoBehaviour {
public class RCC_DashboardInputs : MonoBehaviour
{
public RCC_CarControllerV3 vehicle; // Target vehicle.
public bool autoAssignVehicle = true; // Auto assign target vehicle as player vehicle from the RCC_SceneManager.
// public bool autoAssignVehicle = true; // Auto assign target vehicle as player vehicle from the RCC_SceneManager.
// Needles.
[Header("Needles")]
public GameObject RPMNeedle;
public GameObject KMHNeedle;
public GameObject turboGauge;
public GameObject turboNeedle;
public GameObject NOSGauge;
public GameObject NoSNeedle;
public GameObject heatGauge;
public GameObject heatNeedle;
public GameObject fuelGauge;
public GameObject fuelNeedle;
// Needle rotations.
private float RPMNeedleRotation = 0f;
private float KMHNeedleRotation = 0f;
private float BoostNeedleRotation = 0f;
private float NoSNeedleRotation = 0f;
private float heatNeedleRotation = 0f;
private float fuelNeedleRotation = 0f;
// Variables of the player vehicle.
[HideInInspector] public float RPM;
@ -48,19 +31,10 @@ public class RCC_DashboardInputs : MonoBehaviour {
[HideInInspector] public float Gear;
[HideInInspector] public bool changingGear = false;
[HideInInspector] public bool NGear = false;
[HideInInspector] public bool ABS = false;
[HideInInspector] public bool ESP = false;
[HideInInspector] public bool Park = false;
[HideInInspector] public bool Headlights = false;
[HideInInspector] public RCC_CarControllerV3.IndicatorsOn indicators;
private void Update() {
if (autoAssignVehicle && RCC_SceneManager.Instance.activePlayerVehicle)
vehicle = RCC_SceneManager.Instance.activePlayerVehicle;
else
vehicle = null;
private void Update()
{
// If no any player vehicle, return.
if (!vehicle)
return;
@ -70,71 +44,18 @@ public class RCC_DashboardInputs : MonoBehaviour {
return;
// If nos gauge is selected, enable or disable gauge related to vehicle.
if (NOSGauge) {
if (vehicle.useNOS) {
if (NOSGauge)
{
if (vehicle.useNOS)
{
if (!NOSGauge.activeSelf)
NOSGauge.SetActive(true);
} else {
}
else
{
if (NOSGauge.activeSelf)
NOSGauge.SetActive(false);
}
}
// If turbo gauge is selected, enable or disable turbo gauge related to vehicle.
if (turboGauge) {
if (vehicle.useTurbo) {
if (!turboGauge.activeSelf)
turboGauge.SetActive(true);
} else {
if (turboGauge.activeSelf)
turboGauge.SetActive(false);
}
}
// If heat gauge is selected, enable or disable heat gauge related to vehicle.
if (heatGauge) {
if (vehicle.useEngineHeat) {
if (!heatGauge.activeSelf)
heatGauge.SetActive(true);
} else {
if (heatGauge.activeSelf)
heatGauge.SetActive(false);
}
}
// If fuel gauge is selected, enable or disable fuel gauge related to vehicle.
if (fuelGauge) {
if (vehicle.useFuelConsumption) {
if (!fuelGauge.activeSelf)
fuelGauge.SetActive(true);
} else {
if (fuelGauge.activeSelf)
fuelGauge.SetActive(false);
}
}
// Getting variables from the player vehicle.
@ -144,64 +65,34 @@ public class RCC_DashboardInputs : MonoBehaviour {
Gear = vehicle.currentGear;
changingGear = vehicle.changingGear;
NGear = vehicle.NGear;
ABS = vehicle.ABSAct;
ESP = vehicle.ESPAct;
Park = vehicle.handbrakeInput > .1f ? true : false;
Headlights = vehicle.lowBeamHeadLightsOn || vehicle.highBeamHeadLightsOn;
indicators = vehicle.indicatorsOn;
// If RPM needle is selected, assign rotation of the needle.
if (RPMNeedle) {
if (RPMNeedle)
{
RPMNeedleRotation = (vehicle.engineRPM / 50f);
RPMNeedleRotation = Mathf.Clamp(RPMNeedleRotation, 0f, 180f);
RPMNeedle.transform.eulerAngles = new Vector3(RPMNeedle.transform.eulerAngles.x, RPMNeedle.transform.eulerAngles.y, -RPMNeedleRotation);
}
// If KMH needle is selected, assign rotation of the needle.
if (KMHNeedle) {
if (KMHNeedle)
{
if (RCC_Settings.Instance.units == RCC_Settings.Units.KMH)
KMHNeedleRotation = (vehicle.speed);
else
KMHNeedleRotation = (vehicle.speed * 0.62f);
KMHNeedle.transform.eulerAngles = new Vector3(KMHNeedle.transform.eulerAngles.x, KMHNeedle.transform.eulerAngles.y, -KMHNeedleRotation);
}
// If turbo needle is selected, assign rotation of the needle.
if (turboNeedle) {
BoostNeedleRotation = (vehicle.turboBoost / 30f) * 270f;
turboNeedle.transform.eulerAngles = new Vector3(turboNeedle.transform.eulerAngles.x, turboNeedle.transform.eulerAngles.y, -BoostNeedleRotation);
}
// If nos needle is selected, assign rotation of the needle.
if (NoSNeedle) {
if (NoSNeedle)
{
NoSNeedleRotation = (vehicle.NoS / 100f) * 270f;
NoSNeedle.transform.eulerAngles = new Vector3(NoSNeedle.transform.eulerAngles.x, NoSNeedle.transform.eulerAngles.y, -NoSNeedleRotation);
}
// If heat needle is selected, assign rotation of the needle.
if (heatNeedle) {
heatNeedleRotation = (vehicle.engineHeat / 110f) * 270f;
heatNeedle.transform.eulerAngles = new Vector3(heatNeedle.transform.eulerAngles.x, heatNeedle.transform.eulerAngles.y, -heatNeedleRotation);
}
// If fuel needle is selected, assign rotation of the needle.
if (fuelNeedle) {
fuelNeedleRotation = (vehicle.fuelTank / vehicle.fuelTankCapacity) * 270f;
fuelNeedle.transform.eulerAngles = new Vector3(fuelNeedle.transform.eulerAngles.x, fuelNeedle.transform.eulerAngles.y, -fuelNeedleRotation);
}
}

View File

@ -1,12 +1,4 @@
//----------------------------------------------
// Realistic Car Controller
//
// Copyright © 2014 - 2023 BoneCracker Games
// https://www.bonecrackergames.com
// Buğra Özdoğanlar
//
//----------------------------------------------

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

View File

@ -1,15 +1,4 @@
//----------------------------------------------
// Realistic Car Controller
//
// Copyright © 2014 - 2023 BoneCracker Games
// https://www.bonecrackergames.com
// Buğra Özdoğanlar
//
//----------------------------------------------
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
@ -17,13 +6,16 @@ using UnityEngine.UI;
/// </summary>
[AddComponentMenu("BoneCracker Games/Realistic Car Controller/UI/RCC UI Dashboard Displayer")]
[RequireComponent(typeof(RCC_DashboardInputs))]
public class RCC_UIDashboardDisplay : MonoBehaviour {
public class RCC_UIDashboardDisplay : MonoBehaviour
{
// Inputs of the dashboard elements.
private RCC_DashboardInputs inputs;
private RCC_DashboardInputs Inputs {
private RCC_DashboardInputs Inputs
{
get {
get
{
if (inputs == null)
inputs = GetComponent<RCC_DashboardInputs>();
@ -38,118 +30,37 @@ public class RCC_UIDashboardDisplay : MonoBehaviour {
public enum DisplayType { Full, Customization, TopButtonsOnly, Off }
public RCC_CarControllerV3 vehicle;
public bool autoAssignVehicle = true;
//public bool autoAssignVehicle = true;
// Buttons, texts, images, and dropdown menus.
[Header("Panels")]
public GameObject controllerButtons;
public GameObject gauges;
public GameObject customizationMenu;
[Header("Texts")]
public Text RPMLabel;
public Text KMHLabel;
public Text GearLabel;
public Text recordingLabel;
[Header("Images")]
public Image ABS;
public Image ESP;
public Image Park;
public Image Headlights;
public Image leftIndicator;
public Image rightIndicator;
public Image heatIndicator;
public Image fuelIndicator;
public Image rpmIndicator;
[Header("Colors")]
public Color color_On = Color.yellow;
public Color color_Off = Color.white;
[Header("Dropdowns")]
public Dropdown mobileControllersDropdown;
private void Update() {
if (mobileControllersDropdown)
mobileControllersDropdown.interactable = RCC_Settings.Instance.mobileControllerEnabled;
// Enabling / disabling corresponding elements related to choosen display type.
switch (displayType) {
case DisplayType.Full:
if (controllerButtons && !controllerButtons.activeSelf)
controllerButtons.SetActive(true);
if (gauges && !gauges.activeSelf)
gauges.SetActive(true);
if (customizationMenu && customizationMenu.activeSelf)
customizationMenu.SetActive(false);
break;
case DisplayType.Customization:
if (controllerButtons && controllerButtons.activeSelf)
controllerButtons.SetActive(false);
if (gauges && gauges.activeSelf)
gauges.SetActive(false);
if (customizationMenu && !customizationMenu.activeSelf)
customizationMenu.SetActive(true);
break;
case DisplayType.TopButtonsOnly:
if (controllerButtons.activeSelf)
controllerButtons.SetActive(false);
if (gauges.activeSelf)
gauges.SetActive(false);
if (customizationMenu.activeSelf)
customizationMenu.SetActive(false);
break;
case DisplayType.Off:
if (controllerButtons && controllerButtons.activeSelf)
controllerButtons.SetActive(false);
if (gauges && gauges.activeSelf)
gauges.SetActive(false);
if (customizationMenu && customizationMenu.activeSelf)
customizationMenu.SetActive(false);
break;
}
}
private void LateUpdate() {
private void LateUpdate()
{
// If inputs are not enabled yet, disable it and return.
if (!Inputs.enabled)
return;
if (autoAssignVehicle && RCC_SceneManager.Instance.activePlayerVehicle)
vehicle = RCC_SceneManager.Instance.activePlayerVehicle;
if (!vehicle)
return;
if (RPMLabel)
RPMLabel.text = Inputs.RPM.ToString("0");
if (KMHLabel) {
if (KMHLabel)
{
if (RCC_Settings.Instance.units == RCC_Settings.Units.KMH)
KMHLabel.text = Inputs.KMH.ToString("0") + "\nKMH";
@ -158,7 +69,8 @@ public class RCC_UIDashboardDisplay : MonoBehaviour {
}
if (GearLabel) {
if (GearLabel)
{
if (!Inputs.NGear && !Inputs.changingGear)
GearLabel.text = Inputs.direction == 1 ? (Inputs.Gear + 1).ToString("0") : "R";
@ -167,92 +79,11 @@ public class RCC_UIDashboardDisplay : MonoBehaviour {
}
if (recordingLabel) {
switch (RCC_SceneManager.Instance.recordMode) {
case RCC_SceneManager.RecordMode.Neutral:
if (recordingLabel.gameObject.activeSelf)
recordingLabel.gameObject.SetActive(false);
recordingLabel.text = "";
break;
case RCC_SceneManager.RecordMode.Play:
if (!recordingLabel.gameObject.activeSelf)
recordingLabel.gameObject.SetActive(true);
recordingLabel.text = "Playing";
recordingLabel.color = Color.green;
break;
case RCC_SceneManager.RecordMode.Record:
if (!recordingLabel.gameObject.activeSelf)
recordingLabel.gameObject.SetActive(true);
recordingLabel.text = "Recording";
recordingLabel.color = Color.red;
break;
}
}
if (ABS)
ABS.color = Inputs.ABS == true ? color_On : color_Off;
if (ESP)
ESP.color = Inputs.ESP == true ? color_On : color_Off;
if (Park)
Park.color = Inputs.Park == true ? Color.red : color_Off;
if (Headlights)
Headlights.color = Inputs.Headlights == true ? Color.green : color_Off;
if (heatIndicator)
heatIndicator.color = vehicle.engineHeat >= 100f ? Color.red : new Color(.1f, 0f, 0f);
if (fuelIndicator)
fuelIndicator.color = vehicle.fuelTank < 10f ? Color.red : new Color(.1f, 0f, 0f);
if (rpmIndicator)
rpmIndicator.color = vehicle.engineRPM >= vehicle.maxEngineRPM - 500f ? Color.red : new Color(.1f, 0f, 0f);
if (leftIndicator && rightIndicator) {
switch (Inputs.indicators) {
case RCC_CarControllerV3.IndicatorsOn.Left:
leftIndicator.color = new Color(1f, .5f, 0f);
rightIndicator.color = new Color(.5f, .25f, 0f);
break;
case RCC_CarControllerV3.IndicatorsOn.Right:
leftIndicator.color = new Color(.5f, .25f, 0f);
rightIndicator.color = new Color(1f, .5f, 0f);
break;
case RCC_CarControllerV3.IndicatorsOn.All:
leftIndicator.color = new Color(1f, .5f, 0f);
rightIndicator.color = new Color(1f, .5f, 0f);
break;
case RCC_CarControllerV3.IndicatorsOn.Off:
leftIndicator.color = new Color(.5f, .25f, 0f);
rightIndicator.color = new Color(.5f, .25f, 0f);
break;
}
}
}
public void SetDisplayType(DisplayType _displayType) {
public void SetDisplayType(DisplayType _displayType)
{
displayType = _displayType;

Binary file not shown.