Exemplo n.º 1
0
        public void SimpleExecute()
        {
            var ce = new CoroutineExecutor();

            ce.Start(FrameworkCoroutines.Simple(3));

            Run(ce);
        }
        public void DelaySecondsWithSerialization()
        {
            var t = new CoroutineTestClass(_output);

            var exc = new CoroutineExecutor();

            var thread = exc.Start(t.DelaySeconds(1));

            Assert.True(thread.Status == CoroutineThreadStatus.Yielded);

            exc.Tick(TimeSpan.FromSeconds(0.55));

            Assert.True(thread.Status == CoroutineThreadStatus.Yielded);

            exc.Tick(TimeSpan.FromSeconds(0.55));

            Assert.True(thread.Status == CoroutineThreadStatus.Yielded);

            var serializer = new JsonSerializer();
            serializer.Converters.Add(new CoroutineConverter(true, false));

            var settings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented,
                Converters = new JsonConverter[] { new CoroutineConverter(true, false), new NameValueDictionaryConverter() },
                TypeNameHandling = TypeNameHandling.Auto
            };

            string resultString = JsonConvert.SerializeObject(exc, settings);

            //var dcss = new DataContractSerializerSettings {PreserveObjectReferences = true};
            //var dcs = new DataContractSerializer(typeof(CoroutineExecutor), dcss);
            //var ms = new MemoryStream();
            //dcs.WriteObject(ms, exc);

            //var dat = ms.ToArray();
            //var mss = Encoding.UTF8.GetString(dat, 0, dat.Length);

            exc.Tick(TimeSpan.FromSeconds(0.55));

            Assert.True(thread.Status == CoroutineThreadStatus.Finished);


            var desexc = JsonConvert.DeserializeObject<CoroutineExecutor>(resultString, settings);
        }
Exemplo n.º 3
0
        private static void Run(CoroutineExecutor ce)
        {
            Stopwatch sw = Stopwatch.StartNew();

            TimeSpan previousTime = TimeSpan.Zero;

            TimeSpan elapsed;
            do
            {
                checked
                {
                    TimeSpan newTime = sw.Elapsed;

                    elapsed = newTime - previousTime;

                    previousTime = newTime;
                }
            } while (ce.Tick(elapsed));
        }
        public void DelaySecondsNoSerialization()
        {
            var t = new CoroutineTestClass(_output);

            var exc = new CoroutineExecutor();

            var thread = exc.Start(t.DelaySeconds(1));

            Assert.True(thread.Status == CoroutineThreadStatus.Yielded);

            exc.Tick(TimeSpan.FromSeconds(0.55));

            Assert.True(thread.Status == CoroutineThreadStatus.Yielded);

            exc.Tick(TimeSpan.FromSeconds(0.55));

            Assert.True(thread.Status == CoroutineThreadStatus.Yielded);

            exc.Tick(TimeSpan.FromSeconds(0.55));

            Assert.True(thread.Status == CoroutineThreadStatus.Finished);
        }
