Implement campfire

This commit is contained in:
Jens Pitkänen 2020-04-19 03:00:22 +03:00
parent 1a70bcc3d5
commit 27502d0940
5 changed files with 3002 additions and 353 deletions

View File

@ -12,5 +12,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 89be129a0b3b303478d411ad4ec84e30, type: 3} m_Script: {fileID: 11500000, guid: 89be129a0b3b303478d411ad4ec84e30, type: 3}
m_Name: Stick Burn Quality m_Name: Stick Burn Quality
m_EditorClassIdentifier: m_EditorClassIdentifier:
FuelValue: 10 FuelValue: 5
FlameEffect: 1
BurningSound: {fileID: 0} BurningSound: {fileID: 0}

View File

@ -9,6 +9,9 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 8265150240760341263} - component: {fileID: 8265150240760341263}
- component: {fileID: 1683130550026608685}
- component: {fileID: 986826787110512831}
- component: {fileID: 7293540718676611162}
m_Layer: 0 m_Layer: 0
m_Name: Campfire m_Name: Campfire
m_TagString: Untagged m_TagString: Untagged
@ -29,9 +32,202 @@ Transform:
m_Children: m_Children:
- {fileID: 3464217916028558321} - {fileID: 3464217916028558321}
- {fileID: 5299650773545078260} - {fileID: 5299650773545078260}
- {fileID: 8703236790229133739}
- {fileID: 8279143985661205166}
- {fileID: 664587661892241191}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1683130550026608685
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1791762180592942439}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f97cfece62896c43a1ecf4354b5e229, type: 3}
m_Name:
m_EditorClassIdentifier:
Aliveness: 1
System: {fileID: 2943469733383700679}
AddFuelEffect: 0
--- !u!114 &986826787110512831
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1791762180592942439}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d53e1b3547ca29043b4a527f784da518, type: 3}
m_Name:
m_EditorClassIdentifier:
GameState: {fileID: 0}
DynamicLight: {fileID: 6245881137502637047}
Flame: {fileID: 1683130550026608685}
BurnEffectSource: {fileID: 964052589141395917}
GoodFuelAmount: 20
TooLowFuelColor: {r: 1, g: 0.791215, b: 0.6273585, a: 0}
RandomVarianceDuration: 0.2
RandomVarianceMagnitude: 0.25
LogBurningCooldown: 1
Fuel: 30
--- !u!54 &7293540718676611162
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1791762180592942439}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &4030757379513544979
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 664587661892241191}
- component: {fileID: 3740775333387538961}
m_Layer: 0
m_Name: Collider
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &664587661892241191
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4030757379513544979}
m_LocalRotation: {x: -0.7069834, y: 0, z: 0, w: 0.7072302}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 100, y: 100, z: 100}
m_Children: []
m_Father: {fileID: 8265150240760341263}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: -89.98, y: 0, z: 0}
--- !u!64 &3740775333387538961
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4030757379513544979}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 4
m_Convex: 1
m_CookingOptions: 14
m_Mesh: {fileID: -4095829847968280453, guid: 4facd75878c39c7499d4291e717cda98, type: 3}
--- !u!1 &4797807552203538256
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8703236790229133739}
- component: {fileID: 6245881137502637047}
m_Layer: 0
m_Name: Campfire Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8703236790229133739
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4797807552203538256}
m_LocalRotation: {x: -0.7010575, y: 0.092295825, z: -0.0922958, w: -0.7010574}
m_LocalPosition: {x: 0, y: 1, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8265150240760341263}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: -270, y: 0, z: 15.000001}
--- !u!108 &6245881137502637047
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4797807552203538256}
m_Enabled: 1
serializedVersion: 10
m_Type: 2
m_Shape: 0
m_Color: {r: 1, g: 0.84329563, b: 0.6556604, a: 1}
m_Intensity: 1.5
m_Range: 9.458514
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 0.763
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 7, y: 7}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: NaN, z: -1, w: 1e-45}
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &5974196502008569916 --- !u!1 &5974196502008569916
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -43,7 +239,6 @@ GameObject:
- component: {fileID: 5299650773545078260} - component: {fileID: 5299650773545078260}
- component: {fileID: 2943469733383700679} - component: {fileID: 2943469733383700679}
- component: {fileID: 3600058222818994886} - component: {fileID: 3600058222818994886}
- component: {fileID: 6154584365662919414}
m_Layer: 0 m_Layer: 0
m_Name: Particle System m_Name: Particle System
m_TagString: Untagged m_TagString: Untagged
@ -898,7 +1093,7 @@ ParticleSystem:
rateOverTime: rateOverTime:
serializedVersion: 2 serializedVersion: 2
minMaxState: 0 minMaxState: 0
scalar: 232.9613 scalar: 100
minScalar: 10 minScalar: 10
maxCurve: maxCurve:
serializedVersion: 2 serializedVersion: 2
@ -2007,7 +2202,7 @@ ParticleSystem:
radial: radial:
serializedVersion: 2 serializedVersion: 2
minMaxState: 0 minMaxState: 0
scalar: 1.8634114 scalar: 0.7
minScalar: 0.1 minScalar: 0.1
maxCurve: maxCurve:
serializedVersion: 2 serializedVersion: 2
@ -4796,22 +4991,134 @@ ParticleSystemRenderer:
m_Mesh2: {fileID: 0} m_Mesh2: {fileID: 0}
m_Mesh3: {fileID: 0} m_Mesh3: {fileID: 0}
m_MaskInteraction: 0 m_MaskInteraction: 0
--- !u!114 &6154584365662919414 --- !u!1 &8502149746935864804
MonoBehaviour: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5974196502008569916} serializedVersion: 6
m_Component:
- component: {fileID: 8279143985661205166}
- component: {fileID: 964052589141395917}
m_Layer: 0
m_Name: Burning Effect Audio Source
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8279143985661205166
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8502149746935864804}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.0039999997, y: 0.5292903, z: 0.016000003}
m_LocalScale: {x: 1.1047, y: 0.17583999, z: 1.1398}
m_Children: []
m_Father: {fileID: 8265150240760341263}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!82 &964052589141395917
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8502149746935864804}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 serializedVersion: 4
m_Script: {fileID: 11500000, guid: 5f97cfece62896c43a1ecf4354b5e229, type: 3} OutputAudioMixerGroup: {fileID: -267709887311468707, guid: 032de345950918c4e89684078c6a7213,
m_Name: type: 2}
m_EditorClassIdentifier: m_audioClip: {fileID: 0}
Aliveness: 1 m_PlayOnAwake: 0
System: {fileID: 2943469733383700679} m_Volume: 1
LogEffect: 0 m_Pitch: 1
SecretBoost: 1.6620164 Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1001 &8460551870366396651 --- !u!1001 &8460551870366396651
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

