diff --git a/BOX-BUX/Assets/Scripts/DropZone.cs b/BOX-BUX/Assets/Scripts/DropZone.cs new file mode 100644 index 0000000..50bea8a --- /dev/null +++ b/BOX-BUX/Assets/Scripts/DropZone.cs @@ -0,0 +1,59 @@ +using Assets.Scripts; +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using UnityEngine; + +public class DropZone : MonoBehaviour +{ + private class ChangingState + { + public float countdown; + public bool changing; + + public ChangingState(float countdown, bool changing) + { + this.countdown = countdown; + this.changing = changing; + } + } + + public ChangeType changeType; + public float secondsToChange = 0.5f; + private Dictionary countdowns = new Dictionary(); + + private void Update() + { + foreach(var box in countdowns.Keys.ToList()) + { + var state = countdowns[box]; + if (!state.changing) + { + countdowns.Remove(box); + continue; + } + state.countdown -= Time.deltaTime; + if(state.countdown <= 0) + { + countdowns.Remove(box); + ModificationSystem.MakeChange(box, changeType); + } + } + } + + public void OnTriggerStay(Collider other) + { + Triggerable triggerable = other.GetComponent(); + if (triggerable == null) + { + return; + } + Pickable toChange = triggerable.asPickable(); + + if (!countdowns.ContainsKey(toChange)) + { + countdowns.Add(toChange, new ChangingState(secondsToChange, toChange.holder.held != toChange)); + } + } +} diff --git a/BOX-BUX/Assets/Scripts/DropZone.cs.meta b/BOX-BUX/Assets/Scripts/DropZone.cs.meta new file mode 100644 index 0000000..3e2d3c0 --- /dev/null +++ b/BOX-BUX/Assets/Scripts/DropZone.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 976e12243445f7a449b7d98a0046ad98 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/BOX-BUX/Assets/Scripts/Pickable.cs b/BOX-BUX/Assets/Scripts/Pickable.cs index d16e26d..f7b53ea 100644 --- a/BOX-BUX/Assets/Scripts/Pickable.cs +++ b/BOX-BUX/Assets/Scripts/Pickable.cs @@ -2,207 +2,205 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using VHS; -namespace VHS +public class Pickable : InteractableBase, Triggerable { - public class Pickable : InteractableBase, Triggerable + public Holder holder; + public Rigidbody rigid; + public ColorType colorType; + public MaterialType materialType; + public ShapeType shapeType; + public SizeType sizeType; + public Spawner spawner; + + private void Awake() { - public Holder holder; - public Rigidbody rigid; - public ColorType colorType; - public MaterialType materialType; - public ShapeType shapeType; - public SizeType sizeType; - public Spawner spawner; - - private void Awake() - { - holder = FindObjectOfType(); - rigid = GetComponent(); - } + holder = FindObjectOfType(); + rigid = GetComponent(); + } - public override void OnInteract() + public override void OnInteract() + { + if (holder.held == null) { - if (holder.held == null) - { - holder.SetHeld(this); - rigid.isKinematic = true; - } + holder.SetHeld(this); + rigid.isKinematic = true; } + } + + public void SetMaterial(MaterialType type) + { + SetMaterialAndColor(type, colorType); + } + + public void SetColor(ColorType type) + { + SetMaterialAndColor(materialType, type); + } - public void SetMaterial(MaterialType type) + private void SetMaterialAndColor(MaterialType materialType, ColorType colorType) + { + ColorAndMaterialType? type = null; + switch (materialType) { - SetMaterialAndColor(type, colorType); + case MaterialType.ABSTRACT: + switch (colorType) + { + case ColorType.BLUE: + type = ColorAndMaterialType.ABSTRACT_BLUE; + break; + case ColorType.GREY: + type = ColorAndMaterialType.ABSTRACT_GREY; + break; + case ColorType.RED: + type = ColorAndMaterialType.ABSTRACT_RED; + break; + case ColorType.YELLOW: + type = ColorAndMaterialType.ABSTRACT_YELLOW; + break; + } + break; + case MaterialType.CHECKERED: + switch (colorType) + { + case ColorType.BLUE: + type = ColorAndMaterialType.CHECKERED_BLUE; + break; + case ColorType.GREY: + type = ColorAndMaterialType.CHECKERED_GREY; + break; + case ColorType.RED: + type = ColorAndMaterialType.CHECKERED_RED; + break; + case ColorType.YELLOW: + type = ColorAndMaterialType.CHECKERED_YELLOW; + break; + } + break; + case MaterialType.MATTE: + switch (colorType) + { + case ColorType.BLUE: + type = ColorAndMaterialType.MATTE_BLUE; + break; + case ColorType.GREY: + type = ColorAndMaterialType.MATTE_GREY; + break; + case ColorType.RED: + type = ColorAndMaterialType.MATTE_RED; + break; + case ColorType.YELLOW: + type = ColorAndMaterialType.MATTE_YELLOW; + break; + } + break; + case MaterialType.METAL: + switch (colorType) + { + case ColorType.BLUE: + type = ColorAndMaterialType.METAL_BLUE; + break; + case ColorType.GREY: + type = ColorAndMaterialType.METAL_GREY; + break; + case ColorType.RED: + type = ColorAndMaterialType.METAL_RED; + break; + case ColorType.YELLOW: + type = ColorAndMaterialType.METAL_YELLOW; + break; + } + break; } - - public void SetColor(ColorType type) + if (type == null) { - SetMaterialAndColor(materialType, type); + throw new System.Exception("missing combination for: " + colorType + ", " + materialType); } + this.colorType = colorType; + this.materialType = materialType; + GetComponent().material = ModificationSystem.get().getMaterial(type.Value).material; + } - private void SetMaterialAndColor(MaterialType materialType, ColorType colorType) + public void SetShape(ShapeType type) + { + if (shapeType == type) { - ColorAndMaterialType? type = null; - switch (materialType) - { - case MaterialType.ABSTRACT: - switch (colorType) - { - case ColorType.BLUE: - type = ColorAndMaterialType.ABSTRACT_BLUE; - break; - case ColorType.GREY: - type = ColorAndMaterialType.ABSTRACT_GREY; - break; - case ColorType.RED: - type = ColorAndMaterialType.ABSTRACT_RED; - break; - case ColorType.YELLOW: - type = ColorAndMaterialType.ABSTRACT_YELLOW; - break; - } - break; - case MaterialType.CHECKERED: - switch (colorType) - { - case ColorType.BLUE: - type = ColorAndMaterialType.CHECKERED_BLUE; - break; - case ColorType.GREY: - type = ColorAndMaterialType.CHECKERED_GREY; - break; - case ColorType.RED: - type = ColorAndMaterialType.CHECKERED_RED; - break; - case ColorType.YELLOW: - type = ColorAndMaterialType.CHECKERED_YELLOW; - break; - } - break; - case MaterialType.MATTE: - switch (colorType) - { - case ColorType.BLUE: - type = ColorAndMaterialType.MATTE_BLUE; - break; - case ColorType.GREY: - type = ColorAndMaterialType.MATTE_GREY; - break; - case ColorType.RED: - type = ColorAndMaterialType.MATTE_RED; - break; - case ColorType.YELLOW: - type = ColorAndMaterialType.MATTE_YELLOW; - break; - } - break; - case MaterialType.METAL: - switch (colorType) - { - case ColorType.BLUE: - type = ColorAndMaterialType.METAL_BLUE; - break; - case ColorType.GREY: - type = ColorAndMaterialType.METAL_GREY; - break; - case ColorType.RED: - type = ColorAndMaterialType.METAL_RED; - break; - case ColorType.YELLOW: - type = ColorAndMaterialType.METAL_YELLOW; - break; - } - break; - } - if (type == null) - { - throw new System.Exception("missing combination for: " + colorType + ", " + materialType); - } - this.colorType = colorType; - this.materialType = materialType; - GetComponent().material = ModificationSystem.get().getMaterial(type.Value).material; + return; } - - public void SetShape(ShapeType type) + bool cube = type == ShapeType.CUBE; + var faces = GetComponentsInChildren(); + foreach (var face in faces) { - if (shapeType == type) - { - return; - } - bool cube = type == ShapeType.CUBE; - var faces = GetComponentsInChildren(); - foreach (var face in faces) - { - face.GetComponent().enabled = cube; - } - isInteractable = !cube; - - var shape = ModificationSystem.get().getShape(type); - gameObject.GetComponent().mesh = shape.mesh; - gameObject.GetComponent().sharedMesh = shape.mesh; + face.GetComponent().enabled = cube; } + isInteractable = !cube; + + var shape = ModificationSystem.get().getShape(type); + gameObject.GetComponent().mesh = shape.mesh; + gameObject.GetComponent().sharedMesh = shape.mesh; + } - public void SetSize(SizeType type) + public void SetSize(SizeType type) + { + float scale; + switch (type) { - float scale; - switch (type) - { - case SizeType.NORMAL: - scale = 1; - break; - case SizeType.SMALL: - scale = 0.75f; - break; - case SizeType.XSMALL: - scale = 0.5f; - break; - case SizeType.BIG: - scale = 1.25f; - break; - case SizeType.XBIG: - scale = 1.5f; - break; - default: - throw new System.Exception("No functionality for SizeType: " + type); - } - transform.localScale = new Vector3(1, 1, 1) * scale; + case SizeType.NORMAL: + scale = 1; + break; + case SizeType.SMALL: + scale = 0.75f; + break; + case SizeType.XSMALL: + scale = 0.5f; + break; + case SizeType.BIG: + scale = 1.25f; + break; + case SizeType.XBIG: + scale = 1.5f; + break; + default: + throw new System.Exception("No functionality for SizeType: " + type); } + transform.localScale = new Vector3(1, 1, 1) * scale; + } - #region garbo + #region garbo - public void OnHold() - { + public void OnHold() + { - } + } - public void OnPickUp() - { - } + public void OnPickUp() + { + } - public void OnRelease() - { + public void OnRelease() + { - } - #endregion garbo + } + #endregion garbo - public MaterialType GetMaterialType() - { - return materialType; - } + public MaterialType GetMaterialType() + { + return materialType; + } - public ColorType GetColorType() - { - return colorType; - } + public ColorType GetColorType() + { + return colorType; + } - public ShapeType GetShapeType() - { - return shapeType; - } + public ShapeType GetShapeType() + { + return shapeType; + } - public Pickable asPickable() - { - return this; - } + public Pickable asPickable() + { + return this; } }