Implement casettes

This commit is contained in:
Jens Pitkänen 2020-04-21 02:55:24 +03:00
parent eb9832e14f
commit 2b95d1f68b
8 changed files with 265 additions and 12 deletions

View File

@ -10,8 +10,9 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 388935964095823363} - component: {fileID: 388935964095823363}
- component: {fileID: 388935964095823360} - component: {fileID: 388935964095823360}
- component: {fileID: 388935964095823361} - component: {fileID: 8749723819828979553}
m_Layer: 0 - component: {fileID: 7525334960177098028}
m_Layer: 13
m_Name: Casette m_Name: Casette
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -46,10 +47,10 @@ Rigidbody:
m_AngularDrag: 0.05 m_AngularDrag: 0.05
m_UseGravity: 1 m_UseGravity: 1
m_IsKinematic: 0 m_IsKinematic: 0
m_Interpolate: 0 m_Interpolate: 1
m_Constraints: 0 m_Constraints: 0
m_CollisionDetection: 0 m_CollisionDetection: 0
--- !u!114 &388935964095823361 --- !u!114 &8749723819828979553
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
@ -58,12 +59,125 @@ MonoBehaviour:
m_GameObject: {fileID: 388935964095823366} m_GameObject: {fileID: 388935964095823366}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f70b810850590804092bb2c772ea6012, type: 3} m_Script: {fileID: 11500000, guid: df6e90d9f78abce48bed9c6269482e28, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Quality: {fileID: 0} Clips:
IgnitePoint: {fileID: 0} - {fileID: 8300000, guid: 2b23e5fe1d3f4ff458b43bc8de2322da, type: 3}
Grabbed: 0 - {fileID: 8300000, guid: 9280a563b2aecaf4aa564668354a4198, type: 3}
- {fileID: 8300000, guid: d1c7349c608493944ba60257cadee2d5, type: 3}
- {fileID: 8300000, guid: 5949c62627e28cb439290ab239ac906a, type: 3}
- {fileID: 8300000, guid: a578368d2630ef84bb0d9ef9ed0b61c2, type: 3}
--- !u!82 &7525334960177098028
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 388935964095823366}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: -6189427169395524444, guid: 032de345950918c4e89684078c6a7213,
type: 2}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 0
m_Volume: 1
m_Pitch: 1
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: 0
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!65 &6986160423568067126
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8521982733029884806}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 0.0031601759, y: 0.0019185896, z: 0.00047792346}
m_Center: {x: 0, y: -0.00000045137122, z: 0}
--- !u!1001 &388935963055561359 --- !u!1001 &388935963055561359
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -141,8 +255,19 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: Casette value: Casette
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -927199367670048503, guid: c261ecab8d490a549a26abb254febca6,
type: 3}
propertyPath: m_Layer
value: 13
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c261ecab8d490a549a26abb254febca6, type: 3} m_SourcePrefab: {fileID: 100100000, guid: c261ecab8d490a549a26abb254febca6, type: 3}
--- !u!1 &8521982733029884806 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: -927199367670048503, guid: c261ecab8d490a549a26abb254febca6,
type: 3}
m_PrefabInstance: {fileID: 388935963055561359}
m_PrefabAsset: {fileID: 0}
--- !u!4 &4620539269408403861 stripped --- !u!4 &4620539269408403861 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: -4216859302048453862, guid: c261ecab8d490a549a26abb254febca6, m_CorrespondingSourceObject: {fileID: -4216859302048453862, guid: c261ecab8d490a549a26abb254febca6,

View File

@ -952,6 +952,9 @@ MonoBehaviour:
ItemLayer: ItemLayer:
serializedVersion: 2 serializedVersion: 2
m_Bits: 1024 m_Bits: 1024
CasetteLayer:
serializedVersion: 2
m_Bits: 8192
DroppingRaycastMask: DroppingRaycastMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 3895 m_Bits: 3895

View File

@ -0,0 +1,57 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class CasettePickup : MonoBehaviour {
public AudioClip[] Clips;
public string DisplayPrompt {
get {
return Playing ? "Queue casette" : "Play casette";
}
}
public bool Playing {
get {
return Source.isPlaying;
}
}
private AudioSource Source;
private CasettePickup PreviousInQueue;
private int WaitingIndex;
private bool Disappear;
private void Awake() {
Source = GetComponent<AudioSource>();
CasetteProgress.CasetteCount = Clips.Length;
Disappear = false;
}
private void Update() {
if (Disappear) {
transform.localScale = Vector3.Lerp(transform.localScale, Vector3.zero, 10f * Time.deltaTime);
}
if (PreviousInQueue != null) {
if (!PreviousInQueue.Playing) {
PreviousInQueue = null;
Source.PlayOneShot(Clips[WaitingIndex]);
}
} else if (CasetteProgress.AllCasettesPlayed && !Playing) {
Destroy(gameObject);
}
}
public void Play(CasettePickup previous) {
int Index = CasetteProgress.PlayNext();
if (Index != -1) {
Disappear = true;
if (previous == null) {
Source.PlayOneShot(Clips[Index]);
} else {
PreviousInQueue = previous;
WaitingIndex = Index;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: df6e90d9f78abce48bed9c6269482e28
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CasetteProgress : MonoBehaviour {
public static int CasetteIndex;
public static int CasetteCount;
public static bool AllCasettesPlayed {
get {
return CasetteIndex >= CasetteCount;
}
}
private void Start() {
CasetteIndex = 0;
CasetteCount = 0;
}
public static int PlayNext() {
if (!AllCasettesPlayed) {
int Index = CasetteIndex;
CasetteIndex++;
return Index;
} else {
return -1;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: abaf19d90daa02f469221bf25f8e8e91
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,6 +12,7 @@ public class ItemGrabber : MonoBehaviour {
public CanvasGroup SecondaryIndicator; public CanvasGroup SecondaryIndicator;
public Text SecondaryText; public Text SecondaryText;
public LayerMask ItemLayer; public LayerMask ItemLayer;
public LayerMask CasetteLayer;
public LayerMask DroppingRaycastMask; public LayerMask DroppingRaycastMask;
public float Distance; public float Distance;
@ -23,6 +24,9 @@ public class ItemGrabber : MonoBehaviour {
public Torch Torch; public Torch Torch;
public GameObject NextTorch; public GameObject NextTorch;
private CasettePickup PreviousCasette = null;
private CasettePickup Casette = null;
private float LastCasetteHitTime = -1;
private Item LookedAtItem = null; private Item LookedAtItem = null;
private float LastItemHitTime = -1; private float LastItemHitTime = -1;
@ -49,13 +53,25 @@ public class ItemGrabber : MonoBehaviour {
LookedAtItem = null; LookedAtItem = null;
} }
if (Physics.Raycast(From, Direction, out Hit, Distance, CasetteLayer) &&
Hit.collider.attachedRigidbody != null) {
Casette = Hit.collider.attachedRigidbody.GetComponent<CasettePickup>();
LastCasetteHitTime = Time.time;
} else if (Time.time - LastCasetteHitTime > 0.1f) {
Casette = null;
}
if (Physics.Raycast(From, Direction, out Hit, Distance * 2f, 1 << LayerMask.NameToLayer("Campfire")) && if (Physics.Raycast(From, Direction, out Hit, Distance * 2f, 1 << LayerMask.NameToLayer("Campfire")) &&
Hit.collider.attachedRigidbody != null) { Hit.collider.attachedRigidbody != null) {
Campfire = Hit.collider.attachedRigidbody.GetComponent<Campfire>(); Campfire = Hit.collider.attachedRigidbody.GetComponent<Campfire>();
CanIgniteTorch |= Campfire != null && TorchableItem != null; CanIgniteTorch |= Campfire != null && TorchableItem != null;
} }
if (Campfire == null && LookedAtItem != null && Input.GetButtonDown("Grab")) { if (Casette != null && Input.GetButtonDown("Grab")) {
Casette.Play(PreviousCasette);
PreviousCasette = Casette;
Casette = null;
} else if (Campfire == null && LookedAtItem != null && Input.GetButtonDown("Grab")) {
LookedAtItem.PickUp(HandTransform); LookedAtItem.PickUp(HandTransform);
GrabbedItems.Add(LookedAtItem); GrabbedItems.Add(LookedAtItem);
} }
@ -118,9 +134,11 @@ public class ItemGrabber : MonoBehaviour {
} }
PrimaryIndicator.alpha = Mathf.Lerp(PrimaryIndicator.alpha, PrimaryIndicator.alpha = Mathf.Lerp(PrimaryIndicator.alpha,
LookedAtItem != null || Campfire != null || ThrowableItem != null ? 1 : 0, Casette != null || LookedAtItem != null || Campfire != null || ThrowableItem != null ? 1 : 0,
10f * Time.deltaTime); 10f * Time.deltaTime);
if (Campfire != null && ThrowableItem != null) { if (Casette != null) {
PrimaryText.text = Casette.DisplayPrompt;
} else if (Campfire != null && ThrowableItem != null) {
PrimaryText.text = $"Burn {ThrowableItem.Quality.DisplayName}"; PrimaryText.text = $"Burn {ThrowableItem.Quality.DisplayName}";
} else if (LookedAtItem != null && Campfire == null) { } else if (LookedAtItem != null && Campfire == null) {
PrimaryText.text = $"Take {LookedAtItem.Quality.DisplayName}"; PrimaryText.text = $"Take {LookedAtItem.Quality.DisplayName}";

View File

@ -22,7 +22,7 @@ TagManager:
- Item - Item
- Player - Player
- Walls for Players - Walls for Players
- - Casette
- -
- -
- -