Exemplo n.º 1
0
 protected override void AfterCreateChild(REbaseSelector child)
 {
     // Call function to add layout to childs elements
     try
     {
         child.layoutElementSetter?.Invoke().Set(child.gameObject);
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 2
0
 public static Selector CastSelector(REbaseSelector selector)
 {
     try
     {
         return((Selector)selector);
     }
     catch (Exception)
     {
         Debug.Log("REdiv: Cant cast selector");
         return(null);
     }
 }
Exemplo n.º 3
0
 protected virtual void AfterCreateChild(REbaseSelector child)
 {
 }
Exemplo n.º 4
0
        // Create all the component , call other functions in order
        protected REbase Draw(GameObject parent, REbaseSelector parentSelector)
        {
            // Functions to create parts of the component
            Erase();
            CreateRoot(parent);
            AddComponents();
            this.parentSelector = parentSelector;
            this.selector       = AddSelector();
            selector.SetParent(parentSelector);
            selector.layoutElementSetter = PropsLayoutElement;
            selector.isLayoutElement     = isLayoutElement;
            AddHooks();

            // Create childs
            childsList.Clear();

            IEnumerable <REbase> newChilds = null;

            if (childs != null)
            {
                try { newChilds = childs(); }
                catch (Exception e) { Debug.LogError("UReactor: Error drawing childs of, " + gameObject.name + ", " + e); }
            }

            if (newChilds != null)
            {
                foreach (var child in newChilds)
                {
                    CreateChild(child);
                }
            }
            selector.SetChilds(childsList);

            AfterCreateComponent();

            //// Wait for ui to update values
            if (Application.isPlaying)
            {
                var host = new GameObject();
                UnityEngine.Object.DontDestroyOnLoad(host);
                host.AddComponent <NoBehaviour>().StartCoroutine(WaitForDraw()); IEnumerator WaitForDraw()
                {
                    yield return(new WaitForEndOfFrame());  // Wait for rect values to be calculated

                    bool shouldEnable = PropsGameObject().active;

                    if (isDisabled)
                    {
                        shouldEnable = false;
                    }

                    if (gameObject != null)
                    {
                        gameObject.SetActive(shouldEnable);
                    }

                    AfterRenderComponent(); // Run after create function

                    UnityEngine.Object.Destroy(host);
                }
            }
            else
            {
                WaitForDraw(); async void WaitForDraw()
                {
                    await Task.Delay(1000);                         // Wait for rect values to be calculated

                    AfterRenderComponent();                         // Run after create function
                    gameObject.SetActive(PropsGameObject().active); // Enable or disable
                }
            }

            // Subscribe to useState events
            if (useState != null)
            {
                foreach (var state in useState)
                {
                    if (state == null)
                    {
                        continue;
                    }

                    state.OnStateChange -= OnUseStateChange;
                    state.OnStateChange += OnUseStateChange;
                }
            }

            // Subscribe to useAddChilds events
            if (useAddChilds != null)
            {
                foreach (var h in useAddChilds)
                {
                    if (h == null)
                    {
                        continue;
                    }

                    h.OnChildAdded -= OnUseChildAdded;
                    h.OnChildAdded += OnUseChildAdded;
                }
            }

            // Subscribe to useTrigger events
            if (useTrigger != null)
            {
                foreach (var h in useTrigger.Select(p => p.hook))
                {
                    if (h == null)
                    {
                        continue;
                    }

                    h.OnTrigger -= OnTrigger;
                    h.OnTrigger += OnTrigger;
                }
            }

            // Add Id
            selector.SetErase(Erase);
            selector.SetEraseChilds(EraseChilds);
            idCmp.SetSelector(selector);

            return(this);
        }
Exemplo n.º 5
0
 internal void SetSelector(REbaseSelector selector)
 {
     this.selector = selector;
 }
Exemplo n.º 6
0
 internal void SetParent(REbaseSelector parent)
 {
     this.parent = parent;
 }