Skip to content

Commit

Permalink
archived from bitbucket
Browse files Browse the repository at this point in the history
  • Loading branch information
GandhiGames committed Oct 25, 2016
0 parents commit 3c20d56
Show file tree
Hide file tree
Showing 35 changed files with 369 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Assets/Scripts.meta

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

9 changes: 9 additions & 0 deletions Assets/Scripts/Core.meta

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

21 changes: 21 additions & 0 deletions Assets/Scripts/Core/IMessageEvent.cs
@@ -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; }
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/Core/IMessageEvent.cs.meta

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

22 changes: 22 additions & 0 deletions Assets/Scripts/Core/MessageEvent.cs
@@ -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;
}
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/Core/MessageEvent.cs.meta

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

103 changes: 103 additions & 0 deletions Assets/Scripts/Core/MessageQueue.cs
@@ -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;
}

}
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/Core/MessageQueue.cs.meta

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

9 changes: 9 additions & 0 deletions Assets/Scripts/Demo.meta

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

24 changes: 24 additions & 0 deletions Assets/Scripts/Demo/MessageQueueTest.cs
@@ -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));
}
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/Demo/MessageQueueTest.cs.meta

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

9 changes: 9 additions & 0 deletions Assets/Scripts/Event System.meta

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

71 changes: 71 additions & 0 deletions Assets/Scripts/Event System/Events.cs
@@ -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);
}
}

}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/Event System/Events.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 Assets/Scripts/Event System/GameEvent.cs
@@ -0,0 +1,10 @@
using UnityEngine;
using System.Collections;

namespace GameFoundations
{
public abstract class GameEvent
{

}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/Event System/GameEvent.cs.meta

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

Binary file added Assets/Test Scene.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Test Scene.unity.meta

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

Binary file added ProjectSettings/AudioManager.asset
Binary file not shown.
Binary file added ProjectSettings/ClusterInputManager.asset
Binary file not shown.
Binary file added ProjectSettings/DynamicsManager.asset
Binary file not shown.
Binary file added ProjectSettings/EditorBuildSettings.asset
Binary file not shown.
Binary file added ProjectSettings/EditorSettings.asset
Binary file not shown.
Binary file added ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file added ProjectSettings/InputManager.asset
Binary file not shown.
Binary file added ProjectSettings/NavMeshAreas.asset
Binary file not shown.
Binary file added ProjectSettings/NetworkManager.asset
Binary file not shown.
Binary file added ProjectSettings/Physics2DSettings.asset
Binary file not shown.
Binary file added ProjectSettings/ProjectSettings.asset
Binary file not shown.
2 changes: 2 additions & 0 deletions ProjectSettings/ProjectVersion.txt
@@ -0,0 +1,2 @@
m_EditorVersion: 5.4.1f1
m_StandardAssetsVersion: 0
Binary file added ProjectSettings/QualitySettings.asset
Binary file not shown.
Binary file added ProjectSettings/TagManager.asset
Binary file not shown.
Binary file added ProjectSettings/TimeManager.asset
Binary file not shown.
Binary file added ProjectSettings/UnityAdsSettings.asset
Binary file not shown.
Binary file added ProjectSettings/UnityConnectSettings.asset
Binary file not shown.

0 comments on commit 3c20d56

Please sign in to comment.