Exemplo n.º 5
0
        /// <summary>
        ///   异步加载场景
        /// </summary>
        public static bool LoadSceneAsync(out SceneLoadRequest req
                                          , string scene_name
                                          , System.Action <string> callback = null
                                          , LoadSceneMode mode = LoadSceneMode.Single)
        {
            req = null;

#if UNITY_EDITOR
            if (LoadPattern.SceneLoadPattern == emLoadPattern.EditorAsset ||
                LoadPattern.SceneLoadPattern == emLoadPattern.All)
            {
                if (!Application.CanStreamedLevelBeLoaded(scene_name))
                {
                    return(false);
                }

                var ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(scene_name, mode);
                if (ao != null)
                {
                    req = new SceneLoadRequest(ao);
                    CoroutineExecutor.Create(req, () =>
                    {
                        if (callback != null)
                        {
                            callback(scene_name);
                        }
                    });
                    return(true);
                }
            }
#endif

            if (LoadPattern.SceneLoadPattern == emLoadPattern.AssetBundle ||
                LoadPattern.SceneLoadPattern == emLoadPattern.All)
            {
                req = AssetBundleManager.Instance.LoadSceneAsync(scene_name, mode);
                if (req != null)
                {
                    CoroutineExecutor.Create(req, () =>
                    {
                        GenerateSceneObject(scene_name);
                        if (callback != null)
                        {
                            callback(scene_name);
                        }
                    });
                    return(true);
                }
            }
            if (LoadPattern.SceneLoadPattern == emLoadPattern.Original ||
                LoadPattern.SceneLoadPattern == emLoadPattern.All)
            {
                if (!Application.CanStreamedLevelBeLoaded(scene_name))
                {
                    return(false);
                }

                var ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(scene_name, mode);
                if (ao != null)
                {
                    req = new SceneLoadRequest(ao);
                    CoroutineExecutor.Create(req, () =>
                    {
                        if (callback != null)
                        {
                            callback(scene_name);
                        }
                    });
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
    private void OnGUI()
    {
        if (test == null)
        {
            return;
        }

        float ox = 10, oy = 10, dx = 160, dy = 60;
        Rect  uiPos = new Rect(ox, oy, 150, 40);

        if (this.doCoroutine == null)
        {
            if (GUI.Button(uiPos, "RotationZ"))
            {
                this.doCoroutine = CoroutineExecutor.Do(test.RotateZTest(270.0f, 2.0f));
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "MoveAndRotate"))
            {
                this.doCoroutine = CoroutineExecutor.Do(test.MoveAndRotateTest(new Vector3(1.5f, 0.8f, 0), 90.0f, 1.5f));
            }

            uiPos.x  = ox;
            uiPos.y += dy;

            if (GUI.Button(uiPos, "Group Coroutine"))
            {
                var group = new GroupCoroutine(test.RotateZTest(270.0f, 2.0f));

                group.Add(test.MoveTest(new Vector3(1.5f, 0.8f, 0), 3.0f));

                this.doCoroutine = CoroutineExecutor.Do(group);
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Order Coroutine"))
            {
                var order = new OrderCoroutine(test.RotateZTest(270.0f, 2.0f));

                order.Add(test.MoveTest(new Vector3(1.5f, 0.8f, 0), 3.0f));

                this.doCoroutine = CoroutineExecutor.Do(order);
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Manual Coroutine"))
            {
                // If you use manual coroutine, be caureful of not useing yield return new WaitForEndOfFrame().
                this.manualCoroutine = new NewCoroutine(test.RotateZTest(270.0f, 5.0f));
                this.doCoroutine     = this.manualCoroutine;
            }

            uiPos.x  = ox;
            uiPos.y += dy;

            if (GUI.Button(uiPos, "Complex Coroutine"))
            {
                var order = new OrderCoroutine(test.MoveTest(new Vector3(-1.5f, -0.8f, -3.0f), 1.0f));

                var group = new GroupCoroutine(new IEnumerator[] {
                    test.RotateZTest(270.0f, 2.0f),
                    test.MoveTest(new Vector3(1.5f, 0.8f, 3.0f), 3.0f)
                });

                order.Add(group);

                this.doCoroutine = CoroutineExecutor.Do(order);
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Coroutine with Owner"))
            {
                if (this.owner == null)
                {
                    Debug.LogError("You need to set owner first.");
                    return;
                }

                var order = new OrderCoroutine(this.owner.MoveTest(new Vector3(-1.5f, -0.8f, -3.0f), 1.0f, transform), this.owner);

                var group = new GroupCoroutine(new IEnumerator[] {
                    this.owner.RotateZTest(270.0f, 2.0f, transform),
                    this.owner.MoveTest(new Vector3(1.5f, 0.8f, 3.0f), 3.0f, transform)
                });

                order.Add(group);

                this.doCoroutine = CoroutineExecutor.Do(order);
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Event Coroutine"))
            {
                if (this.owner == null)
                {
                    Debug.LogError("You need to set owner first.");
                    return;
                }

                var group = new GroupCoroutine(new IEnumerator[] {
                    this.owner.WaitEventTest(null),
                    this.owner.SendEventAfterSeconds("ABC", 2.0f)
                });

                this.doCoroutine = CoroutineExecutor.Do(group);
            }

            uiPos.x  = ox;
            uiPos.y += dy;

            if (GUI.Button(uiPos, "Reset Position"))
            {
                transform.position = originalPosition;
            }
        }
        else
        {
            if (this.doCoroutine.Pause)
            {
                if (GUI.Button(uiPos, "Resume"))
                {
                    this.doCoroutine.Pause = false;
                }
            }
            else
            {
                if (GUI.Button(uiPos, "Pause"))
                {
                    this.doCoroutine.Pause = true;
                }
            }

            if (this.doCoroutine.Owner != null)
            {
                uiPos.x += dx;

                if (this.doCoroutine.Owner.enabled)
                {
                    if (GUI.Button(uiPos, "Disable Owner"))
                    {
                        this.doCoroutine.Owner.enabled = false;
                    }
                }
                else
                {
                    if (GUI.Button(uiPos, "Enable Owner"))
                    {
                        this.doCoroutine.Owner.enabled = true;
                    }
                }

                uiPos.x += dx;

                if (GUI.Button(uiPos, "Kill Owner"))
                {
                    Destroy(this.doCoroutine.Owner);
                }
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Cancel"))
            {
                this.doCoroutine.Cancel();
            }
        }
    }
Exemplo n.º 7
0
        public ExitMenu(ScreenManager screenManager, Renderer parent) : base(screenManager, parent)
        {
            // Parent is scenario screen
            background = GUIElement.CreateContainer(screenContainer.renderer, new Vector3(0f, 0f, -1f), new Vector2(19.2f, 10.8f), "SimpleTransitionForMenu");
            {
                CoroutineExecutor.Add(Routine());

                IEnumerator Routine()
                {
                    var ticket1 = GPUTextureLoader.LoadAsync("Images/GUI/ec_exit_bg_1.png");
                    var ticket2 = GPUTextureLoader.LoadAsync("Images/GUI/ec_exit_bg_2.png");

                    while (ticket1.texture == null || ticket2.texture == null)
                    {
                        yield return(null);
                    }

                    background.material.SetTexture("Tex1", ticket1.texture);
                    background.material.SetTexture("Tex2", ticket2.texture);

                    while (true)
                    {
                        foreach (var i in CoroutineExecutor.ForTime(5f))
                        {
                            yield return(null);
                        }

                        foreach (var i in CoroutineExecutor.ForTime(0.5f))
                        {
                            background.material.SetFloat("CrossFade", i);
                            yield return(null);
                        }

                        foreach (var i in CoroutineExecutor.ForTime(0.5f))
                        {
                            background.material.SetFloat("CrossFade", 1f - i);
                            yield return(null);
                        }
                    }
                }
            }

            var label = GUIElement.CreateEmpty(screenContainer.renderer, new Vector3(-2.3f, 0f, -2f), new Vector2(10f, 1.08f));

            label.renderer.name = "Label";

            {
                var textBox = label.Entity.CreateComponent <TextBox>(name);
                textBox.InitFromRenderer();
                textBox.CharHeight = 0.4f;
                textBox.FontName   = "Furore";
                textBox.Text       = "Ты правда хочешь сбежать?";
            }

            buttonYes = GUIElement.CreateContainer(screenContainer.renderer, new Vector3(-5.2f, -1f, -2f), new Vector2(1.2f, 0.56f), "Game/Color");
            {
                buttonYes.renderer.name = "Yes";
                ODEngine.Helpers.GUIHelper.TextButton(buttonYes, new Vector3(0f, 0.02f, 0f), "Furore", 0.45f, "Да", new Color4(160, 185, 198, 255), Color4.White);
                buttonYes.MouseClick += ButtonYes_MouseClick;
            }

            buttonNo = GUIElement.CreateContainer(screenContainer.renderer, new Vector3(-2.35f, -1f, -2f), new Vector2(1.2f, 0.56f), "Game/Color");
            {
                buttonNo.renderer.name = "No";
                ODEngine.Helpers.GUIHelper.TextButton(buttonNo, new Vector3(0f, 0.02f, 0f), "Furore", 0.45f, "Нет", new Color4(160, 185, 198, 255), Color4.White);
                buttonNo.MouseClick += ButtonNo_MouseClick;
            }

            screenContainer.renderer.isVisible = false;
        }
Exemplo n.º 8
0
        public MainMenu(ScreenManagerVN screenManager, Renderer parent) : base(screenManager, parent)
        {
            screenContainer.name          = "MainMenu screenContainer";
            screenContainer.renderer.name = "MainMenu screenContainer Renderer";
            screenContainer.material.SetFloat("alpha", 0f);

            var backBack   = GUIElement.CreateImage(screenContainer.renderer, Vector3.Zero, parentRenderer.size, "GUI/MainMenu/BackBack");
            var character1 = GUIElement.CreateImage(screenContainer.renderer, Vector3.Zero, parentRenderer.size, "GUI/MainMenu/Character1");

            buttonsContainer = GUIElement.CreateContainer(screenContainer.renderer, new Vector3(0f, -4.85f, -1f), new Vector2(19.2f, 0.88f), "Game/Alpha");
            deskImage        = GUIElement.CreateImage(buttonsContainer.renderer, Vector3.Zero, new Vector2(19.2f, 0.88f), "GUI/MainMenu/Buttons/desk");
            buttonsContainer.renderer.isVisible = false;
            buttonsContainer.material.SetFloat("alpha", 0f);

            var rays = GUIElement.CreateImage(screenContainer.renderer, Vector3.Zero, parentRenderer.size, "GUI/MainMenu/PostAber", new Material(null, "Game/Alpha"));

            { // Лучи
                IEnumerator AlphaAnimation()
                {
                    while (true)
                    {
                        rays.material.SetFloat("alpha", 0f);
                        yield return(null);

                        for (float i = 0f; i < 7f; i += Kernel.deltaTimeUpdate)
                        {
                            yield return(null);
                        }
                        for (float i = 0f; i < 1f; i += Kernel.deltaTimeUpdate / 2f)
                        {
                            rays.material.SetFloat("alpha", i * i * i * i);
                            yield return(null);
                        }
                        for (float i = 0f; i < MathF.PI * 2; i += Kernel.deltaTimeUpdate * MathF.PI)
                        {
                            rays.material.SetFloat("alpha", (MathF.Cos(i) / 2f + 0.5f) * 0.3f + 0.7f);
                            yield return(null);
                        }
                        for (float i = 0f; i < 1f; i += Kernel.deltaTimeUpdate / 2f)
                        {
                            rays.material.SetFloat("alpha", 1f - i * i * i * i);
                            yield return(null);
                        }
                    }
                }

                var animation = AlphaAnimation();
                CoroutineExecutor.Add(animation);
            }

            buttonStart = GUIElement.CreateEmpty(screenContainer.renderer, new Vector3(-5.69f, -1.73f, -1f), new Vector2(5.64f, 5.29f) * 0.73f);
            { // Кнопка начала игры
                buttonStart.renderer.name = "Start game";
                ODEngine.Helpers.GUIHelper.ImageButton(buttonStart,
                                                       "Images/GUI/MainMenu/BookGo_idle.png",
                                                       "Images/GUI/MainMenu/BookGo_hover.png");

                var imageTicket = ImageLoader.LoadRaw("Images/GUI/MainMenu/BookGo_idle.png", (ticket) =>
                {
                    buttonStart.CreateMask(ticket.rawImage).Wait();
                    ticket.Unload();
                });

                buttonStart.threshold = 0.5f;

                buttonStart.MouseClick += ButtonStart_MouseClick;
            }

            // Надпись "Глубина Холода"
            var labelDOC = GUIElement.CreateFrameAnimation(screenContainer.renderer, new Vector3(-4.64f, 3.46f, -1f), new Vector2(8.67f, 3.54f),
                                                           ("GUI/MainMenu/Title", ColorMatrix.Identity, 10f),
                                                           ("GUI/MainMenu/Title_G1", ColorMatrix.Identity, 0.04f),
                                                           ("GUI/MainMenu/Title_G2", ColorMatrix.Identity, 0.04f),
                                                           ("GUI/MainMenu/Title_G3", ColorMatrix.Identity, 0.04f),
                                                           ("GUI/MainMenu/Title_G4", ColorMatrix.Identity, 0.04f),
                                                           ("GUI/MainMenu/Title", ColorMatrix.Identity, 8f),
                                                           ("GUI/MainMenu/Title_G1", ColorMatrix.Identity, 0.05f),
                                                           ("GUI/MainMenu/Title", ColorMatrix.Identity, 10f),
                                                           ("GUI/MainMenu/Title_G1", ColorMatrix.Identity, 0.03f),
                                                           ("GUI/MainMenu/Title_G2", ColorMatrix.Identity, 0.03f));

            buttonMenu = GUIElement.CreateEmpty(screenContainer.renderer, new Vector3(9.23f, -4.87f, -2f), new Vector2(0.74f, 0.88f));
            {
                buttonMenu.renderer.name = "Menu";

                var imageFile1 = "Images/GUI/MainMenu/Buttons/Triangle_idle.png";
                var texTicket1 = GPUTextureLoader.LoadAsync(imageFile1);
                var imageFile2 = "Images/GUI/MainMenu/Buttons/Triangle_hover.png";
                var texTicket2 = GPUTextureLoader.LoadAsync(imageFile2);
                var imageFile3 = "Images/GUI/MainMenu/Buttons/TriangleBack_idle.png";
                var texTicket3 = GPUTextureLoader.LoadAsync(imageFile3);
                var imageFile4 = "Images/GUI/MainMenu/Buttons/TriangleBack_hover.png";
                var texTicket4 = GPUTextureLoader.LoadAsync(imageFile4);

                buttonMenu.renderer.onRender = (input, output) =>
                {
                    if (!menuIsVisible)
                    {
                        if (!buttonMenu.mouseOnElement)
                        {
                            if (texTicket1 != null)
                            {
                                Graphics.Blit(texTicket1.texture, output);
                            }
                        }
                        else
                        {
                            if (texTicket2 != null)
                            {
                                Graphics.Blit(texTicket2.texture, output);
                            }
                        }
                    }
                    else
                    {
                        if (!buttonMenu.mouseOnElement)
                        {
                            if (texTicket1 != null)
                            {
                                Graphics.Blit(texTicket3.texture, output);
                            }
                        }
                        else
                        {
                            if (texTicket2 != null)
                            {
                                Graphics.Blit(texTicket4.texture, output);
                            }
                        }
                    }
                };

                buttonMenu.isLoaded = () => texTicket1.isLoaded && texTicket2.isLoaded && texTicket3.isLoaded && texTicket4.isLoaded;

                buttonMenu.MouseClick += ButtonMenu_MouseClick;
            }

            buttonExit = GUIElement.CreateContainer(buttonsContainer.renderer, new Vector3(6.75f, 0f, -1f), new Vector2(1.95f, 0.56f), "Game/Color");
            { // Кнопка выхода
                buttonExit.renderer.name = "Exit";
                ODEngine.Helpers.GUIHelper.TextButton(buttonExit, new Vector3(0f, 0.02f, 0f), "Furore", 0.45f, "Выход", new Color4(160, 185, 198, 255), Color4.White);
                buttonExit.MouseClick += ButtonExit_MouseClick;
            }

            buttonSettings = GUIElement.CreateContainer(buttonsContainer.renderer, new Vector3(3.88f, 0f, -1f), new Vector2(3.02f, 0.56f), "Game/Color");
            { // Кнопка "Настройки"
                buttonSettings.renderer.name = "Settings";
                ODEngine.Helpers.GUIHelper.TextButton(buttonSettings, new Vector3(0f, 0.02f, 0f), "Furore", 0.45f, "Настройки", new Color4(160, 185, 198, 255), Color4.White);
                buttonSettings.MouseClick += ButtonSettings_MouseClick;
            }

            buttonLoad = GUIElement.CreateContainer(buttonsContainer.renderer, new Vector3(0.5f, 0f, -1f), new Vector2(3.02f, 0.56f), "Game/Color");
            { // Кнопка "Загрузить"
                buttonLoad.renderer.name = "Load";
                ODEngine.Helpers.GUIHelper.TextButton(buttonLoad, new Vector3(0f, 0.02f, 0f), "Furore", 0.45f, "Загрузить", new Color4(160, 185, 198, 255), Color4.White);
                buttonLoad.MouseClick += ButtonLoad_MouseClick;
            }

            buttonFragment = GUIElement.CreateContainer(buttonsContainer.renderer, new Vector3(-2.65f, 0f, -1f), new Vector2(3.02f, 0.56f), "Game/Color");
            { // Кнопка "Фрагмент"
                buttonFragment.renderer.name = "Fragment";
                ODEngine.Helpers.GUIHelper.TextButton(buttonFragment, new Vector3(0f, 0.02f, 0f), "Furore", 0.45f, "Фрагмент", new Color4(160, 185, 198, 255), Color4.White);
                buttonFragment.MouseClick += ButtonFragment_MouseClick;
            }

            isLoaded = () => backBack.IsLoaded && character1.IsLoaded && deskImage.IsLoaded && rays.IsLoaded &&
                       buttonStart.IsLoaded && labelDOC.IsLoaded && buttonSettings.IsLoaded && buttonExit.IsLoaded && buttonMenu.IsLoaded;
        }
Exemplo n.º 9
0
 private void OnDestroy()
 {
     instance = null;
 }
Exemplo n.º 10
0
 private void OnApplicationQuit()
 {
     instance = null;
 }