View File

@ -5,5 +5,6 @@ using UnityEngine;
[CreateAssetMenu(fileName = "Unnamed Burn Quality", menuName = "Campfire/Burn Quality")] [CreateAssetMenu(fileName = "Unnamed Burn Quality", menuName = "Campfire/Burn Quality")]
public class BurnQuality : ScriptableObject { public class BurnQuality : ScriptableObject {
public float FuelValue; public float FuelValue;
public float FlameEffect;
public AudioClip BurningSound; public AudioClip BurningSound;
} }

View File

@ -5,6 +5,7 @@ using UnityEngine;
public class Campfire : MonoBehaviour { public class Campfire : MonoBehaviour {
public GameState GameState; public GameState GameState;
public Light DynamicLight; public Light DynamicLight;
public Flame Flame;
[Tooltip("This audiosource will play the clips to indicate that an object has been thrown in the fire.")] [Tooltip("This audiosource will play the clips to indicate that an object has been thrown in the fire.")]
public AudioSource BurnEffectSource; public AudioSource BurnEffectSource;
public float GoodFuelAmount; public float GoodFuelAmount;
@ -36,9 +37,10 @@ public class Campfire : MonoBehaviour {
private void Update() { private void Update() {
if (LogQueue.Count > 0 && Time.time - LastLogBurned > LogBurningCooldown) { if (LogQueue.Count > 0 && Time.time - LastLogBurned > LogBurningCooldown) {
LastLogBurned = Time.time; LastLogBurned = Time.time;
BurnLog(LogQueue[0]); if (BurnLog(LogQueue[0])) {
LogQueue.RemoveAt(0); LogQueue.RemoveAt(0);
} }
}
if (Time.time - LastRandomVarianceChange > RandomVarianceDuration) { if (Time.time - LastRandomVarianceChange > RandomVarianceDuration) {
NextRandomVariance = (Random.value - 0.5f) * 2f * RandomVarianceMagnitude; NextRandomVariance = (Random.value - 0.5f) * 2f * RandomVarianceMagnitude;
@ -49,19 +51,23 @@ public class Campfire : MonoBehaviour {
Fuel -= Time.deltaTime; Fuel -= Time.deltaTime;
DynamicLight.range = Mathf.Log(Fuel + 1f, 10) / 2f * FullRange + RandomVariance; DynamicLight.range = Mathf.Log(Fuel + 1f, 10) / 2f * FullRange + RandomVariance;
DynamicLight.color = Color.Lerp(DynamicLight.color, Fuel < GoodFuelAmount ? TooLowFuelColor : EnoughFuelColor, 10f * Time.deltaTime); DynamicLight.color = Color.Lerp(DynamicLight.color, Fuel < GoodFuelAmount ? TooLowFuelColor : EnoughFuelColor, 10f * Time.deltaTime);
Flame.Aliveness = Mathf.Log(Fuel + 1f, 10) / 2f;
if (Fuel <= 0) { if (Fuel <= 0) {
GameState.Current = State.GameOver; GameState.Current = State.GameOver;
} }
} }
private void BurnLog(Burnable burnable) { private bool BurnLog(Burnable burnable) {
Fuel += burnable.Quality.FuelValue; if (Fuel >= GoodFuelAmount * 2) {
if (Fuel < GoodFuelAmount) { return false;
Fuel += 2; } else {
} Fuel += burnable.Quality.FuelValue * Mathf.Max(0, (2 - Fuel / GoodFuelAmount));
Flame.AddFuelEffect += burnable.Quality.FlameEffect;
BurnEffectSource.PlayOneShot(burnable.Quality.BurningSound); BurnEffectSource.PlayOneShot(burnable.Quality.BurningSound);
Destroy(burnable.gameObject); Destroy(burnable.gameObject);
return true;
}
} }
private void OnCollisionEnter(Collision c) { private void OnCollisionEnter(Collision c) {