Main Menu
Added Main Menu scene Tweaked world map to incorporate secondary colors in zone icons + glowing links Entity Serialization is now generic Zone Serialization now includes entities Fixed bug where wormhole traversal would unbind from player entity Game Manager no longer spawns entities (loadout file format changed) Wrote extension to randomly select weighted items from collections (for generating enemies)
This commit is contained in:
parent
1aef932162
commit
e6181c11dc
53 changed files with 3763 additions and 49169 deletions
|
|
@ -34,164 +34,169 @@ namespace UniRx
|
|||
|
||||
public static CullingMode cullingMode = CullingMode.Self;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
// In UnityEditor's EditorMode can't instantiate and work MonoBehaviour.Update.
|
||||
// EditorThreadDispatcher use EditorApplication.update instead of MonoBehaviour.Update.
|
||||
class EditorThreadDispatcher
|
||||
{
|
||||
static object gate = new object();
|
||||
static EditorThreadDispatcher instance;
|
||||
|
||||
public static EditorThreadDispatcher Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
// Activate EditorThreadDispatcher is dangerous, completely Lazy.
|
||||
lock (gate)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new EditorThreadDispatcher();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ThreadSafeQueueWorker editorQueueWorker = new ThreadSafeQueueWorker();
|
||||
|
||||
EditorThreadDispatcher()
|
||||
{
|
||||
UnityEditor.EditorApplication.update += Update;
|
||||
}
|
||||
|
||||
public void Enqueue(Action<object> action, object state)
|
||||
{
|
||||
editorQueueWorker.Enqueue(action, state);
|
||||
}
|
||||
|
||||
public void UnsafeInvoke(Action action)
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnsafeInvoke<T>(Action<T> action, T state)
|
||||
{
|
||||
try
|
||||
{
|
||||
action(state);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void PseudoStartCoroutine(IEnumerator routine)
|
||||
{
|
||||
editorQueueWorker.Enqueue(_ => ConsumeEnumerator(routine), null);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
editorQueueWorker.ExecuteAll(x => Debug.LogException(x));
|
||||
}
|
||||
|
||||
void ConsumeEnumerator(IEnumerator routine)
|
||||
{
|
||||
if (routine.MoveNext())
|
||||
{
|
||||
var current = routine.Current;
|
||||
if (current == null)
|
||||
{
|
||||
goto ENQUEUE;
|
||||
}
|
||||
|
||||
var type = current.GetType();
|
||||
if (type == typeof(AsyncOperation))
|
||||
{
|
||||
var asyncOperation = (AsyncOperation)current;
|
||||
editorQueueWorker.Enqueue(_ => ConsumeEnumerator(UnwrapWaitAsyncOperation(asyncOperation, routine)), null);
|
||||
return;
|
||||
}
|
||||
else if (type == typeof(WaitForSeconds))
|
||||
{
|
||||
var waitForSeconds = (WaitForSeconds)current;
|
||||
var accessor = typeof(WaitForSeconds).GetField("m_Seconds", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);
|
||||
var second = (float)accessor.GetValue(waitForSeconds);
|
||||
editorQueueWorker.Enqueue(_ => ConsumeEnumerator(UnwrapWaitForSeconds(second, routine)), null);
|
||||
return;
|
||||
}
|
||||
else if (type == typeof(Coroutine))
|
||||
{
|
||||
Debug.Log("Can't wait coroutine on UnityEditor");
|
||||
goto ENQUEUE;
|
||||
}
|
||||
#if SupportCustomYieldInstruction
|
||||
else if (current is IEnumerator)
|
||||
{
|
||||
var enumerator = (IEnumerator)current;
|
||||
editorQueueWorker.Enqueue(_ => ConsumeEnumerator(UnwrapEnumerator(enumerator, routine)), null);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
ENQUEUE:
|
||||
editorQueueWorker.Enqueue(_ => ConsumeEnumerator(routine), null); // next update
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator UnwrapWaitAsyncOperation(AsyncOperation asyncOperation, IEnumerator continuation)
|
||||
{
|
||||
while (!asyncOperation.isDone)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
ConsumeEnumerator(continuation);
|
||||
}
|
||||
|
||||
IEnumerator UnwrapWaitForSeconds(float second, IEnumerator continuation)
|
||||
{
|
||||
var startTime = DateTimeOffset.UtcNow;
|
||||
while (true)
|
||||
{
|
||||
yield return null;
|
||||
|
||||
var elapsed = (DateTimeOffset.UtcNow - startTime).TotalSeconds;
|
||||
if (elapsed >= second)
|
||||
{
|
||||
break;
|
||||
}
|
||||
};
|
||||
ConsumeEnumerator(continuation);
|
||||
}
|
||||
|
||||
IEnumerator UnwrapEnumerator(IEnumerator enumerator, IEnumerator continuation)
|
||||
{
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
ConsumeEnumerator(continuation);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
// #if UNITY_EDITOR
|
||||
//
|
||||
// // In UnityEditor's EditorMode can't instantiate and work MonoBehaviour.Update.
|
||||
// // EditorThreadDispatcher use EditorApplication.update instead of MonoBehaviour.Update.
|
||||
// class EditorThreadDispatcher
|
||||
// {
|
||||
// static object gate = new object();
|
||||
// static EditorThreadDispatcher instance;
|
||||
//
|
||||
// public static EditorThreadDispatcher Instance
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// // Activate EditorThreadDispatcher is dangerous, completely Lazy.
|
||||
// lock (gate)
|
||||
// {
|
||||
// if (instance == null)
|
||||
// {
|
||||
// instance = new EditorThreadDispatcher();
|
||||
// }
|
||||
//
|
||||
// return instance;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ThreadSafeQueueWorker editorQueueWorker = new ThreadSafeQueueWorker();
|
||||
//
|
||||
// EditorThreadDispatcher()
|
||||
// {
|
||||
// UnityEditor.EditorApplication.update += Update;
|
||||
// }
|
||||
//
|
||||
// public void Enqueue(Action<object> action, object state)
|
||||
// {
|
||||
// editorQueueWorker.Enqueue(action, state);
|
||||
// }
|
||||
//
|
||||
// public void UnsafeInvoke(Action action)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// action();
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Debug.LogException(ex);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void UnsafeInvoke<T>(Action<T> action, T state)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// action(state);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Debug.LogException(ex);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void PseudoStartCoroutine(IEnumerator routine)
|
||||
// {
|
||||
// editorQueueWorker.Enqueue(_ => ConsumeEnumerator(routine), null);
|
||||
// }
|
||||
//
|
||||
// void Update()
|
||||
// {
|
||||
// editorQueueWorker.ExecuteAll(x => Debug.LogException(x));
|
||||
// }
|
||||
//
|
||||
// void ConsumeEnumerator(IEnumerator routine)
|
||||
// {
|
||||
// if (routine.MoveNext())
|
||||
// {
|
||||
// var current = routine.Current;
|
||||
// if (current == null)
|
||||
// {
|
||||
// goto ENQUEUE;
|
||||
// }
|
||||
//
|
||||
// var type = current.GetType();
|
||||
// if (type == typeof(AsyncOperation))
|
||||
// {
|
||||
// var asyncOperation = (AsyncOperation)current;
|
||||
// editorQueueWorker.Enqueue(_ => ConsumeEnumerator(UnwrapWaitAsyncOperation(asyncOperation, routine)), null);
|
||||
// return;
|
||||
// }
|
||||
// else if (type == typeof(WaitForSeconds))
|
||||
// {
|
||||
// var waitForSeconds = (WaitForSeconds)current;
|
||||
// var accessor = typeof(WaitForSeconds).GetField("m_Seconds", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);
|
||||
// var second = (float)accessor.GetValue(waitForSeconds);
|
||||
// editorQueueWorker.Enqueue(_ => ConsumeEnumerator(UnwrapWaitForSeconds(second, routine)), null);
|
||||
// return;
|
||||
// }
|
||||
// else if (type == typeof(Coroutine))
|
||||
// {
|
||||
// Debug.Log("Can't wait coroutine on UnityEditor");
|
||||
// goto ENQUEUE;
|
||||
// }
|
||||
// #if SupportCustomYieldInstruction
|
||||
// else if (current is IEnumerator)
|
||||
// {
|
||||
// var enumerator = (IEnumerator)current;
|
||||
// editorQueueWorker.Enqueue(_ => ConsumeEnumerator(UnwrapEnumerator(enumerator, routine)), null);
|
||||
// return;
|
||||
// }
|
||||
// #endif
|
||||
//
|
||||
// ENQUEUE:
|
||||
// editorQueueWorker.Enqueue(_ => ConsumeEnumerator(routine), null); // next update
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// IEnumerator UnwrapWaitAsyncOperation(AsyncOperation asyncOperation, IEnumerator continuation)
|
||||
// {
|
||||
// while (!asyncOperation.isDone)
|
||||
// {
|
||||
// yield return null;
|
||||
// }
|
||||
// ConsumeEnumerator(continuation);
|
||||
// }
|
||||
//
|
||||
// IEnumerator UnwrapWaitForSeconds(float second, IEnumerator continuation)
|
||||
// {
|
||||
// var startTime = DateTimeOffset.UtcNow;
|
||||
// while (true)
|
||||
// {
|
||||
// yield return null;
|
||||
//
|
||||
// var elapsed = (DateTimeOffset.UtcNow - startTime).TotalSeconds;
|
||||
// if (elapsed >= second)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// };
|
||||
// ConsumeEnumerator(continuation);
|
||||
// }
|
||||
//
|
||||
// IEnumerator UnwrapEnumerator(IEnumerator enumerator, IEnumerator continuation)
|
||||
// {
|
||||
// while (enumerator.MoveNext())
|
||||
// {
|
||||
// yield return null;
|
||||
// }
|
||||
// ConsumeEnumerator(continuation);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #endif
|
||||
|
||||
/// <summary>Dispatch Asyncrhonous action.</summary>
|
||||
public static void Post(Action<object> action, object state)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!ScenePlaybackDetector.IsPlaying) { EditorThreadDispatcher.Instance.Enqueue(action, state); return; }
|
||||
if (!ScenePlaybackDetector.IsPlaying)
|
||||
{
|
||||
throw new InvalidOperationException("No main thread dispatcher in Edit Mode!");
|
||||
//EditorThreadDispatcher.Instance.Enqueue(action, state);
|
||||
//return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -206,7 +211,12 @@ namespace UniRx
|
|||
public static void Send(Action<object> action, object state)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!ScenePlaybackDetector.IsPlaying) { EditorThreadDispatcher.Instance.Enqueue(action, state); return; }
|
||||
if (!ScenePlaybackDetector.IsPlaying)
|
||||
{
|
||||
throw new InvalidOperationException("No main thread dispatcher in Edit Mode!");
|
||||
// EditorThreadDispatcher.Instance.Enqueue(action, state);
|
||||
// return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mainThreadToken != null)
|
||||
|
|
@ -234,7 +244,12 @@ namespace UniRx
|
|||
public static void UnsafeSend(Action action)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!ScenePlaybackDetector.IsPlaying) { EditorThreadDispatcher.Instance.UnsafeInvoke(action); return; }
|
||||
if (!ScenePlaybackDetector.IsPlaying)
|
||||
{
|
||||
throw new InvalidOperationException("No main thread dispatcher in Edit Mode!");
|
||||
// EditorThreadDispatcher.Instance.UnsafeInvoke(action);
|
||||
// return;
|
||||
}
|
||||
#endif
|
||||
|
||||
try
|
||||
|
|
@ -255,7 +270,12 @@ namespace UniRx
|
|||
public static void UnsafeSend<T>(Action<T> action, T state)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!ScenePlaybackDetector.IsPlaying) { EditorThreadDispatcher.Instance.UnsafeInvoke(action, state); return; }
|
||||
if (!ScenePlaybackDetector.IsPlaying)
|
||||
{
|
||||
throw new InvalidOperationException("No main thread dispatcher in Edit Mode!");
|
||||
// EditorThreadDispatcher.Instance.UnsafeInvoke(action, state);
|
||||
// return;
|
||||
}
|
||||
#endif
|
||||
|
||||
try
|
||||
|
|
@ -283,7 +303,12 @@ namespace UniRx
|
|||
{
|
||||
#if UNITY_EDITOR
|
||||
// call from other thread
|
||||
if (!ScenePlaybackDetector.IsPlaying) { EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine); return; }
|
||||
if (!ScenePlaybackDetector.IsPlaying)
|
||||
{
|
||||
throw new InvalidOperationException("No main thread dispatcher in Edit Mode!");
|
||||
// EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine);
|
||||
// return;
|
||||
}
|
||||
#endif
|
||||
|
||||
var dispatcher = Instance;
|
||||
|
|
@ -304,7 +329,12 @@ namespace UniRx
|
|||
public static void StartUpdateMicroCoroutine(IEnumerator routine)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!ScenePlaybackDetector.IsPlaying) { EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine); return; }
|
||||
if (!ScenePlaybackDetector.IsPlaying)
|
||||
{
|
||||
throw new InvalidOperationException("No main thread dispatcher in Edit Mode!");
|
||||
// EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine);
|
||||
// return;
|
||||
}
|
||||
#endif
|
||||
|
||||
var dispatcher = Instance;
|
||||
|
|
@ -317,7 +347,12 @@ namespace UniRx
|
|||
public static void StartFixedUpdateMicroCoroutine(IEnumerator routine)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!ScenePlaybackDetector.IsPlaying) { EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine); return; }
|
||||
if (!ScenePlaybackDetector.IsPlaying)
|
||||
{
|
||||
throw new InvalidOperationException("No main thread dispatcher in Edit Mode!");
|
||||
// EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine);
|
||||
// return;
|
||||
}
|
||||
#endif
|
||||
|
||||
var dispatcher = Instance;
|
||||
|
|
@ -330,7 +365,11 @@ namespace UniRx
|
|||
public static void StartEndOfFrameMicroCoroutine(IEnumerator routine)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!ScenePlaybackDetector.IsPlaying) { EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine); return; }
|
||||
if (!ScenePlaybackDetector.IsPlaying)
|
||||
{
|
||||
// EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine);
|
||||
// return;
|
||||
}
|
||||
#endif
|
||||
|
||||
var dispatcher = Instance;
|
||||
|
|
@ -343,7 +382,12 @@ namespace UniRx
|
|||
new public static Coroutine StartCoroutine(IEnumerator routine)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!ScenePlaybackDetector.IsPlaying) { EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine); return null; }
|
||||
if (!ScenePlaybackDetector.IsPlaying)
|
||||
{
|
||||
throw new InvalidOperationException("No main thread dispatcher in Edit Mode!");
|
||||
// EditorThreadDispatcher.Instance.PseudoStartCoroutine(routine);
|
||||
// return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
var dispatcher = Instance;
|
||||
|
|
|
|||
Loading…
Reference in a new issue