Skip to content

Commit

Permalink
signs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamReifsneider committed Jul 12, 2020
1 parent 1f6e10f commit 82a47cf
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 18 deletions.
19 changes: 10 additions & 9 deletions BOX-BUX/Assets/Scripts/DeliveryZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class DeliveryZone : MonoBehaviour
{
[Serializable]
public class Order
{
public ColorType colorGoal;
public MaterialType materialGoal;
public ShapeType shapeGoal;
public SizeType sizeGoal;
}
public static EventTriggerable onDelivered;
public static EventOrder onNewOrder;

public List<Order> orders;
private Order currentOrder;
private bool wonPrinted = false;
private HudText score;
private void Awake()
{
onDelivered = new EventTriggerable();
onNewOrder = new EventOrder();
}

private void Start()
{
Expand All @@ -33,6 +33,7 @@ private void Update()
{
currentOrder = orders[0];
orders.RemoveAt(0);
onNewOrder.Invoke(currentOrder);
Debug.Log("GOAL: " + currentOrder.materialGoal + ", " + currentOrder.colorGoal + ", " + currentOrder.shapeGoal + ", " + currentOrder.sizeGoal);
}
else if (!wonPrinted)
Expand Down Expand Up @@ -66,7 +67,7 @@ public void OnTriggerEnter(Collider other)
private void Deliver(Pickable box)
{
Debug.Log("GIANT ENEMY GOAL GOT");
score.OnDelivered(box);
onDelivered.Invoke(box);
Destroy(box.gameObject);
currentOrder = null;
}
Expand Down
12 changes: 8 additions & 4 deletions BOX-BUX/Assets/Scripts/GlobalState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ public static GlobalState get()
return FindObjectOfType<GlobalState>();
}

public void OnSpawned(Pickable pickable)
private void OnSpawned(Pickable pickable)
{
spawned.Add(pickable);
}

public void Trash(Pickable toTrash)
private void Start()
{
if (!spawned.Remove(toTrash))
Trasher.onTrashed.AddListener(Trash);
}

private void Trash(Triggerable toTrash)
{
if (!spawned.Remove(toTrash.asPickable()))
{
throw new System.Exception("Failed to trash: " + toTrash);
}
Destroy(toTrash.gameObject);
}
}
1 change: 1 addition & 0 deletions BOX-BUX/Assets/Scripts/HudText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class HudText : MonoBehaviour

private void Start()
{
DeliveryZone.onDelivered.AddListener(OnDelivered);
var texts = GetComponentsInChildren<Text>();
timerText = texts.Single(t => t.name == "Timer");
scoreText = texts.Single(t => t.name == "Score");
Expand Down
82 changes: 82 additions & 0 deletions BOX-BUX/Assets/Scripts/Signs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;

public class Signs : MonoBehaviour
{
[Serializable]
public class SizePair
{
public SizeType type;
public Sprite sprite;
}

[Serializable]
public class ColorPair
{
public ColorType type;
public Sprite sprite;
}

[Serializable]
public class ShapePair
{
public ShapeType type;
public Sprite sprite;
}


[Serializable]
public class MaterialPair
{
public MaterialType type;
public Sprite sprite;
}

public ColorPair[] colorPairing;
public MaterialPair[] materialPairing;
public ShapePair[] shapePairing;
public SizePair[] sizePairing;

private GameObject color;
private GameObject material;
private GameObject shape;
private GameObject size;

private void Start()
{
DeliveryZone.onNewOrder.AddListener(OnNewOrder);

foreach (Transform child in transform)
{
var obj = child.gameObject;
switch (obj.name)
{
case "Sign_Color":
color = child.gameObject;
break;
case "Sign_Material":
material = child.gameObject;
break;
case "Sign_Shape":
shape = child.gameObject;
break;
case "Sign_Size":
size = child.gameObject;
break;
}
}
}

public void OnNewOrder(Order order)
{
color.GetComponent<SpriteRenderer>().sprite = colorPairing.Single(cp => cp.type == order.colorGoal).sprite;
material.GetComponent<SpriteRenderer>().sprite = materialPairing.Single(cp => cp.type == order.materialGoal).sprite;
shape.GetComponent<SpriteRenderer>().sprite = shapePairing.Single(cp => cp.type == order.shapeGoal).sprite;
size.GetComponent<SpriteRenderer>().sprite = sizePairing.Single(cp => cp.type == order.sizeGoal).sprite;
}
}
11 changes: 11 additions & 0 deletions BOX-BUX/Assets/Scripts/Signs.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions BOX-BUX/Assets/Scripts/Spawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public class Spawner : InteractableBase
{
public Pickable box;
public Vector3 spawnPosition;
public GlobalState state;
public float secondsCooldown = 1.0f;
public static EventTriggerable onSpawned;
private GlobalState state;
private float countdown;

public SizeType defaultSize = SizeType.NORMAL;
Expand All @@ -24,9 +25,10 @@ public class Spawner : InteractableBase
public bool randomMaterial;
public bool randomShape;

private void Start()
private void Awake()
{
state = FindObjectOfType<GlobalState>();
onSpawned = new EventTriggerable();
}

private void Update()
Expand All @@ -46,7 +48,7 @@ public override void OnInteract()

countdown = secondsCooldown;
var created = Instantiate(box);
state.OnSpawned(created);
onSpawned.Invoke(created);

if (randomSize)
{
Expand Down
6 changes: 4 additions & 2 deletions BOX-BUX/Assets/Scripts/Trasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

public class Trasher : MonoBehaviour
{
public static EventTriggerable onTrashed;
public ParticleSystem particle;
public GlobalState state;

private void Start()
{
state = FindObjectOfType<GlobalState>();
onTrashed = new EventTriggerable();
}

private void OnTriggerStay(Collider other)
Expand All @@ -30,7 +31,8 @@ private void OnTriggerStay(Collider other)
var p = Instantiate(particle);
p.transform.position = pick.transform.position;
p.Play();
state.Trash(pick);
onTrashed.Invoke(pick);
Destroy(pick.gameObject);
}
}
}
14 changes: 14 additions & 0 deletions BOX-BUX/Assets/Scripts/_Data Structures/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

[Serializable]
public class Order
{
public ColorType colorGoal;
public MaterialType materialGoal;
public ShapeType shapeGoal;
public SizeType sizeGoal;
}
11 changes: 11 additions & 0 deletions BOX-BUX/Assets/Scripts/_Data Structures/Order.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions BOX-BUX/Assets/Scripts/_Events.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions BOX-BUX/Assets/Scripts/_Events/EventOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.Events;

public class EventOrder : UnityEvent<Order>
{
}
11 changes: 11 additions & 0 deletions BOX-BUX/Assets/Scripts/_Events/EventOrder.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions BOX-BUX/Assets/Scripts/_Events/EventTriggerable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.Events;

public class EventTriggerable : UnityEvent<Triggerable>
{
}
11 changes: 11 additions & 0 deletions BOX-BUX/Assets/Scripts/_Events/EventTriggerable.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 82a47cf

Please sign in to comment.