Permalink
Browse files

archived from bitbucket

  • Loading branch information...
GandhiGames committed Oct 25, 2016
0 parents commit 3c20d5684ccc8785df96779c6467d985e7a237f9
Showing with 369 additions and 0 deletions.
  1. +9 −0 Assets/Scripts.meta
  2. +9 −0 Assets/Scripts/Core.meta
  3. +21 −0 Assets/Scripts/Core/IMessageEvent.cs
  4. +12 −0 Assets/Scripts/Core/IMessageEvent.cs.meta
  5. +22 −0 Assets/Scripts/Core/MessageEvent.cs
  6. +12 −0 Assets/Scripts/Core/MessageEvent.cs.meta
  7. +103 −0 Assets/Scripts/Core/MessageQueue.cs
  8. +12 −0 Assets/Scripts/Core/MessageQueue.cs.meta
  9. +9 −0 Assets/Scripts/Demo.meta
  10. +24 −0 Assets/Scripts/Demo/MessageQueueTest.cs
  11. +12 −0 Assets/Scripts/Demo/MessageQueueTest.cs.meta
  12. +9 −0 Assets/Scripts/Event System.meta
  13. +71 −0 Assets/Scripts/Event System/Events.cs
  14. +12 −0 Assets/Scripts/Event System/Events.cs.meta
  15. +10 −0 Assets/Scripts/Event System/GameEvent.cs
  16. +12 −0 Assets/Scripts/Event System/GameEvent.cs.meta
  17. BIN Assets/Test Scene.unity
  18. +8 −0 Assets/Test Scene.unity.meta
  19. BIN ProjectSettings/AudioManager.asset
  20. BIN ProjectSettings/ClusterInputManager.asset
  21. BIN ProjectSettings/DynamicsManager.asset
  22. BIN ProjectSettings/EditorBuildSettings.asset
  23. BIN ProjectSettings/EditorSettings.asset
  24. BIN ProjectSettings/GraphicsSettings.asset
  25. BIN ProjectSettings/InputManager.asset
  26. BIN ProjectSettings/NavMeshAreas.asset
  27. BIN ProjectSettings/NetworkManager.asset
  28. BIN ProjectSettings/Physics2DSettings.asset
  29. BIN ProjectSettings/ProjectSettings.asset
  30. +2 −0 ProjectSettings/ProjectVersion.txt
  31. BIN ProjectSettings/QualitySettings.asset
  32. BIN ProjectSettings/TagManager.asset
  33. BIN ProjectSettings/TimeManager.asset
  34. BIN ProjectSettings/UnityAdsSettings.asset
  35. BIN ProjectSettings/UnityConnectSettings.asset

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,21 @@
using UnityEngine;
using System;
using System.Collections;
namespace GameFoundations
{
public enum MessagePriority
{
Low,
Medium,
High
}
public interface IMessageEvent
{
DateTime timeRaised { get; }
float displayTime { get; }
MessagePriority priority { get; }
object message { get; }
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,22 @@
using UnityEngine;
using System;
using System.Collections;
namespace GameFoundations
{
public class MessageEvent : GameEvent, IMessageEvent
{
public DateTime timeRaised { private set; get; }
public MessagePriority priority { private set; get; }
public float displayTime { private set; get; }
public object message { private set; get; }
public MessageEvent (object message, float displayTime, MessagePriority priority)
{
this.message = message;
this.displayTime = displayTime;
this.priority = priority;
timeRaised = DateTime.Now;
}
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,103 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
namespace GameFoundations
{
public class MessageQueue : MonoBehaviour
{
public bool logToConsole = false;
public bool prependDateTime = false;
[Header ("Message Colours")]
public Color
highPriorityColour = Color.red;
public Color normalPriorityColour = Color.black;
public Color lowPriorityColour = Color.white;
[Header ("Message Font Style")]
public FontStyle
highPriorityStyle = FontStyle.Bold;
public FontStyle normalPriorityStyle = FontStyle.Normal;
public FontStyle lowPriorityStyle = FontStyle.Normal;
[Header ("Message Location")]
public Vector2
queueLocation = new Vector2 (25, 25);
public Vector2 messageSize = new Vector2 (200, 15);
private static readonly GUIStyle LOW_PRIORTY = new GUIStyle (), NORMAL_PRIORITY = new GUIStyle (), HIGH_PRIORITY = new GUIStyle ();
private List<IMessageEvent> _pending = new List<IMessageEvent> ();
void OnEnable ()
{
if (_pending.Count > 0) {
_pending.Clear ();
}
LOW_PRIORTY.normal.textColor = lowPriorityColour;
LOW_PRIORTY.fontStyle = lowPriorityStyle;
NORMAL_PRIORITY.normal.textColor = normalPriorityColour;
NORMAL_PRIORITY.fontStyle = normalPriorityStyle;
HIGH_PRIORITY.normal.textColor = highPriorityColour;
HIGH_PRIORITY.fontStyle = highPriorityStyle;
Events.instance.AddListener<MessageEvent> (OnMessage);
}
void OnDisable ()
{
Events.instance.RemoveListener<MessageEvent> (OnMessage);
}
void Update ()
{
for (int i = _pending.Count - 1; i>=0; i--) {
if (Time.time > _pending [i].displayTime)
_pending.RemoveAt (i);
}
}
void OnMessage (IMessageEvent e)
{
_pending.Add (e);
if (logToConsole) {
Debug.Log ("Message Recieved [" + System.DateTime.Now + "]: " + e.message.ToString ());
}
}
void OnGUI ()
{
float yPos = queueLocation.y;
foreach (var m in _pending) {
GUIStyle style = GetMessageStyle (m);
string message = (prependDateTime) ? "[" + m.timeRaised + "]: " + m.message.ToString () : m.message.ToString ();
GUI.Label (new Rect (queueLocation.x, yPos, messageSize.x, messageSize.y), message, style);
yPos += messageSize.y;
}
}
GUIStyle GetMessageStyle (IMessageEvent e)
{
switch (e.priority) {
case MessagePriority.Low:
return LOW_PRIORTY;
case MessagePriority.Medium:
return NORMAL_PRIORITY;
default:
return HIGH_PRIORITY;
}
}
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;
using GameFoundations;
public class MessageQueueTest : MonoBehaviour
{
private int count = 1;
void Update ()
{
if (Input.GetMouseButtonDown (0)) {
MessagePriority priorty = MessagePriority.High;
float random = Random.value;
if (random < 0.333f) {
priorty = MessagePriority.Low;
} else if (random < 0.666f) {
priorty = MessagePriority.Medium;
}
Events.instance.Raise (new MessageEvent ("Test Message " + count++, Time.time + 3f, priorty));
}
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,71 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace GameFoundations
{
public class Events
{
private static Events _instance;
public static Events instance {
get {
if (_instance == null) {
_instance = new Events ();
}
return _instance;
}
}
public delegate void EventDelegate<T> (T e) where T: GameEvent;
private delegate void EventDelegate (GameEvent e);
private Dictionary<System.Type, EventDelegate> delegates = new Dictionary<System.Type, EventDelegate> ();
private Dictionary<System.Delegate, EventDelegate> delegateLookup = new Dictionary<System.Delegate, EventDelegate> ();
public void AddListener<T> (EventDelegate<T> del) where T : GameEvent
{
EventDelegate internalDelegate = (e) => del ((T)e);
if (delegateLookup.ContainsKey (del) && delegateLookup [del] == internalDelegate) {
return;
}
delegateLookup [del] = internalDelegate;
EventDelegate tempDel;
if (delegates.TryGetValue (typeof(T), out tempDel)) {
delegates [typeof(T)] = tempDel += internalDelegate;
} else {
delegates [typeof(T)] = internalDelegate;
}
}
public void RemoveListener<T> (EventDelegate<T> del) where T : GameEvent
{
EventDelegate internalDelegate;
if (delegateLookup.TryGetValue (del, out internalDelegate)) {
EventDelegate tempDel;
if (delegates.TryGetValue (typeof(T), out tempDel)) {
tempDel -= internalDelegate;
if (tempDel == null) {
delegates.Remove (typeof(T));
} else {
delegates [typeof(T)] = tempDel;
}
}
delegateLookup.Remove (del);
}
}
public void Raise (GameEvent e)
{
EventDelegate del;
if (delegates.TryGetValue (e.GetType (), out del)) {
del.Invoke (e);
}
}
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,10 @@
using UnityEngine;
using System.Collections;
namespace GameFoundations
{
public abstract class GameEvent
{
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Binary file not shown.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
m_EditorVersion: 5.4.1f1
m_StandardAssetsVersion: 0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 3c20d56

Please sign in to comment.