Skip to content

Commit

Permalink
Add Light to Microwave (#340) (#638)
Browse files Browse the repository at this point in the history
* Add interior light to microwave when active

* remove completed TODO

* Add spot light to microwave

* Change microwave window to use Glass Absolutely Opaque material
  • Loading branch information
mjboth authored Apr 27, 2021
1 parent 4ff4d1c commit e4be8ec
Show file tree
Hide file tree
Showing 3 changed files with 5,051 additions and 4,930 deletions.
Binary file modified Assets/Art/Models/Furniture/Machines/Kitchen/microwave.fbx
Binary file not shown.
55 changes: 37 additions & 18 deletions Assets/Content/Furniture/Machines/Kitchen/Microwave/Microwave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using UnityEngine.Assertions;

// Handles the microwave object
// TODO: IMPORTANT, rename the SND stuff to Sound
[RequireComponent(typeof(AudioSource))]
public class Microwave : InteractionTargetNetworkBehaviour
{
Expand All @@ -30,6 +29,10 @@ public class Microwave : InteractionTargetNetworkBehaviour
// Sound that plays when it ends a cycle
public AudioClip finishSound;

//used to enable & disable microwave lights
private Material emissionMaterial;
private Light light;

// is it being used rn
// should probably be renamed to busy
// we might have isOn for electricity stuff
Expand All @@ -43,17 +46,22 @@ private void Start()

storageContainer = GetComponent<StorageContainer>();
audioSource = GetComponent<AudioSource>();

emissionMaterial = GetComponent<Renderer>().materials[1];
emissionMaterial.DisableKeyword("_EMISSION");
light = GetComponentInChildren<Light>();
light.enabled = false;
}

public override IInteraction[] GenerateInteractions(InteractionEvent interactionEvent)
{
return new IInteraction[] {new SimpleInteraction
{
// TODO: Should be a custom interaction
// TODO: Should be a custom interaction
Name = "Turn on", CanInteractCallback = CanTurnOn, Interact = TurnOn
}};
}

private bool CanTurnOn(InteractionEvent interactionEvent)
{
if (!InteractionExtensions.RangeCheck(interactionEvent))
Expand All @@ -73,9 +81,8 @@ private bool CanTurnOn(InteractionEvent interactionEvent)
private void TurnOn(InteractionEvent interactionEvent, InteractionReference reference)
{
SetActivated(true);
// TODO: Rename this ASAP, this kind of naming is not allowed
PlayOnSnd();
// Great naming
RunMicrowave();
// Great naming
StartCoroutine(BlastShit());
}

Expand All @@ -92,63 +99,75 @@ private void SetActivated(bool activated)
// Start a cycle
private IEnumerator BlastShit()
{
// waits until the cycle has finished
// waits until the cycle has finished
yield return new WaitForSeconds(MicrowaveDuration);
PlayFinishSnd();
StopMicrowave();
SetActivated(false);

// Process the contents
// Process the contents
CookItems();
}

private void CookItems()
{
var items = AttachedContainer.Container.Items.ToArray();

// tries to get a microweavable in each item that is in the container
// tries to get a microweavable in each item that is in the container
foreach (Item item in items)
{
Microwaveable microwaveable = item.GetComponent<Microwaveable>();
if (microwaveable != null)
{
// if the microwaveable has a result we produce it
// if the microwaveable has a result we produce it
ItemHelpers.ReplaceItem(item, ItemHelpers.CreateItem(microwaveable.ResultingObject));
}
else
{
// if there's no recipe we throw trash
// if there's no recipe we throw trash
ItemHelpers.ReplaceItem(item, ItemHelpers.CreateItem(DestroyedItemPrefab));
}
}
}

[Server]
private void PlayFinishSnd()
private void StopMicrowave()
{
emissionMaterial.DisableKeyword("_EMISSION");
light.enabled = false;

audioSource.Stop();
audioSource.PlayOneShot(finishSound);
RpcPlayFinishSnd();
RpcStopMicrowave();
}

[ClientRpc]
private void RpcPlayFinishSnd()
private void RpcStopMicrowave()
{
emissionMaterial.DisableKeyword("_EMISSION");
light.enabled = false;

audioSource.Stop();
audioSource.PlayOneShot(finishSound);
}

[Server]
private void PlayOnSnd()
private void RunMicrowave()
{
emissionMaterial.EnableKeyword("_EMISSION");
light.enabled = true;

audioSource.Stop();
audioSource.clip = onSound;
audioSource.Play();
RpcPlayOnSnd();
RpcRunMicrowave();
}

[ClientRpc]
private void RpcPlayOnSnd()
private void RpcRunMicrowave()
{
emissionMaterial.EnableKeyword("_EMISSION");
light.enabled = true;

audioSource.Stop();
audioSource.clip = onSound;
audioSource.Play();
Expand Down
Loading

0 comments on commit e4be8ec

Please sign in to comment.