Skip to content

Commit

Permalink
Merge pull request #37 from kefniark/feature/cleanup
Browse files Browse the repository at this point in the history
Feature/cleanup
  • Loading branch information
nullorvoid committed Jun 9, 2016
2 parents ca70c17 + 04e635a commit 941accb
Show file tree
Hide file tree
Showing 75 changed files with 4,564 additions and 3,691 deletions.
6 changes: 6 additions & 0 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Runtime.InteropServices;

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
80 changes: 0 additions & 80 deletions Async/Async.cs

This file was deleted.

9 changes: 9 additions & 0 deletions EditorScript/EditorPlayModeState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Wizcorp.MageSDK.Editor
{
public enum EditorPlayModeState
{
Stopped,
Playing,
Paused
}
}
75 changes: 75 additions & 0 deletions EditorScript/UnityEditorPlayMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#if UNITY_EDITOR

using UnityEditor;

namespace Wizcorp.MageSDK.Editor
{
[InitializeOnLoad]
public static class UnityEditorPlayMode
{
public delegate void EditorModeChanged(EditorPlayModeState newState);

private static EditorPlayModeState currentState = EditorPlayModeState.Stopped;
public static EditorModeChanged OnEditorModeChanged;

static UnityEditorPlayMode()
{
EditorApplication.playmodeStateChanged += OnUnityPlayModeChanged;
if (EditorApplication.isPaused)
{
currentState = EditorPlayModeState.Paused;
}
}

private static void OnUnityPlayModeChanged()
{
var newState = EditorPlayModeState.Stopped;
switch (currentState)
{
case EditorPlayModeState.Stopped:
if (EditorApplication.isPlayingOrWillChangePlaymode)
{
newState = EditorPlayModeState.Playing;
}
else
{
newState = EditorPlayModeState.Paused;
}
break;
case EditorPlayModeState.Playing:
if (EditorApplication.isPaused)
{
newState = EditorPlayModeState.Paused;
}
else if (EditorApplication.isPlaying)
{
newState = EditorPlayModeState.Playing;
}
else
{
newState = EditorPlayModeState.Stopped;
}
break;
case EditorPlayModeState.Paused:
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPaused)
{
newState = EditorPlayModeState.Playing;
}
else if (EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPaused)
{
newState = EditorPlayModeState.Paused;
}
break;
}

if (OnEditorModeChanged != null)
{
OnEditorModeChanged.Invoke(newState);
}

currentState = newState;
}
}
}

#endif
71 changes: 71 additions & 0 deletions Event/EventEmitter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace Wizcorp.MageSDK.Event
{
public class EventEmitter<T>
{
private EventHandlerList eventsList = new EventHandlerList();

//
private Dictionary<string, object> eventTags = new Dictionary<string, object>();

//
public void On(string eventTag, Action<object, T> handler)
{
if (!eventTags.ContainsKey(eventTag))
{
eventTags.Add(eventTag, new object());
}

eventsList.AddHandler(eventTags[eventTag], handler);
}

//
public void Once(string eventTag, Action<object, T> handler)
{
Action<object, T> handlerWrapper = null;
handlerWrapper = (obj, arguments) => {
eventsList.RemoveHandler(eventTags[eventTag], handlerWrapper);
handler(obj, arguments);
};

On(eventTag, handlerWrapper);
}

//
public void Emit(string eventTag, object sender, T arguments)
{
if (!eventTags.ContainsKey(eventTag))
{
return;
}

var execEventList = (Action<object, T>)eventsList[eventTags[eventTag]];
execEventList(sender, arguments);
}

public void Emit(string eventTag, T arguments)
{
Emit(eventTag, null, arguments);
}

//
public void Off(string eventTag, Action<object, T> handler)
{
eventsList.RemoveHandler(eventTags[eventTag], handler);
}

//
public void RemoveAllListeners()
{
// Destroy all event handlers
eventsList.Dispose();
eventsList = new EventHandlerList();

// Destroy all event tags
eventTags = new Dictionary<string, object>();
}
}
}
64 changes: 0 additions & 64 deletions EventEmitter/EventEmitter.cs

This file was deleted.

Loading

0 comments on commit 941accb

Please sign in to comment.