예제 #1
0
        protected static IEnumerator CopyAssets(List <ImportAsset> assetData, ImportType importType)
        {
            switch (importType)
            {
            case ImportType.Background:
                for (int i = 0; i < assetData.Count; i++)
                {
                    EditorCoroutineRunner.UpdateUI("Importing Background: " + assetData[i].targetName, i / (float)assetData.Count);
                    SpriteImporter.ImportSprite(assetData[i]);
                    yield return(null);
                }
                break;

            case ImportType.Object:
                for (int i = 0; i < assetData.Count; i++)
                {
                    EditorCoroutineRunner.UpdateUI("Importing Object: " + assetData[i].targetName, i / (float)assetData.Count);
                    ObjectImporter.ImportObject(assetData[i]);
                    yield return(null);
                }
                break;

            case ImportType.Room:
                for (int i = 0; i < assetData.Count; i++)
                {
                    EditorCoroutineRunner.UpdateUI("Importing Room: " + assetData[i].targetName, i / (float)assetData.Count);
                    RoomImporter.ImportRoom(assetData[i]);
                    yield return(null);
                }
                break;

            case ImportType.Sound:
                for (int i = 0; i < assetData.Count; i++)
                {
                    EditorCoroutineRunner.UpdateUI("Importing Sound: " + assetData[i].targetName, i / (float)assetData.Count);
                    CheckAndCopy(assetData[i]);
                    yield return(null);
                }
                break;

            case ImportType.Sprite:
                for (int i = 0; i < assetData.Count; i++)
                {
                    EditorCoroutineRunner.UpdateUI("Importing Sprite: " + assetData[i].targetName, i / (float)assetData.Count);
                    SpriteImporter.ImportSprite(assetData[i]);
                    yield return(null);
                }
                break;
            }
        }
예제 #2
0
    static IEnumerator DemoCoroutiune()
    {
        // You can code editor coroutines exactly like you would a normal unity coroutine
        Debug.Log("Step: 0");
        yield return(null);

        // all the normal return types that work with regular Unity coroutines should work here! for example lets wait for a second
        Debug.Log("Step: 1");
        yield return(new WaitForSeconds(1));

        // We can also yeild any type that extends Unitys CustomYieldInstruction class. here we are going to use EditorStatusUpdate. this allows us to yield and update the
        // editor coroutine UI at the same time!
        yield return(new EditorStatusUpdate("coroutine is running", 0.2f));

        // We can also yield to nested coroutines
        Debug.Log("Step: 2");

        yield return(EditorCoroutineRunner.StartCoroutine(DemoTwo()));

        EditorCoroutineRunner.UpdateUIProgressBar(0.35f); // we can use the UpdateUI helper methods to update the UI whenever, without yielding a EditorStatusUpdate
        yield return(DemoTwo());                          // it shouldnt matter how we start the nested coroutine, the editor runner can hadle it

        // we can even yield a WWW object if we want to grab data from the internets!
        Debug.Log("Step: 3");

        // for example, lets as random.org to generate us a list of random numbers and shove it into the console
        var www = new WWW("https://www.random.org/integers/?num=100&min=1&max=1000&col=1&base=10&col=5&format=plain&rnd=new");

        yield return(www);

        Debug.Log(www.text);

        EditorCoroutineRunner.UpdateUI("Half way!", 0.5f);
        yield return(new WaitForSeconds(1));

        // Finally lets do a long runnig task and split its updates over many frames to keep the editor responsive
        Debug.Log("Step: 4");
        var test = 1000;

        yield return(new WaitUntil(() => {
            test--;
            EditorCoroutineRunner.UpdateUI("Crunching Numbers: " + test, 0.5f + (((1000 - test) / 1000f) * 0.5f));
            return (test <= 0);
        }));

        Debug.Log("Done!!");
    }