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_UseUpdate_31InDisabledElements_DontRun() { var counter = 0; // A Component REcanvas MainReactorComponent() { return(new REcanvas { childs = () => new REbase[] { new REtext { propsId = () => new REtext.IdSetter { id = "ProveText" }, propsText = () => new REtext.TextSetter { text = "Hello World!", }, useUpdate = new REtext.UseUpdate.Hook { onUpdate = (s) => { // Increment the value each frame if (counter < 10) { counter++; } }, } }, }, }); } var routerProve = MainReactorComponent(); yield return(new WaitForSecondsRealtime(1)); // Draw the component Debug.Log("Drawing"); routerProve.Draw(); // Hide the element routerProve.Disable(); Assert.IsFalse(((REcanvas.Selector)REbase.Find("#ProveText")[0].rootCanvasSelector).canvas.enabled); // First check and hook must be runned yield return(new WaitForSecondsRealtime(1.0f)); Assert.IsFalse(counter == 10); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
public IEnumerator FindAll() { yield return(new WaitForSecondsRealtime(2)); // Select All var finded = REbase.Find(); Assert.IsTrue(finded.Length == 12); // Select All finded = REbase.Find(""); Assert.IsTrue(finded.Length == 12); yield return(new WaitForSecondsRealtime(2)); }
public IEnumerator FindById() { yield return(new WaitForSecondsRealtime(2)); // By id var finded = REbase.Find("#CanvasSuperior"); Assert.IsTrue(finded.Length == 1); // By id finded = REbase.Find("#Title-One"); Assert.IsTrue(finded.Length == 2); // By id finded = REbase.Find("#ImagenSuperior"); Assert.IsTrue(finded.Length == 1); // By id finded = REbase.Find("#PanelBack"); Assert.IsTrue(finded.Length == 1); // By id finded = REbase.Find("#MainButton"); Assert.IsTrue(finded.Length == 0); yield return(new WaitForSecondsRealtime(2)); }
private void Start() { if (toDestroy != null && destroyOnStart) { for (int i = 0; i < toDestroy.Length; i++) { if (toDestroy[i] == null) { continue; } UnityEngine.GameObject.Destroy(toDestroy[i]); } } switch (testCase) { case TestCase.A00Basic: #region TestCase.A00Basic new REcanvas { childs = () => new REbase[] { new REpanelHorizontal { }, } }.Draw(); #endregion break; case TestCase.A01WithChilds: #region TestCase.A01WithChilds new REcanvas { childs = () => new REbase[] { new REpanelHorizontal { childs = () => new REbase[] { new REimage { }, new REimage { }, }, }, } }.Draw(); #endregion break; case TestCase.A10WithScrollbar: #region TestCase.A10WithScrollbar new REcanvas { childs = () => new REbase[] { new REpanelHorizontal { childs = () => { var ch = new REbase[15]; for (int i = 0; i < ch.Length; i++) { ch[i] = new REimage { }; } return(ch); }, }, } }.Draw(); #endregion break; case TestCase.A02ControlChildsHeigh: #region TestCase.A02ControlChildsHeigh new REcanvas { childs = () => new REbase[] { new REpanelHorizontal { propsHorizontalLayoutGroup = () => new REpanelHorizontal.HorizontalLayoutGroupSetter { childControlHeight = true, }, childs = () => new REbase[] { new REimage { }, new REimage { }, new REimage { }, new REimage { }, new REimage { }, }, }, } }.Draw(); #endregion break; case TestCase.A03BadWayRenderNoLayoutElements: #region TestCase.A03BadWayRenderNoLayoutElements new REcanvas { childs = () => new REbase[] { new REpanelHorizontal { childs = () => new REbase[] { new REimage { propsLayoutElement = () => new REimage.LayoutElementSetter { preferredHeight = 25, }, }, // This element wont de created and a error message will be displayed new REpanelHorizontal { }, new REbox { propsLayoutElement = () => new REbox.LayoutElementSetter { preferredHeight = 50, }, }, new REimage { propsLayoutElement = () => new REimage.LayoutElementSetter { preferredHeight = 50, }, }, }, }, } }.Draw(); #endregion break; case TestCase.A04RightWayToRenderNoLayoutElements: #region TestCase.A04RightWayToRenderNoLayoutElements new REcanvas { childs = () => new REbase[] { new REpanelHorizontal { childs = () => new REbase[] { new REimage { propsLayoutElement = () => new REimage.LayoutElementSetter { preferredHeight = 25, }, }, // Create inside a box new REbox { propsLayoutElement = () => new REbox.LayoutElementSetter { preferredHeight = 50, }, childs = () => new REbase[] { new REpanelHorizontal { }, }, }, new REbox { propsLayoutElement = () => new REbox.LayoutElementSetter { preferredHeight = 50, }, }, new REimage { propsLayoutElement = () => new REimage.LayoutElementSetter { preferredHeight = 50, }, }, }, }, } }.Draw(); #endregion break; } lastTestCase = testCase; }
public IEnumerator Hooks_UseEffect_31InDisabledElements_DontRun() { // A Component REcanvas MainReactorComponent() { var count = 0; return(new REcanvas { childs = () => new REbase[] { new REtext { propsId = () => new REtext.IdSetter { id = "ProveText" }, propsText = () => new REtext.TextSetter { text = "Hello World!", }, useEffect = new REtext.UseEffect.Hook[] { new REtext.UseEffect.Hook { // Is executd each 1second per default in unscaled time mode deltaFunction = (d, s) => { count++; s.textCmp.text = "C: " + count; }, } } }, }, }); } var routerProve = MainReactorComponent(); yield return(new WaitForSecondsRealtime(1)); // Draw the component routerProve.Draw(); Debug.Log("Drawing"); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "Hello World!"); // First check and hook must be runner 1 yield return(new WaitForSecondsRealtime(1.2f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 1"); // Hide the element routerProve.Disable(); Assert.IsFalse(REbase.Find("#ProveText")[0].gameObject.activeInHierarchy); // Second check and hook must be runner 2 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 1"); // Enable and check routerProve.Enable(); Assert.IsTrue(REbase.Find("#ProveText")[0].gameObject.activeInHierarchy); // Thirh check and hook must be runner 3 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 2"); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
public IEnumerator FindByClassName() { yield return(new WaitForSecondsRealtime(2)); // One classname var finded = REbase.Find(".Back"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 2); finded = REbase.Find(".H1"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 2); finded = REbase.Find(".Text"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 4); finded = REbase.Find(".Title"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 2); finded = REbase.Find(".Button"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 2); finded = REbase.Find(".White"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 0); // With AND finded = REbase.Find(".H1&&.Text&&.Title"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 1); finded = REbase.Find(".Button&&Title"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 1); finded = REbase.Find(".H1&&.Text"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 2); finded = REbase.Find(".H1&&Pink"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 0); // With or finded = REbase.Find(".Button||Text"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 6); finded = REbase.Find(".Back||H1||Text"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 6); finded = REbase.Find(".Back||H1||Grey"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 4); 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(); }