예제 #1
0
        public void InvokeLaterAndNameTest()
        {
            var myEvent = new Event();
            var counter = 0;
            var cr      = CoroutineHandler.InvokeLater(new Wait(myEvent), () => {
                counter++;
            }, "Bird");

            CoroutineHandler.InvokeLater(new Wait(myEvent), () => {
                counter++;
            });

            CoroutineHandler.InvokeLater(new Wait(myEvent), () => {
                counter++;
            });

            Assert.AreEqual(0, counter, "Incorrect counter value after 5 seconds.");
            CoroutineHandler.Tick(1);
            CoroutineHandler.RaiseEvent(myEvent);
            Assert.AreEqual(3, counter, "Incorrect counter value after 10 seconds.");
            Assert.AreEqual(true, cr.IsFinished, "Incorrect IsFinished value.");
            Assert.AreEqual(false, cr.WasCanceled, "Incorrect IsCanceled value.");
            Assert.AreEqual(cr.MoveNextCount, 2, "Incorrect MoveNextCount value.");
            Assert.AreEqual(cr.Name, "Bird", "Incorrect name of the coroutine.");
        }
예제 #2
0
        public static void Main()
        {
            var seconds = CoroutineHandler.Start(WaitSeconds(), "Awesome Waiting Coroutine");

            CoroutineHandler.Start(PrintEvery10Seconds(seconds));

            CoroutineHandler.Start(EmptyCoroutine());

            CoroutineHandler.InvokeLater(new Wait(5), () => {
                Console.WriteLine("Raising test event");
                CoroutineHandler.RaiseEvent(TestEvent);
            });
            CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("Example event received"));

            CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("I am invoked after 'Example event received'"), priority: -5);
            CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("I am invoked before 'Example event received'"), priority: 2);

            var lastTime = DateTime.Now;

            while (true)
            {
                var currTime = DateTime.Now;
                CoroutineHandler.Tick(currTime - lastTime);
                lastTime = currTime;
                Thread.Sleep(1);
            }
        }
        private static IEnumerator <Wait> SubmitRenderLogic()
        {
            while (true)
            {
                yield return(new Wait(Overlay.OnRender));

                if (NativeMethods.IsKeyPressed(0x7B)) //F12.
                {
                    showClickableMenu = !showClickableMenu;
                }

                if (showImGuiDemo)
                {
                    ImGui.ShowDemoWindow(ref showImGuiDemo);
                }

                if (showOverlaySample1)
                {
                    ImGui.SetNextWindowPos(new Vector2(0f, 0f));
                    ImGui.SetNextWindowBgAlpha(0.9f);
                    ImGui.Begin(
                        "Sample Overlay",
                        ImGuiWindowFlags.NoInputs |
                        ImGuiWindowFlags.NoCollapse |
                        ImGuiWindowFlags.NoTitleBar |
                        ImGuiWindowFlags.AlwaysAutoResize |
                        ImGuiWindowFlags.NoResize);

                    ImGui.Text("I am sample Overlay");
                    ImGui.Text("You can not click me");
                    ImGui.Text("I am here just to display stuff");
                    ImGui.Text($"Current Date: {DateTime.Now.Date}");
                    ImGui.Text($"Current Time: {DateTime.Now.TimeOfDay}");
                    ImGui.End();
                }

                if (showOverlaySample2)
                {
                    ImGui.SetNextWindowContentSize(ImGui.GetIO().DisplaySize);
                    ImGui.SetNextWindowPos(new Vector2(0, 0));
                    ImGui.Begin(
                        "Background Screen",
                        ref showOverlaySample2,
                        ImGuiWindowFlags.NoInputs |
                        ImGuiWindowFlags.NoBackground |
                        ImGuiWindowFlags.NoBringToFrontOnFocus |
                        ImGuiWindowFlags.NoCollapse |
                        ImGuiWindowFlags.NoMove |
                        ImGuiWindowFlags.NoScrollbar |
                        ImGuiWindowFlags.NoSavedSettings |
                        ImGuiWindowFlags.NoResize |
                        ImGuiWindowFlags.NoTitleBar);
                    var windowPtr = ImGui.GetWindowDrawList();
                    for (int i = 0; i < circleCenters.Length; i++)
                    {
                        windowPtr.AddCircleFilled(circleCenters[i], 10.0f, (uint)(((255 << 24) | (00 << 16) | (00 << 8) | 255) & 0xffffffffL));
                    }
                    ImGui.End();
                }

                if (showClickableMenu)
                {
                    bool isRunning = true;
                    if (!ImGui.Begin("Overlay Main Menu", ref isRunning, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.AlwaysAutoResize))
                    {
                        Overlay.Close = !isRunning;
                        ImGui.End();
                        continue;
                    }

                    Overlay.Close = !isRunning;
                    ImGui.Text("Try pressing F12 button to show/hide this menu.");
                    ImGui.Text("Click X on top right of this menu to close the overlay.");
                    ImGui.Checkbox("Show non-clickable transparent overlay Sample 1.", ref showOverlaySample1);
                    ImGui.Checkbox("Show full-screen non-clickable transparent overlay sample 2.", ref showOverlaySample2);
                    ImGui.NewLine();

                    ImGui.SliderInt2("Set Position", ref resizeHelper[0], 0, 3840);
                    ImGui.SliderInt2("Set Size", ref resizeHelper[2], 0, 3840);
                    if (ImGui.Button("Resize"))
                    {
                        Overlay.Position = new Veldrid.Point(resizeHelper[0], resizeHelper[1]);
                        Overlay.Size     = new Veldrid.Point(resizeHelper[2], resizeHelper[3]);
                    }

                    ImGui.NewLine();
                    ImGui.SliderInt("###time(sec)", ref seconds, 1, 30);
                    if (ImGui.Button($"Hide for {seconds} seconds"))
                    {
                        Overlay.Visible = false;
                        // Time Based Coroutines are executed even when the Overlay is invisible.
                        // So in case there is a reason you want to hide the overlay, u can use timebased
                        // coroutines to bring it back.
                        CoroutineHandler.InvokeLater(new Wait(seconds), () => { Overlay.Visible = true; });
                    }

                    ImGui.NewLine();
                    if (ImGui.Button("Toggle ImGui Demo"))
                    {
                        showImGuiDemo = !showImGuiDemo;
                    }

                    if (ImGui.Button("Toggle Terminal"))
                    {
                        Overlay.TerminalWindow = !Overlay.TerminalWindow;
                    }

                    ImGui.NewLine();
                    if (File.Exists("image.png"))
                    {
                        ImGui.Image(Overlay.AddOrGetImagePointer("image.png"), new Vector2(256, 256));
                    }
                    else
                    {
                        ImGui.Text("Put any image where the exe is, name is 'image.png'");
                    }

                    ImGui.End();
                }

                ImGui.End();
            }
        }