public IEnumerator FindAllOfType() { yield return(new WaitForSecondsRealtime(2)); // - REcanvas 1 // - REtext 4 // - REimage 4 // - REbutton 2 // - REpanel 1 // Select All REcanvas.Selector[] finded = REcanvas.Find(); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 1); REtext.Selector[] finded2 = REtext.Find(); Debug.Log(finded2.Length); Assert.IsTrue(finded2.Length == 4); REimage.Selector[] finded3 = REimage.Find(); Debug.Log(finded3.Length); Assert.IsTrue(finded3.Length == 4); REbutton.Selector[] finded4 = REbutton.Find(); Debug.Log(finded4.Length); Assert.IsTrue(finded4.Length == 2); REpanel.Selector[] finded5 = REpanel.Find(); Debug.Log(finded5.Length); Assert.IsTrue(finded5.Length == 1); // Select All finded = REcanvas.Find(""); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 1); finded2 = REtext.Find(""); Debug.Log(finded2.Length); Assert.IsTrue(finded2.Length == 4); finded3 = REimage.Find(""); Debug.Log(finded3.Length); Assert.IsTrue(finded3.Length == 4); finded4 = REbutton.Find(""); Debug.Log(finded4.Length); Assert.IsTrue(finded4.Length == 2); finded5 = REpanel.Find(""); Debug.Log(finded5.Length); Assert.IsTrue(finded5.Length == 1); yield return(new WaitForSecondsRealtime(2)); }
public IEnumerator Hooks_UseState_WrongValues() { 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)); routerProve.Draw(); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "Hola a todos !!"); yield return(new WaitForSecondsRealtime(1)); wordState.SetState("NewWord"); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "NewWord"); wordState.SetState("OtherWord"); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "OtherWord"); wordState.PrevState(0); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "OtherWord"); wordState.SetState("OtherWord"); wordState.SetState("Word"); wordState.SetState("LastWord"); wordState.SetState("FinalWord"); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "FinalWord"); wordState.PrevState(-1); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "FinalWord"); wordState.PrevState(-2); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "FinalWord"); wordState.PrevState(-10); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "FinalWord"); wordState.PrevState(-2); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "FinalWord"); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
public IEnumerator Hooks_UseEffect_60ThrowErrorInDeltaFunction() { // 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; throw new Exception("Expected error"); }, } } }, }, }); } 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!"); // One message will be printed LogAssert.Expect(LogType.Error, new Regex("Expected error")); // Regex - Contains that string // First check and hook must be runner 1 yield return(new WaitForSecondsRealtime(1.2f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 1"); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
public IEnumerator GenerateChildsFromArray() { var words = new string[] { "One", "Two", "Three", "Four", "Five", }; // A Component REcanvas MainReactorComponent() { return(new REcanvas { childs = () => words.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)); Debug.Log("Drawing"); routerProve.Draw(); Debug.Log("Brothers"); Assert.IsTrue(REtext.FindOne("#" + words[0] + "Num").brothersSelector.Length == 5); Debug.Log("Childs"); foreach (var word in words) { //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(); }
void Start() { // Multiple components reactorList1 = ListREcomponent().Draw(); var find = REtext.Find("#Title-One"); Debug.Log("Elements Finded: " + find.Length); foreach (var element in find) { Debug.Log("Type: " + element.textCmp.text); } }
public IEnumerator Hooks_UseStateUseEffect() { 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 = "Textmain", }, propsText = () => new REtext.TextSetter { text = wordState.value, }, useState = new IuseState[] { wordState, }, useEffect = new REtext.UseEffect.Hook[] { new REtext.UseEffect.Hook { duration = 3, deltaFunction = (d, s) => wordState.SetState("A new word"), } } }, }, }); } var routerProve = MainReactorComponent(); routerProve.Draw(); // Waint until useeffect act yield return(new WaitForSecondsRealtime(4)); // Find the component Assert.IsTrue(REtext.FindOne("#Textmain").textCmp.text == "A new word"); yield return(null); }
public IEnumerator FindByIdOfType() { yield return(new WaitForSecondsRealtime(2)); // By id REcanvas.Selector[] finded = REcanvas.Find("#CanvasSuperior"); Assert.IsTrue(finded.Length == 1); // By id REtext.Selector[] finded2 = REtext.Find("#Title-One"); Assert.IsTrue(finded2.Length == 2); // By id REcanvas.Selector[] finded3 = REcanvas.Find("#ImagenSuperior"); Assert.IsTrue(finded3.Length == 0); // By id REpanel.Selector[] finded4 = REpanel.Find("#PanelBack"); Assert.IsTrue(finded4.Length == 1); // By id REbutton.Selector[] finded5 = REbutton.Find("#MainButton"); Assert.IsTrue(finded5.Length == 0); yield return(new WaitForSecondsRealtime(2)); }
public IEnumerator Hooks_UseEffect_32InErasedElements_WillBeErasedToo() { // 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.Erase(); // Second check and hook must be runner 2 yield return(new WaitForSecondsRealtime(3f)); Assert.IsTrue(REtext.FindOne("#ProveText") == null); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
public IEnumerator Hooks_UseEffect_30InHidedElements_RunNormally() { // 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.Hide(); Assert.IsFalse(((REcanvas.Selector)REbase.Find("#ProveText")[0].rootCanvasSelector).canvas.enabled); // Second check and hook must be runner 2 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 2"); // Enable and check routerProve.Show(); Assert.IsTrue(((REcanvas.Selector)REbase.Find("#ProveText")[0].rootCanvasSelector).canvas.enabled); // Thirh check and hook must be runner 3 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 3"); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
public IEnumerator Hooks_UseState_VariableNumberOfStates() { var wordState = new UseState <string>("Hola a todos !!"); var fontSizeState = new UseState <int>(20); // 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, fontSize = fontSizeState.value, }, useState = new IuseState[] { wordState, fontSizeState, }, }, }, }); } var routerProve = MainReactorComponent(); yield return(new WaitForSecondsRealtime(1)); // Draw the component routerProve.Draw(); Debug.Log("Check"); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "Hola a todos !!"); yield return(new WaitForSecondsRealtime(1)); // Erase the component routerProve.Erase(); wordState.SetState("NewWord"); wordState.SetState("OtherWord"); fontSizeState.SetState(23); wordState.PrevState(); wordState.SetState("OtherWord"); fontSizeState.SetState(44); wordState.SetState("Word"); wordState.SetState("LastWord"); fontSizeState.SetState(39); wordState.SetState("FinalWord"); fontSizeState.SetState(34); // Draw the component again routerProve.Draw(); Debug.Log("Check"); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "FinalWord"); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
public IEnumerator Hooks_UseEffect_16DeltaUnscaledEffect_ManyHooks() { // A Component REcanvas MainReactorComponent() { var count = 0; var count2 = 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 deltaFunction = (d, s) => { count++; s.textCmp.text = "C: " + count; }, }, new REtext.UseEffect.Hook { // Is executd each 1second per default deltaFunction = (d, s) => { count2++; s.textCmp.fontSize = count2; }, } } }, }, }); } 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"); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.fontSize == 1); // Second check and hook must be runner 2 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 2"); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.fontSize == 2); // Thirh check and hook must be runner 3 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 3"); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.fontSize == 3); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
public IEnumerator Find_ThenErase() { // Create a reactor component REcanvas MainReactorComponent() { return(new REcanvas { childs = () => new REbase[] { new REtext { propsId = () => new REtext.IdSetter { id = "ProveText" }, propsText = () => new REtext.TextSetter { text = "Hello world", }, childs = () => new REbase[] { new REimage(), new REimage(), } }, new REtext(), new REtext(), new REtext(), }, }); } var reactorComponent = MainReactorComponent(); yield return(new WaitForSecondsRealtime(1)); // Draw the component for the first time Debug.Log("Drawing"); reactorComponent.Draw(); yield return(new WaitForSecondsRealtime(1)); // Look fr the component Debug.Log("Finding"); var textSelector = REtext.FindOne("#ProveText"); // Check that the compoennt exist Assert.IsFalse(textSelector.isDisposed); Assert.IsFalse(textSelector.rectTransform == null); Assert.IsFalse(textSelector.gameObject == null); Assert.IsFalse(textSelector.parent == null); Assert.IsFalse(textSelector.childs == null); Assert.IsFalse(textSelector.brothersSelector == null); Assert.IsFalse(textSelector.canvasRenderer == null); Assert.IsTrue(textSelector.textCmp.text == "Hello world"); // Erase the component Debug.Log("Erasing"); reactorComponent.Erase(); // Check that the selector references are now null Assert.IsTrue(textSelector.isDisposed); Assert.IsTrue(textSelector.rectTransform == null); Assert.IsTrue(textSelector.gameObject == null); Assert.IsTrue(textSelector.parent == null); Assert.IsTrue(textSelector.childs == null); Assert.IsTrue(textSelector.brothersSelector == null); Assert.IsTrue(textSelector.canvasRenderer == null); Assert.Throws <NullReferenceException>(() => Debug.Log("V: " + textSelector.rectTransform.rect)); // Try to find again the component that it must not exist Debug.Log("Finding again"); Assert.IsTrue(REtext.Find("#ProveText").Length == 0); yield return(new WaitForSecondsRealtime(2)); reactorComponent.Erase(); }
public IEnumerator DrawInOtherObject() { // Create a reactor component REcanvas MainReactorComponent() { return(new REcanvas { childs = () => new REbase[] { new REtext { propsId = () => new REtext.IdSetter { id = "ProveText" }, propsText = () => new REtext.TextSetter { text = "Hello world", }, childs = () => new REbase[] { new REimage(), new REimage(), } }, new REtext(), new REtext(), new REtext(), }, }); } var reactorComponent = MainReactorComponent(); yield return(new WaitForSecondsRealtime(1)); // Draw the component for the first time but in other object Debug.Log("Drawing"); reactorComponent.Draw(new GameObject("AnyObject")); yield return(new WaitForSecondsRealtime(1)); // Look fr the component var textSelector = REtext.Find("#ProveText")[0]; // The transform root must be the other object Assert.IsTrue(REtext.Find("#ProveText").Length == 1); Assert.IsTrue(textSelector.rectTransform.root.gameObject.name == "AnyObject"); // If component is redrawed the same parent must be in same object, but must be finded again reactorComponent.Draw(new GameObject("OtherObject")); textSelector = REtext.Find("#ProveText")[0]; // The transform root must be the other object Assert.IsTrue(REtext.Find("#ProveText").Length == 1); Assert.IsTrue(textSelector.rectTransform.root.gameObject.name == "OtherObject"); // If component is redrawed in null reactorComponent.Draw(); textSelector = REtext.Find("#ProveText")[0]; // The transform root must be the canvas Assert.IsTrue(REtext.Find("#ProveText").Length == 1); Assert.IsTrue(textSelector.rectTransform.root.gameObject.name == "Canvas-Unamed"); reactorComponent.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(); }
private REcanvas SingnInView() { string usernameText = ""; string passwordText = ""; User currentUser = null; string message = "Write your credentials"; bool rememberme = false; // Hooks var viweState = new UseState <int>(0); var errorTrigger = new UseTrigger(); var usersList = new UseState <User[]>(new User[0]); var userslistRequest = false; return(new REcanvas { childs = () => { // Profile if (viweState.value == 1) { return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Welcome " + currentUser.username, } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username: "******"Password: "******"Logout" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { currentUser = null; message = "Write your credentials"; if (!rememberme) { usernameText = ""; passwordText = ""; } errorTrigger.Trigger(); viweState.SetState(0); } } }, new REtext { propsText = () => new REtext.TextSetter { text = message, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = message; } } } }, new REbox { propsRectTransform = () => new REbox.RectTransformSetter { height = 400, width = 800, }, childs = () => new REbase[] { new REpanelVertical { childs = () => usersList.value.Select(u => new REtext { propsText = () => new REtext.TextSetter { text = u.username, } }), } }, useState = new IuseState[] { usersList, }, useObjectEvents = new REbox.UseObjectEvents.Hook { onAwake = async(s) => { if (userslistRequest) { return; } Debug.Log("Requesting List ..."); try { var users = await User.Find(); userslistRequest = true; usersList.SetState(users); } catch (System.Exception) { } } }, } } , useObjectEvents = new REpanelVertical.UseObjectEvents.Hook { onDestroy = (s) => { userslistRequest = false; } }, }, }; } // Sign Up Component else if (viweState.value == 3) { string newUsername = ""; string newPassword = ""; return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Sign Up" } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = newUsername, OnValueChangedListener = (v, s) => { newUsername = v; } } }, new REtext { propsText = () => new REtext.TextSetter { text = "Password" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = newPassword, OnValueChangedListener = (v, s) => { newPassword = v; } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Create" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = async(s) => { try { var newUser = await new User { username = newUsername, password = newPassword, }.Save(); if (newUser) { message = "Succesfull Created"; newUsername = ""; newPassword = ""; errorTrigger.Trigger(); viweState.SetState(0); } else { message = "Cant create a user"; errorTrigger.Trigger(); } } catch (System.Exception e) { message = e + ""; errorTrigger.Trigger(); } } } }, new REtext { propsText = () => new REtext.TextSetter { text = message, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = message; } } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Sign In" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { message = "Write your credentials"; errorTrigger.Trigger(); viweState.SetState(0); } } }, } }, }; } // Sign In Component else { return new REbase[] { // Get request new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Sign In" } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = usernameText, OnValueChangedListener = (v, s) => { usernameText = v; } } }, new REtext { propsText = () => new REtext.TextSetter { text = "Password" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = passwordText, OnValueChangedListener = (v, s) => { passwordText = v; } } }, new REtoggle { propsText = () => new REtoggle.TextSetter { text = "Remember me" }, propsToggle = () => new REtoggle.ToggleSetter { isOn = rememberme, OnValueChangedListener = (v, s) => rememberme = v, } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Login" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = async(s) => { try { var findUser = await User.Find(usernameText, passwordText); currentUser = findUser; } catch (System.Exception e) { message = e + ""; currentUser = null; errorTrigger.Trigger(); return; } if (currentUser != null) { Debug.Log("Username: "******" Password: "******"Succesfull sign In"; errorTrigger.Trigger(); viweState.SetState(1); } else { message = "Bad credentials"; errorTrigger.Trigger(); } } } }, new REtext { propsText = () => new REtext.TextSetter { text = message, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = message; } } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Sign Up" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { message = "Create your credentials"; errorTrigger.Trigger(); viweState.SetState(3); } } }, } }, }; } }, useState = new IuseState[] { viweState, } }); }
public IEnumerator GenerateChildsFromDinamicList() { var words = new List <string> { "One", "Two", "Three", "Four", "Five", }; // A Component REcanvas MainReactorComponent() { return(new REcanvas { childs = () => words.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("Brothers"); Assert.IsTrue(REtext.FindOne("#" + words[0] + "Num").brothersSelector.Length == 5); Debug.Log("Childs"); foreach (var word in words) { //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); } // Cahnge the list words.Add("Perro"); words.Add("Gato"); // Second check must not change Debug.Log("Brothers"); Assert.IsTrue(REtext.FindOne("#" + words[0] + "Num").brothersSelector.Length == 5); Debug.Log("Childs"); foreach (var word in words) { if (word == "Perro" || word == "Gato") { continue; } Debug.Log("Child: " + "#" + word + "Num" + " == " + word); Debug.Log("Child: " + REtext.FindOne("#" + word + "Num").textCmp.text + " == " + word); Assert.IsTrue(REtext.FindOne("#" + word + "Num").textCmp.text == word); } // Draw again the component Debug.Log("Drawing again"); routerProve.Draw(); // Check Debug.Log("Brothers: " + REtext.FindOne("#" + words[0] + "Num").brothersSelector.Length); Assert.IsTrue(REtext.FindOne("#" + words[0] + "Num").brothersSelector.Length == 7); Debug.Log("Childs"); foreach (var word in words) { //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); } // Cahnge the list words.Remove("Perro"); words.Remove("Gato"); // Draw again the component Debug.Log("Drawing again"); routerProve.Draw(); // Check Debug.Log("Brothers"); Assert.IsTrue(REtext.FindOne("#" + words[0] + "Num").brothersSelector.Length == 5); Debug.Log("Childs"); foreach (var word in words) { //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); } // Cahnge the list words.Clear(); // Draw again the component Debug.Log("Drawing again"); routerProve.Draw(); // Check Debug.Log("Brothers"); Assert.IsTrue(REtext.FindOne("#1") == null); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
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(); }
private REcanvas SingnInView() { string usernameText = ""; string passwordText = ""; User currentUser = null; string error = "Write your credentials"; bool rememberme = false; // Hooks var viweState = new UseState <int>(0); var errorTrigger = new UseTrigger(); return(new REcanvas { childs = () => { // Profile if (viweState.value == 1) { return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Welcome " + currentUser.username, } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username: "******"Password: "******"Logout" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { currentUser = null; error = "Write your credentials"; if (!rememberme) { usernameText = ""; passwordText = ""; } errorTrigger.Trigger(); viweState.SetState(0); } } }, new REtext { propsText = () => new REtext.TextSetter { text = error, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = error; } } } }, new REbox { propsRectTransform = () => new REbox.RectTransformSetter { height = 400, width = 800, }, childs = () => new REbase[] { new REpanelVertical { childs = () => User.Find().Select(u => new REtext { propsText = () => new REtext.TextSetter { text = u.username, } } ), } } } } }, }; } // Sign Up Component else if (viweState.value == 3) { string newUsername = ""; string newPassword = ""; return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Sign Up" } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = newUsername, OnValueChangedListener = (v, s) => { newUsername = v; } } }, new REtext { propsText = () => new REtext.TextSetter { text = "Password" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = newPassword, OnValueChangedListener = (v, s) => { newPassword = v; } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Create" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { var newUser = new User { username = newUsername, password = newPassword, }.Save(); if (newUser) { error = "Succesfull Created"; newUsername = ""; newPassword = ""; errorTrigger.Trigger(); viweState.SetState(0); } else { error = "Cant create a user"; errorTrigger.Trigger(); } } } }, new REtext { propsText = () => new REtext.TextSetter { text = error, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = error; } } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Sign In" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { error = "Write your credentials"; errorTrigger.Trigger(); viweState.SetState(0); } } }, } }, }; } // Sign In Component else { return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Sign In" } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = usernameText, OnValueChangedListener = (v, s) => { usernameText = v; } } }, new REtext { propsText = () => new REtext.TextSetter { text = "Password" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = passwordText, OnValueChangedListener = (v, s) => { passwordText = v; } } }, new REtoggle { propsText = () => new REtoggle.TextSetter { text = "Remember me" }, propsToggle = () => new REtoggle.ToggleSetter { isOn = rememberme, OnValueChangedListener = (v, s) => rememberme = v, } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Login" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { var findUser = User.Find(usernameText, passwordText); currentUser = findUser; if (findUser != null) { Debug.Log("Username: "******" Password: "******"Succesfull sign In"; errorTrigger.Trigger(); viweState.SetState(1); } else { error = "Invalid credentials, try again"; errorTrigger.Trigger(); } } } }, new REtext { propsText = () => new REtext.TextSetter { text = error, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = error; } } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Sign Up" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { error = "Create your credentials"; errorTrigger.Trigger(); viweState.SetState(3); } } }, } }, }; } }, useState = new IuseState[] { viweState, } }); }
public IEnumerator FindAsChildOfOtherGO_AndDisableEnable() { // Create a reactor component REcanvas MainReactorComponent() { return(new REcanvas { childs = () => new REbase[] { new REtext { propsId = () => new REtext.IdSetter { id = "ProveText" }, propsText = () => new REtext.TextSetter { text = "Hello world", }, childs = () => new REbase[] { new REimage(), new REimage(), } }, new REtext(), new REtext(), new REtext(), }, }); } var reactorComponent = MainReactorComponent(); yield return(new WaitForSecondsRealtime(1)); // Draw the component for the first time Debug.Log("Drawing"); var go = new GameObject("AnyGameobject"); reactorComponent.Draw(go); yield return(new WaitForSecondsRealtime(1)); // Look fr the component Debug.Log("Finding"); var textSelector = REtext.FindOne("#ProveText"); Assert.IsTrue(textSelector.gameObject.activeSelf); // Check that the compoennt exist Assert.IsFalse(textSelector.isDisposed); Assert.IsFalse(textSelector.rectTransform == null); Assert.IsFalse(textSelector.gameObject == null); Assert.IsFalse(textSelector.parent == null); Assert.IsFalse(textSelector.childs == null); Assert.IsFalse(textSelector.brothersSelector == null); Assert.IsFalse(textSelector.canvasRenderer == null); Assert.IsTrue(textSelector.textCmp.text == "Hello world"); // Disable the component Debug.Log("Disabling"); go.SetActive(false); Assert.IsTrue(textSelector.gameObject.activeSelf); Assert.IsFalse(textSelector.gameObject.activeInHierarchy); Assert.IsTrue(textSelector.rootCanvasSelector.gameObject.activeSelf); // Check that the selector references are not null Assert.IsFalse(textSelector.isDisposed); Assert.IsFalse(textSelector.rectTransform == null); Assert.IsFalse(textSelector.gameObject == null); Assert.IsFalse(textSelector.parent == null); Assert.IsFalse(textSelector.childs == null); Assert.IsFalse(textSelector.brothersSelector == null); Assert.IsFalse(textSelector.canvasRenderer == null); Assert.IsTrue(textSelector.textCmp.text == "Hello world"); // Show/Enable the component Debug.Log("Showing"); go.SetActive(true); Assert.IsTrue(textSelector.gameObject.activeSelf); Assert.IsTrue(textSelector.gameObject.activeInHierarchy); Assert.IsTrue(textSelector.rootCanvasSelector.gameObject.activeSelf); // Check that the selector references are now null Assert.IsFalse(textSelector.isDisposed); Assert.IsFalse(textSelector.rectTransform == null); Assert.IsFalse(textSelector.gameObject == null); Assert.IsFalse(textSelector.parent == null); Assert.IsFalse(textSelector.childs == null); Assert.IsFalse(textSelector.brothersSelector == null); Assert.IsFalse(textSelector.canvasRenderer == null); Assert.IsTrue(textSelector.textCmp.text == "Hello world"); yield return(new WaitForSecondsRealtime(2)); reactorComponent.Erase(); }
public IEnumerator DrawInOtherObject_ButObjectDestroyed() { // Create a reactor component REcanvas MainReactorComponent() { return(new REcanvas { childs = () => new REbase[] { new REtext { propsId = () => new REtext.IdSetter { id = "ProveText" }, propsText = () => new REtext.TextSetter { text = "Hello world", }, childs = () => new REbase[] { new REimage(), new REimage(), } }, new REtext(), new REtext(), new REtext(), }, }); } var reactorComponent = MainReactorComponent(); yield return(new WaitForSecondsRealtime(1)); // Draw the component for the first time but in other object Debug.Log("Drawing"); reactorComponent.Draw(new GameObject("AnyObject")); yield return(new WaitForSecondsRealtime(1)); // Look fr the component Debug.Log("Finding"); var textSelector = REtext.Find("#ProveText")[0]; // The transform root must be the other object Assert.IsTrue(REtext.Find("#ProveText").Length == 1); Assert.IsTrue(textSelector.rectTransform.root.gameObject.name == "AnyObject"); // If component is redrawed the same parent must be in same object, but must be finded again Debug.Log("Drawing in other object"); var go = new GameObject("OtherObject"); reactorComponent.Draw(go); textSelector = REtext.Find("#ProveText")[0]; // The transform root must be the other object Debug.Log("Finding again"); Assert.IsTrue(REtext.Find("#ProveText").Length == 1); Assert.IsTrue(textSelector.rectTransform.root.gameObject.name == "OtherObject"); // If object destroyed Debug.Log("Destroying object"); UnityEngine.Object.DestroyImmediate(go); // Reactor component will be destroyed too Assert.IsTrue(REtext.Find("#ProveText").Length == 0); // Check that the selector references are now null Debug.Log("Checking selectoris destroyed"); Assert.IsTrue(textSelector.isDisposed); Assert.IsTrue(textSelector.rectTransform == null); Assert.IsTrue(textSelector.gameObject == null); Assert.IsTrue(textSelector.parent == null); Assert.IsTrue(textSelector.childs == null); Assert.IsTrue(textSelector.brothersSelector == null); Assert.IsTrue(textSelector.canvasRenderer == null); Assert.Throws <NullReferenceException>(() => Debug.Log("V: " + textSelector.rectTransform.rect)); reactorComponent.Erase(); }
public IEnumerator DrawInOtherObjectNestedCanvas_Selector_ParentCanvas() { // Create a reactor component REcanvas MainReactorComponent() { return(new REcanvas { propsGameObject = () => new REcanvas.GameObjectSetter { name = "RootCanvas", }, childs = () => new REbase[] { new REcanvas { childs = () => new REbase[] { new REpanel { childs = () => new REbase[] { new REtext { propsId = () => new REtext.IdSetter { id = "ProveText" }, propsText = () => new REtext.TextSetter { text = "Hello world", }, childs = () => new REbase[] { new REimage(), new REimage(), } }, new REtext(), new REtext(), new REtext(), }, } }, } }, }); } var reactorComponent = MainReactorComponent(); yield return(new WaitForSecondsRealtime(1)); // Draw the component for the first time but in other object Debug.Log("Drawing"); reactorComponent.Draw(new GameObject("AnyObject")); yield return(new WaitForSecondsRealtime(1)); // Look fr the component Debug.Log("Finding"); var textSelector = REtext.Find("#ProveText")[0]; // The transform root must be the other object Assert.IsTrue(REtext.Find("#ProveText").Length == 1); Assert.IsTrue(textSelector.rectTransform.root.gameObject.name == "AnyObject"); // But the selector parentcanvas must be the first canvas Debug.Log("Check parentCanvas"); Assert.IsTrue(textSelector.parentCanvasSelector.gameObject.name == "Canvas-Unamed"); Assert.IsTrue(textSelector.parentCanvasSelector.parentCanvasSelector.gameObject.name == "RootCanvas"); Assert.IsTrue(textSelector.parentCanvasSelector.parentCanvasSelector.parentCanvasSelector.gameObject.name == "RootCanvas"); var canvasSelector = (REcanvas.Selector)textSelector.parentCanvasSelector; canvasSelector = (REcanvas.Selector)textSelector.parentCanvasSelector.parentCanvasSelector; canvasSelector = (REcanvas.Selector)textSelector.parentCanvasSelector.parentCanvasSelector.parentCanvasSelector; // If component is redrawed in null Debug.Log("Drawing in null"); reactorComponent.Draw(); textSelector = REtext.Find("#ProveText")[0]; // But the selector parentcanvas must be the first canvas Debug.Log("Check parentCanvas"); Assert.IsTrue(textSelector.parentCanvasSelector.gameObject.name == "Canvas-Unamed"); Assert.IsTrue(textSelector.parentCanvasSelector.parentCanvasSelector.gameObject.name == "RootCanvas"); Assert.IsTrue(textSelector.parentCanvasSelector.parentCanvasSelector.parentCanvasSelector.gameObject.name == "RootCanvas"); canvasSelector = (REcanvas.Selector)textSelector.parentCanvasSelector; canvasSelector = (REcanvas.Selector)textSelector.parentCanvasSelector.parentCanvasSelector; canvasSelector = (REcanvas.Selector)textSelector.parentCanvasSelector.parentCanvasSelector.parentCanvasSelector; reactorComponent.Erase(); }
public IEnumerator FindByClassNameOfType() { yield return(new WaitForSecondsRealtime(2)); // One classname var finded = REcanvas.Find(".Back"); Debug.Log(finded.Length); Assert.IsTrue(finded.Length == 1); var finded2 = REtext.Find(".H1"); Debug.Log(finded2.Length); Assert.IsTrue(finded2.Length == 2); var finded3 = REtext.Find(".Text"); Debug.Log(finded3.Length); Assert.IsTrue(finded3.Length == 4); var finded4 = REimage.Find(".Title"); Debug.Log(finded4.Length); Assert.IsTrue(finded4.Length == 0); var finded5 = REbutton.Find(".Button"); Debug.Log(finded5.Length); Assert.IsTrue(finded5.Length == 2); var finded6 = REcanvas.Find(".White"); Debug.Log(finded6.Length); Assert.IsTrue(finded6.Length == 0); // With AND var finded7 = REtext.Find(".H1&&.Text&&.Title"); Debug.Log(finded7.Length); Assert.IsTrue(finded7.Length == 1); var finded8 = REbutton.Find(".Button&&Title"); Debug.Log(finded8.Length); Assert.IsTrue(finded8.Length == 1); var finded9 = REimage.Find(".H1&&.Text"); Debug.Log(finded9.Length); Assert.IsTrue(finded9.Length == 0); var finded10 = REcanvas.Find(".H1&&Pink"); Debug.Log(finded10.Length); Assert.IsTrue(finded10.Length == 0); // With or var finded11 = REtext.Find(".Button||Text"); Debug.Log(finded11.Length); Assert.IsTrue(finded11.Length == 4); var finded12 = REpanel.Find(".Back||H1||Text"); Debug.Log(finded12.Length); Assert.IsTrue(finded12.Length == 1); var finded13 = REtext.Find(".Back||H1||Grey"); Debug.Log(finded13.Length); Assert.IsTrue(finded13.Length == 2); yield return(new WaitForSecondsRealtime(2)); }
public IEnumerator Hooks_UseEffect_10Basics() { // 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"); // Second check and hook must be runner 2 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 2"); // Thirh check and hook must be runner 3 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 3"); // Time dont affect deltaUnscaledEffect Time.timeScale = .01f; // Four check and hook must be runner 4 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 4"); // Five check and hook must be runner 5 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 5"); // Time dont affect deltaUnscaledEffect Time.timeScale = 1f; // Four check and hook must be runner 6 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 6"); // Five check and hook must be runner 7 yield return(new WaitForSecondsRealtime(1f)); Assert.IsTrue(REtext.FindOne("#ProveText").textCmp.text == "C: 7"); yield return(new WaitForSecondsRealtime(2)); routerProve.Erase(); }
public IEnumerator Find_AndUseState() { var letterState = new UseState <string>("Hello world"); // Create a reactor component REcanvas MainReactorComponent() { return(new REcanvas { childs = () => new REbase[] { new REtext { propsId = () => new REtext.IdSetter { id = "ProveText" }, propsText = () => new REtext.TextSetter { text = letterState.value, }, useState = new IuseState[] { letterState, }, childs = () => new REbase[] { new REimage(), new REimage(), } }, new REtext(), new REtext(), new REtext(), }, }); } var reactorComponent = MainReactorComponent(); yield return(new WaitForSecondsRealtime(1)); // Draw the component for the first time Debug.Log("Drawing"); reactorComponent.Draw(); yield return(new WaitForSecondsRealtime(1)); // Look fr the component Debug.Log("Finding"); var textSelector = REtext.FindOne("#ProveText"); // Check that the compoennt exist Assert.IsFalse(textSelector.isDisposed); Assert.IsFalse(textSelector.rectTransform == null); Assert.IsFalse(textSelector.gameObject == null); Assert.IsFalse(textSelector.parent == null); Assert.IsFalse(textSelector.childs == null); Assert.IsFalse(textSelector.brothersSelector == null); Assert.IsFalse(textSelector.canvasRenderer == null); Assert.IsTrue(textSelector.textCmp.text == "Hello world"); // Redraw the component Debug.Log("Changing and drawing again"); letterState.SetState("New text"); // Check that the selector references are now null Debug.Log("Changing and drawing again"); Assert.IsTrue(textSelector.isDisposed); Debug.Log("Changing and drawing again"); Assert.IsTrue(textSelector.rectTransform == null); Debug.Log("Changing and drawing again"); Assert.IsTrue(textSelector.gameObject == null); Debug.Log("Changing and drawing again"); Assert.IsTrue(textSelector.parent == null); Debug.Log("Changing and drawing again"); Assert.IsTrue(textSelector.childs == null); Debug.Log("Changing and drawing again"); Assert.IsTrue(textSelector.brothersSelector == null); Debug.Log("Changing and drawing again"); Assert.IsTrue(textSelector.canvasRenderer == null); Debug.Log("Changing and drawing again"); Assert.Throws <NullReferenceException>(() => Debug.Log("V: " + textSelector.rectTransform.rect)); Debug.Log("Changing and drawing again"); // Try to find again the component that it must exist Debug.Log("Finding again"); textSelector = REtext.FindOne("#ProveText"); // Check that the compoennt exist Assert.IsFalse(textSelector.isDisposed); Assert.IsFalse(textSelector.rectTransform == null); Assert.IsFalse(textSelector.gameObject == null); Assert.IsFalse(textSelector.parent == null); Assert.IsFalse(textSelector.childs == null); Assert.IsFalse(textSelector.brothersSelector == null); Assert.IsFalse(textSelector.canvasRenderer == null); Assert.IsTrue(textSelector.textCmp.text == "New text"); yield return(new WaitForSecondsRealtime(2)); reactorComponent.Erase(); }