Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Message stream #39

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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