2020-04-30 02:26:18 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2020-05-02 23:47:34 +02:00
|
|
|
|
// TODO: Fix sound when in warn mode
|
|
|
|
|
// TODO: Clamp light to slightly above the terrain
|
|
|
|
|
// TODO: Increase fuel consumption on ground
|
|
|
|
|
|
2020-04-30 02:26:18 +02:00
|
|
|
|
/*
|
|
|
|
|
* <summary>A replacement for the Item class in VR contexts.</summary>
|
|
|
|
|
*/
|
2020-04-30 02:33:23 +02:00
|
|
|
|
[RequireComponent(typeof(Burnable))]
|
2020-04-30 02:26:18 +02:00
|
|
|
|
public class ItemVR : MonoBehaviour {
|
|
|
|
|
public BurnQuality IgnitedQuality;
|
|
|
|
|
public float IgniteDuration;
|
|
|
|
|
public bool Ignited = false;
|
2020-05-02 18:28:42 +02:00
|
|
|
|
public bool Extinguished = false;
|
2020-04-30 02:26:18 +02:00
|
|
|
|
public float TorchDuration;
|
|
|
|
|
public float TorchWarnDuration;
|
|
|
|
|
|
|
|
|
|
[Header("Burning indicators")]
|
|
|
|
|
public GameObject StickObject;
|
2020-05-02 18:28:42 +02:00
|
|
|
|
public GameObject DestroyedOnExtinguish;
|
2020-04-30 02:26:18 +02:00
|
|
|
|
public GameObject TorchObject;
|
|
|
|
|
public ParticleSystem FireParticles;
|
|
|
|
|
public Light TorchLight;
|
|
|
|
|
public Color WarnColor;
|
2020-04-30 02:50:47 +02:00
|
|
|
|
public GameObject FireVolume;
|
2020-05-01 04:37:20 +02:00
|
|
|
|
public AudioSource TorchSound;
|
|
|
|
|
public AudioClip[] FireClips;
|
2020-04-30 02:26:18 +02:00
|
|
|
|
|
|
|
|
|
[Header("Runtime values")]
|
|
|
|
|
public float TorchFuel;
|
|
|
|
|
|
2020-04-30 02:33:23 +02:00
|
|
|
|
private Burnable Burnable;
|
2020-04-30 02:26:18 +02:00
|
|
|
|
private int BurningSourceCount = 0;
|
|
|
|
|
private float IgnitionStartTime = -1;
|
|
|
|
|
private Color NormalColor;
|
|
|
|
|
|
|
|
|
|
private void Start() {
|
2020-04-30 02:33:23 +02:00
|
|
|
|
Burnable = GetComponent<Burnable>();
|
2020-04-30 02:26:18 +02:00
|
|
|
|
NormalColor = TorchLight.color;
|
|
|
|
|
TorchObject.SetActive(Ignited);
|
|
|
|
|
StickObject.SetActive(!Ignited);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update() {
|
2020-05-02 18:28:42 +02:00
|
|
|
|
if (Extinguished) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-05-01 04:37:20 +02:00
|
|
|
|
|
2020-04-30 02:26:18 +02:00
|
|
|
|
if (Ignited && TorchLight.enabled) {
|
|
|
|
|
TorchFuel -= Time.deltaTime;
|
|
|
|
|
if (TorchFuel < TorchWarnDuration) {
|
|
|
|
|
TorchLight.color = Color.Lerp(TorchLight.color, WarnColor, 5f * Time.deltaTime);
|
|
|
|
|
} else {
|
|
|
|
|
TorchLight.color = Color.Lerp(TorchLight.color, NormalColor, 5f * Time.deltaTime);
|
|
|
|
|
}
|
2020-05-01 04:37:20 +02:00
|
|
|
|
|
|
|
|
|
if ((TorchSound.clip.length - TorchSound.time) <= Time.deltaTime || !TorchSound.isPlaying) {
|
|
|
|
|
TorchSound.clip = FireClips[Random.Range(0, FireClips.Length)];
|
|
|
|
|
TorchSound.time = 0;
|
|
|
|
|
TorchSound.Play();
|
|
|
|
|
}
|
|
|
|
|
float FuelFactor = 1f / (Mathf.Max(0, TorchDuration + 0.5f - TorchFuel) * 4f + 1);
|
|
|
|
|
TorchSound.volume = 0.4f + 0.6f * FuelFactor - (TorchFuel < TorchWarnDuration ? 0.3f : 0);
|
|
|
|
|
|
2020-04-30 02:26:18 +02:00
|
|
|
|
if (TorchFuel <= 0) {
|
|
|
|
|
FireParticles.Stop();
|
2020-04-30 02:50:47 +02:00
|
|
|
|
FireVolume.layer = gameObject.layer;
|
2020-04-30 02:26:18 +02:00
|
|
|
|
TorchLight.range = Mathf.Lerp(TorchLight.range, 0, 10f * Time.deltaTime);
|
|
|
|
|
if (TorchLight.range < 0.01f) {
|
2020-05-02 18:28:42 +02:00
|
|
|
|
Destroy(DestroyedOnExtinguish);
|
|
|
|
|
Extinguished = true;
|
2020-04-30 02:26:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-01 04:37:20 +02:00
|
|
|
|
} else if (!Ignited && !Burnable.BurningInCampfire && IgnitionStartTime != -1 && Time.time - IgnitionStartTime >= IgniteDuration) {
|
2020-04-30 02:26:18 +02:00
|
|
|
|
Ignited = true;
|
|
|
|
|
TorchFuel = TorchDuration;
|
|
|
|
|
TorchObject.SetActive(true);
|
|
|
|
|
FireParticles.Play();
|
|
|
|
|
StickObject.SetActive(false);
|
2020-04-30 02:33:23 +02:00
|
|
|
|
Burnable.Quality = IgnitedQuality;
|
2020-04-30 02:26:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider collider) {
|
|
|
|
|
if (!Ignited && collider.gameObject.layer == LayerMask.NameToLayer("Fire")) {
|
|
|
|
|
if (BurningSourceCount == 0) {
|
|
|
|
|
IgnitionStartTime = Time.time;
|
|
|
|
|
}
|
|
|
|
|
BurningSourceCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerExit(Collider collider) {
|
|
|
|
|
if (!Ignited && collider.gameObject.layer == LayerMask.NameToLayer("Fire")) {
|
|
|
|
|
BurningSourceCount--;
|
|
|
|
|
if (BurningSourceCount == 0) {
|
|
|
|
|
IgnitionStartTime = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|