Created
April 25, 2016 12:25
-
-
Save tm8r/499b67669f94d3aa625e60e7da3d43c7 to your computer and use it in GitHub Desktop.
CoroutineEditorWindow
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
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