Browse Source

Move TaskManager to Fungus namespace

master
chrisgregan 9 years ago
parent
commit
581f9ce171
  1. 2
      Assets/Fungus/FungusScript/Resources/Types/RegisterTypes.txt
  2. 312
      Assets/Fungus/FungusScript/Thirdparty/TaskManager/TaskManager.cs

2
Assets/Fungus/FungusScript/Resources/Types/RegisterTypes.txt

@ -21,6 +21,7 @@ Fungus.PortraitState, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicK
Fungus.SayDialog, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Fungus.SayDialog, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Fungus.SpriteVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Fungus.SpriteVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Fungus.StringVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Fungus.StringVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Fungus.Task, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Fungus.TextureVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Fungus.TextureVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Fungus.TransformVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Fungus.TransformVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Fungus.Variable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Fungus.Variable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
@ -34,7 +35,6 @@ System.IntPtr, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c
System.Single, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Single, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Task, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
UnityEngine.AudioClip, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null UnityEngine.AudioClip, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
UnityEngine.AudioClipLoadType, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null UnityEngine.AudioClipLoadType, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
UnityEngine.AudioDataLoadState, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null UnityEngine.AudioDataLoadState, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

312
Assets/Fungus/FungusScript/Thirdparty/TaskManager/TaskManager.cs vendored

@ -56,159 +56,165 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
/// A Task object represents a coroutine. Tasks can be started, paused, and stopped. // Using the Fungus namespace to minimize conflicts with other assets.
/// It is an error to attempt to start a task that has been stopped or which has namespace Fungus
/// naturally terminated.
public class Task
{ {
/// Returns true if and only if the coroutine is running. Paused tasks
/// are considered to be running.
public bool Running {
get {
return task.Running;
}
}
/// Returns true if and only if the coroutine is currently paused.
public bool Paused {
get {
return task.Paused;
}
}
/// Delegate for termination subscribers. manual is true if and only if
/// the coroutine was stopped with an explicit call to Stop().
public delegate void FinishedHandler(bool manual);
/// Termination event. Triggered when the coroutine completes execution.
public event FinishedHandler Finished;
/// Creates a new Task object for the given coroutine.
///
/// If autoStart is true (default) the task is automatically started
/// upon construction.
public Task(IEnumerator c, bool autoStart = true)
{
task = TaskManager.CreateTask(c);
task.Finished += TaskFinished;
if(autoStart)
Start();
}
/// Begins execution of the coroutine
public void Start()
{
task.Start();
}
/// Discontinues execution of the coroutine at its next yield.
public void Stop()
{
task.Stop();
}
public void Pause()
{
task.Pause();
}
public void Unpause()
{
task.Unpause();
}
void TaskFinished(bool manual)
{
FinishedHandler handler = Finished;
if(handler != null)
handler(manual);
}
TaskManager.TaskState task;
}
class TaskManager : MonoBehaviour /// A Task object represents a coroutine. Tasks can be started, paused, and stopped.
{ /// It is an error to attempt to start a task that has been stopped or which has
public class TaskState /// naturally terminated.
{ public class Task
public bool Running { {
get { /// Returns true if and only if the coroutine is running. Paused tasks
return running; /// are considered to be running.
} public bool Running {
} get {
return task.Running;
public bool Paused { }
get { }
return paused;
} /// Returns true if and only if the coroutine is currently paused.
} public bool Paused {
get {
public delegate void FinishedHandler(bool manual); return task.Paused;
public event FinishedHandler Finished; }
}
IEnumerator coroutine;
bool running; /// Delegate for termination subscribers. manual is true if and only if
bool paused; /// the coroutine was stopped with an explicit call to Stop().
bool stopped; public delegate void FinishedHandler(bool manual);
public TaskState(IEnumerator c) /// Termination event. Triggered when the coroutine completes execution.
{ public event FinishedHandler Finished;
coroutine = c;
} /// Creates a new Task object for the given coroutine.
///
public void Pause() /// If autoStart is true (default) the task is automatically started
{ /// upon construction.
paused = true; public Task(IEnumerator c, bool autoStart = true)
} {
task = TaskManager.CreateTask(c);
public void Unpause() task.Finished += TaskFinished;
{ if(autoStart)
paused = false; Start();
} }
public void Start() /// Begins execution of the coroutine
{ public void Start()
running = true; {
singleton.StartCoroutine(CallWrapper()); task.Start();
} }
public void Stop() /// Discontinues execution of the coroutine at its next yield.
{ public void Stop()
stopped = true; {
running = false; task.Stop();
} }
IEnumerator CallWrapper() public void Pause()
{ {
yield return null; task.Pause();
IEnumerator e = coroutine; }
while(running) {
if(paused) public void Unpause()
yield return null; {
else { task.Unpause();
if(e != null && e.MoveNext()) { }
yield return e.Current;
} void TaskFinished(bool manual)
else { {
running = false; FinishedHandler handler = Finished;
} if(handler != null)
} handler(manual);
} }
FinishedHandler handler = Finished; TaskManager.TaskState task;
if(handler != null) }
handler(stopped);
} class TaskManager : MonoBehaviour
} {
public class TaskState
static TaskManager singleton; {
public bool Running {
public static TaskState CreateTask(IEnumerator coroutine) get {
{ return running;
if(singleton == null) { }
GameObject go = new GameObject("TaskManager"); }
singleton = go.AddComponent<TaskManager>();
} public bool Paused {
return new TaskState(coroutine); get {
} return paused;
}
}
public delegate void FinishedHandler(bool manual);
public event FinishedHandler Finished;
IEnumerator coroutine;
bool running;
bool paused;
bool stopped;
public TaskState(IEnumerator c)
{
coroutine = c;
}
public void Pause()
{
paused = true;
}
public void Unpause()
{
paused = false;
}
public void Start()
{
running = true;
singleton.StartCoroutine(CallWrapper());
}
public void Stop()
{
stopped = true;
running = false;
}
IEnumerator CallWrapper()
{
yield return null;
IEnumerator e = coroutine;
while(running) {
if(paused)
yield return null;
else {
if(e != null && e.MoveNext()) {
yield return e.Current;
}
else {
running = false;
}
}
}
FinishedHandler handler = Finished;
if(handler != null)
handler(stopped);
}
}
static TaskManager singleton;
public static TaskState CreateTask(IEnumerator coroutine)
{
if(singleton == null) {
GameObject go = new GameObject("TaskManager");
singleton = go.AddComponent<TaskManager>();
}
return new TaskState(coroutine);
}
}
} }
Loading…
Cancel
Save