Skip to content

Instantly share code, notes, and snippets.

@tm8r
Created April 25, 2016 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tm8r/499b67669f94d3aa625e60e7da3d43c7 to your computer and use it in GitHub Desktop.
Save tm8r/499b67669f94d3aa625e60e7da3d43c7 to your computer and use it in GitHub Desktop.
CoroutineEditorWindow
using UnityEngine;
using UnityEditor;
using System.Collections;
using UniRx;
public class CoroutineWindow : EditorWindow
{
static float deltaTime;
static bool isCompleted;
[MenuItem ("Tools/CoroutineTest")]
static void Open ()
{
GetWindow<CoroutineWindow> ();
}
static void OpenFromCUI ()
{
Observable.FromCoroutine (Update).Subscribe (_ => {
Debug.Log ("complete:" + deltaTime);
EditorApplication.Exit (0);
});
}
void OnEnable ()
{
Debug.Log ("init");
Observable.FromCoroutine (Update).Subscribe (_ => isCompleted = true);
}
void OnDestroy ()
{
Debug.Log ("end");
deltaTime = 0f;
isCompleted = false;
}
void OnGUI ()
{
GUILayout.Label ("deltaTime:" + deltaTime);
if (isCompleted) {
GUILayout.Label ("completed!");
}
}
static IEnumerator Update ()
{
while (30f > deltaTime) {
deltaTime += Time.fixedDeltaTime;
yield return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment