Exemplo n.º 1
0
    public IEnumerator FindOne()
    {
        yield return(new WaitForSecondsRealtime(2));



        // By id
        Assert.IsTrue(REbase.Find("#CanvasSuperior").Length == 1);
        Assert.IsTrue(REbase.FindOne("#CanvasSuperior") != null);



        // By id
        Assert.IsTrue(REbase.Find("#ImagenSuperior").Length == 1);
        Assert.IsTrue(REbase.FindOne("#ImagenSuperior") != null);



        // By id
        Assert.IsTrue(REbase.Find("#PanelBack").Length == 1);
        Assert.IsTrue(REbase.FindOne("#PanelBack") != null);



        yield return(new WaitForSecondsRealtime(2));
    }
    public IEnumerator Hooks_GenerateChildWithUseState()
    {
        var listState = new UseState <List <string> >(new List <string>());

        // A Component
        REcanvas MainReactorComponent()
        {
            return(new REcanvas
            {
                propsId = () => new REcanvas.IdSetter
                {
                    id = "MainCanvas",
                },
                useState = new IuseState[]
                {
                    listState,
                },
                childs = () => listState.value.Select(c =>
                                                      new REtext
                {
                    propsId = () => new REtext.IdSetter
                    {
                        id = c + "Num",
                    },
                    propsText = () => new REtext.TextSetter
                    {
                        text = c,
                    }
                }
                                                      ),
            });
        }

        var routerProve = MainReactorComponent();

        yield return(new WaitForSecondsRealtime(1));

        // Draw the component
        Debug.Log("Drawing");
        routerProve.Draw();

        // First check
        Debug.Log("Childs: " + REbase.FindOne("#MainCanvas").childs.Length);
        Assert.IsTrue(REbase.FindOne("#MainCanvas").childs.Length == 0);



        // Simulate the fetch
        yield return(new WaitForSecondsRealtime(1));

        var fetchData = new List <string>
        {
            "Six",
            "Seven",
            "Eight",
            "Nine",
        };



        // Draw again the component
        Debug.Log("UseState: " + listState.value.Count());
        listState.SetState(fetchData);

        // Check
        Debug.Log("Childs: " + REbase.FindOne("#MainCanvas").childs.Length);
        Assert.IsTrue(REbase.FindOne("#MainCanvas").childs.Length == 4);

        Debug.Log("Childs");
        foreach (var word in listState.value)
        {
            //Debug.Log("Child: " + "#" + word + "Num" + " == " + word);
            //Debug.Log("Child: " + ReactorElement.Find<REtext.Selector>("#" + word + "Num")[0].textCmp.text + " == " + word);
            Assert.IsTrue(REtext.FindOne("#" + word + "Num").textCmp.text == word);
        }



        yield return(new WaitForSecondsRealtime(2));

        routerProve.Erase();
    }
    public IEnumerator GenerateChildsFromArrayOfClasses()
    {
        var levels = new Level[]
        {
            new Level
            {
                number = 1,
                name   = "LevelOne",
                time   = 12f,
            },
            new Level
            {
                number = 2,
                name   = "LevelTwo",
                time   = 15.3f,
            },
            new Level
            {
                number = 3,
                name   = "LevelThree",
                time   = 12.12f,
            },
            new Level
            {
                number = 4,
                name   = "LevelFour",
                time   = 0f,
            },
        };

        // A Component
        REcanvas MainReactorComponent()
        {
            return(new REcanvas
            {
                childs = () => levels.Select(c =>
                                             new REpanel
                {
                    propsId = () => new REpanel.IdSetter
                    {
                        id = c.number + "",
                    },
                    childs = () => new REbase[]
                    {
                        new REtext
                        {
                            propsText = () => new REtext.TextSetter
                            {
                                text = c.name,
                            }
                        },
                        new REimage(),
                        new REtext
                        {
                            propsText = () => new REtext.TextSetter
                            {
                                text = "Time: " + c.time,
                            }
                        }
                    }
                }
                                             ),
            });
        }

        var routerProve = MainReactorComponent();

        yield return(new WaitForSecondsRealtime(1));

        Debug.Log("Drawing");
        routerProve.Draw();

        Assert.IsTrue(REbase.FindOne("#" + levels[0].number + "").brothersSelector.Length == 4);

        Debug.Log("Childs");
        foreach (var level in levels)
        {
            //Debug.Log("Child: " + "#" + word + "Num" + " == " + word);
            //Debug.Log("Child: " + ReactorElement.Find<REtext.Selector>("#" + word + "Num")[0].textCmp.text + " == " + word);
            Assert.IsTrue(((REtext.Selector)REbase.FindOne("#" + level.number + "").childs[0]).textCmp.text == level.name);
            Assert.IsTrue(((REtext.Selector)REbase.FindOne("#" + level.number + "").childs[2]).textCmp.text == "Time: " + level.time);
        }

        routerProve.Erase();
    }
    public IEnumerator Hooks_UseState_GenerateChildWithUseState_ManualTriggerToChange()
    {
        var listState = new UseState <List <string> >(new List <string>());

        // A Component
        REcanvas MainReactorComponent()
        {
            return(new REcanvas
            {
                propsId = () => new REcanvas.IdSetter
                {
                    id = "MainCanvas",
                },
                useState = new IuseState[]
                {
                    listState,
                },
                childs = () => listState.value.Select(c =>
                                                      new REtext
                {
                    propsId = () => new REtext.IdSetter
                    {
                        id = c + "Num",
                    },
                    propsText = () => new REtext.TextSetter
                    {
                        text = c,
                    }
                }
                                                      ),
            });
        }

        var routerProve = MainReactorComponent();

        yield return(new WaitForSecondsRealtime(1));

        // Draw the component
        Debug.Log("Drawing");
        routerProve.Draw();

        // First check
        Debug.Log("Childs: " + REbase.FindOne("#MainCanvas").childs.Length);
        Assert.IsTrue(REbase.FindOne("#MainCanvas").childs.Length == 0);



        // usestate the component adding elements to the list manually
        Debug.Log("UseState: " + listState.value.Count());
        listState.value.Add("Dog");
        listState.value.Add("Cat");

        // Check, childs are 0, because the useState will not trigger if .SetState is not used
        Debug.Log("Childs: " + REbase.FindOne("#MainCanvas").childs.Length);
        Assert.IsTrue(REbase.FindOne("#MainCanvas").childs.Length == 0);



        // But can be triggered manually
        listState.Trigger();
        // Check, childs are 2, because the useState will not trigger if .SetState is not used
        Debug.Log("Childs: " + REbase.FindOne("#MainCanvas").childs.Length);
        Assert.IsTrue(REbase.FindOne("#MainCanvas").childs.Length == 2);



        yield return(new WaitForSecondsRealtime(2));

        routerProve.Erase();
    }
    public IEnumerator Hooks_UseState_InDisabledCanvas()
    {
        var alphaState = new UseState <float>(0f);

        // A Component
        REcanvas MainReactorComponent()
        {
            return(new REcanvas
            {
                propsId = () => new REcanvas.IdSetter
                {
                    id = "ProveCanvas"
                },
                propsCanvasGroup = () => new REcanvas.CanvasGroupSetter
                {
                    alpha = alphaState.value,
                },
                useState = new IuseState[]
                {
                    alphaState,
                },
                childs = () => new REbase[] {
                    new REtext(),
                },
            });
        }

        var routerProve = MainReactorComponent();

        yield return(new WaitForSecondsRealtime(1));

        // Drawing the component
        Debug.Log("Drawing");
        routerProve.Draw();
        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == 0f);

        yield return(new WaitForSecondsRealtime(1));

        // Hide the element
        routerProve.Disable();
        Assert.IsFalse(REbase.FindOne("#ProveCanvas").gameObject.activeSelf);

        // Change the states
        alphaState.SetState(.33f);
        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == .33f);

        // Will disable after one frame, because need to be active to calculate all the rect transform parameters
        yield return(new WaitForSecondsRealtime(.3f));

        Assert.IsFalse(REbase.FindOne("#ProveCanvas").gameObject.activeSelf);

        alphaState.SetState(.66f);
        // Will disable after one frame, because need to be active to calculate all the rect transform parameters
        yield return(new WaitForSecondsRealtime(.3f));

        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == .66f);
        Assert.IsFalse(REbase.FindOne("#ProveCanvas").gameObject.activeSelf);

        alphaState.PrevState();

        // Will disable after one frame, because need to be active to calculate all the rect transform parameters
        yield return(new WaitForSecondsRealtime(.3f));

        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == .33f);
        Assert.IsFalse(REbase.FindOne("#ProveCanvas").gameObject.activeSelf);


        // Enable and check
        routerProve.Enable();
        // Will disable after one frame, because need to be active to calculate all the rect transform parameters
        yield return(new WaitForSecondsRealtime(.3f));

        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == .33f);
        Assert.IsTrue(REbase.FindOne("#ProveCanvas").gameObject.activeSelf);


        yield return(new WaitForSecondsRealtime(2));

        routerProve.Erase();
    }
    public IEnumerator Hooks_UseState_InHidedCanvas()
    {
        var alphaState = new UseState <float>(0f);

        // A Component
        REcanvas MainReactorComponent()
        {
            return(new REcanvas
            {
                propsId = () => new REcanvas.IdSetter
                {
                    id = "ProveCanvas"
                },
                propsCanvasGroup = () => new REcanvas.CanvasGroupSetter
                {
                    alpha = alphaState.value,
                },
                useState = new IuseState[]
                {
                    alphaState,
                },
                childs = () => new REbase[] {
                    new REtext(),
                },
            });
        }

        var routerProve = MainReactorComponent();

        yield return(new WaitForSecondsRealtime(1));

        // Drawing the component
        Debug.Log("Drawing");
        routerProve.Draw();
        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == 0f);

        yield return(new WaitForSecondsRealtime(1));

        // Hide the element
        routerProve.Hide();
        Assert.IsFalse(REbase.FindOne("#ProveCanvas").rootCanvasSelector.canvas.enabled);

        // Change the states
        alphaState.SetState(.33f);
        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == .33f);
        Assert.IsFalse(REcanvas.FindOne("#ProveCanvas").rootCanvasSelector.canvas.enabled);
        alphaState.SetState(.66f);
        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == .66f);
        Assert.IsFalse(REcanvas.FindOne("#ProveCanvas").rootCanvasSelector.canvas.enabled);
        alphaState.PrevState();
        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == .33f);
        Assert.IsFalse(REcanvas.FindOne("#ProveCanvas").rootCanvasSelector.canvas.enabled);

        // Enable and check
        routerProve.Show();
        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").canvasGroup.alpha == .33f);
        Assert.IsTrue(REcanvas.FindOne("#ProveCanvas").rootCanvasSelector.canvas.enabled);


        yield return(new WaitForSecondsRealtime(2));

        routerProve.Erase();
    }
    public IEnumerator Hooks_UseState_InDisabledElements()
    {
        var wordState = new UseState <string>("Hola a todos !!");

        // A Component
        REcanvas MainReactorComponent()
        {
            return(new REcanvas
            {
                childs = () => new REbase[] {
                    new REtext {
                        propsId = () => new REtext.IdSetter {
                            id = "ProveText"
                        },
                        propsText = () => new REtext.TextSetter {
                            text = wordState.value,
                        },
                        useState = new IuseState[] {
                            wordState,
                        },
                    },
                },
            });
        }

        var routerProve = MainReactorComponent();

        yield return(new WaitForSecondsRealtime(1));

        // Drawing the component
        Debug.Log("Drawing");
        routerProve.Draw();
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "Hola a todos !!");

        yield return(new WaitForSecondsRealtime(1));

        // Hide the element
        routerProve.Disable();
        Assert.IsFalse(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);

        // Change the states
        wordState.SetState("NewWord");
        Debug.Log("Check");
        Assert.IsFalse(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "NewWord");
        wordState.SetState("OtherWord");
        Debug.Log("Check");
        Assert.IsFalse(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "OtherWord");
        wordState.PrevState();
        Debug.Log("Check");
        Assert.IsFalse(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "NewWord");
        wordState.SetState("OtherWord");
        wordState.SetState("Word");
        wordState.SetState("LastWord");
        wordState.SetState("FinalWord");
        Debug.Log("Check");
        Assert.IsFalse(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "FinalWord");
        wordState.PrevState(1);
        Debug.Log("Check");
        Assert.IsFalse(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "LastWord");
        wordState.PrevState(2);
        Debug.Log("Check");
        Assert.IsFalse(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "OtherWord");
        wordState.PrevState(10);
        Debug.Log("Check");
        Assert.IsFalse(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "Hola a todos !!");
        wordState.PrevState();
        Debug.Log("Check");
        Assert.IsFalse(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "Hola a todos !!");
        Debug.Log("Check");

        // Enable and check
        routerProve.Enable();
        Assert.IsTrue(REbase.FindOne("#ProveText").gameObject.activeInHierarchy);
        Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "Hola a todos !!");
        Debug.Log("Check");


        yield return(new WaitForSecondsRealtime(2));

        routerProve.Erase();
    }