-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from kefniark/feature/cleanup
Feature/cleanup
- Loading branch information
Showing
75 changed files
with
4,564 additions
and
3,691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Wizcorp.MageSDK.Editor | ||
{ | ||
public enum EditorPlayModeState | ||
{ | ||
Stopped, | ||
Playing, | ||
Paused | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.