Add burning queue

This commit is contained in:
Jens Pitkänen 2020-04-19 02:39:52 +03:00
parent 2eb12b1cd0
commit 98d0278c03
5 changed files with 42 additions and 10 deletions

View File

@ -9,7 +9,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 8433165236288212749}
m_Layer: 0
m_Layer: 11
m_Name: Item Holder
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -42,7 +42,7 @@ GameObject:
- component: {fileID: 6125707628839966529}
- component: {fileID: 6125707628839966528}
- component: {fileID: 6125707628839966535}
m_Layer: 0
m_Layer: 11
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
@ -188,7 +188,7 @@ GameObject:
- component: {fileID: 6125707630481988397}
- component: {fileID: 6125707630481988371}
- component: {fileID: 7093134810128755097}
m_Layer: 0
m_Layer: 11
m_Name: Player
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -222,6 +222,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b656f92dbeaf1784786c317df80ca152, type: 3}
m_Name:
m_EditorClassIdentifier:
GameState: {fileID: 0}
BodyTransform: {fileID: 6125707630481988396}
HeadTransform: {fileID: 6125707628839966534}
--- !u!114 &6125707630481988397
@ -277,6 +278,7 @@ MonoBehaviour:
CameraTransform: {fileID: 6125707628839966534}
HandTransform: {fileID: 8433165236288212749}
GrabHint: {fileID: 0}
GrabText: {fileID: 0}
ItemLayer:
serializedVersion: 2
m_Bits: 1024

View File

@ -289,6 +289,7 @@ MonoBehaviour:
TooLowFuelColor: {r: 1, g: 0.791215, b: 0.6273585, a: 0}
RandomVarianceDuration: 0.2
RandomVarianceMagnitude: 0.25
LogBurningCooldown: 1
Fuel: 60
--- !u!1 &404370537
GameObject:

View File

@ -12,6 +12,8 @@ public class Campfire : MonoBehaviour {
public Color TooLowFuelColor;
public float RandomVarianceDuration;
public float RandomVarianceMagnitude;
[Tooltip("How long of a break the campfire takes between eating logs, if multiple are placed on it.")]
public float LogBurningCooldown;
[Header("Runtime values")]
public float Fuel;
@ -23,12 +25,21 @@ public class Campfire : MonoBehaviour {
private float NextRandomVariance = 0;
private float LastRandomVarianceChange = 0;
private List<Burnable> LogQueue = new List<Burnable>();
private float LastLogBurned = 0;
private void Awake() {
EnoughFuelColor = DynamicLight.color;
FullRange = DynamicLight.range;
}
private void Update() {
if (LogQueue.Count > 0 && Time.time - LastLogBurned > LogBurningCooldown) {
LastLogBurned = Time.time;
BurnLog(LogQueue[0]);
LogQueue.RemoveAt(0);
}
if (Time.time - LastRandomVarianceChange > RandomVarianceDuration) {
NextRandomVariance = (Random.value - 0.5f) * 2f * RandomVarianceMagnitude;
LastRandomVarianceChange = Time.time;
@ -44,13 +55,29 @@ public class Campfire : MonoBehaviour {
}
}
private void BurnLog(Burnable burnable) {
Fuel += burnable.Quality.FuelValue;
if (Fuel < GoodFuelAmount) {
Fuel += 2;
}
BurnEffectSource.PlayOneShot(burnable.Quality.BurningSound);
Destroy(burnable.gameObject);
}
private void OnCollisionEnter(Collision c) {
if (c.collider.attachedRigidbody != null && c.collider.attachedRigidbody) {
Burnable Burnable = c.collider.attachedRigidbody.GetComponent<Burnable>();
if (Burnable != null) {
Fuel += Burnable.Quality.FuelValue;
BurnEffectSource.PlayOneShot(Burnable.Quality.BurningSound);
Destroy(c.collider.attachedRigidbody.gameObject);
LogQueue.Add(Burnable);
}
}
}
private void OnCollisionExit(Collision c) {
if (c.collider.attachedRigidbody != null && c.collider.attachedRigidbody) {
Burnable Burnable = c.collider.attachedRigidbody.GetComponent<Burnable>();
if (Burnable != null) {
LogQueue.Remove(Burnable);
}
}
}

View File

@ -3,7 +3,7 @@
--- !u!55 &1
PhysicsManager:
m_ObjectHideFlags: 0
serializedVersion: 11
serializedVersion: 13
m_Gravity: {x: 0, y: -9.81, z: 0}
m_DefaultMaterial: {fileID: 0}
m_BounceThreshold: 2
@ -17,11 +17,12 @@ PhysicsManager:
m_ClothInterCollisionDistance: 0
m_ClothInterCollisionStiffness: 0
m_ContactsGeneration: 1
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_AutoSimulation: 1
m_AutoSyncTransforms: 0
m_ReuseCollisionCallbacks: 1
m_ClothInterCollisionSettingsToggle: 0
m_ClothGravity: {x: 0, y: -9.81, z: 0}
m_ContactPairsMode: 0
m_BroadphaseType: 0
m_WorldBounds:
@ -31,4 +32,5 @@ PhysicsManager:
m_FrictionType: 0
m_EnableEnhancedDeterminism: 0
m_EnableUnifiedHeightmaps: 1
m_DefaultMaxAngluarSpeed: 7
m_SolverType: 0
m_DefaultMaxAngularSpeed: 7

View File

@ -18,7 +18,7 @@ TagManager:
- Post-Processing
- Campfire
- Item
-
- Player
-
-
-