public void AddbindableObjects(BindableContainer refer, UnityEngine.Component obj)
        {
            if (refer.children == null) //需要新增加
            {
                List <Binding> bindings = new List <Binding>();
                refer.children = new List <BindableObject>(); // bindings.ToArray ();
            }

            var            children = refer.children;
            BindableObject bindable = null;

            if (obj is BindableObject)
            {
                bindable = obj as BindableObject;
            }
            else
            {
                if (bindable == null)
                {
                    Component[] allcomps = obj.GetComponents <Component>(); //默认绑定最后一个组件
                    Component   target   = null;
                    int         index    = 0;
                    int         tpId     = -1;
                    foreach (var comp in allcomps)
                    {
                        if (comp is BindableObject)
                        {
                            bindable = (BindableObject)comp;
                            break;
                        }
                        else if ((index = BinderCheckTypes.IndexOf(comp.GetType())) >= 0)
                        {
                            target = comp;
                            tpId   = index;
                        }
                    }

                    if (bindable == null)
                    {
                        Type createBinderType = typeof(Hugula.Databinding.BindableObject);
                        if (tpId >= 0)
                        {
                            createBinderType = BinderCreateTypes[tpId];
                        }

                        bindable = (BindableObject)obj.gameObject.AddComponent(createBinderType);
                    }
                }
            }

            if (children.IndexOf(bindable) < 0)
            {
                refer.AddChild(bindable);
            }
        }
        public void AddbindableObjects(BindableContainer refer, UnityEngine.Component obj)
        {
            if (refer.children == null) //需要新增加
            {
                List <Binding> bindings = new List <Binding>();
                refer.children = new List <BindableObject>(); // bindings.ToArray ();
            }

            var            children = refer.children;
            BindableObject bindable = null;

            if (obj is BindableObject)
            {
                bindable = obj as BindableObject;
            }
            else
            {
                if (bindable == null)
                {
                    Component[] allcomps = obj.GetComponents <Component>(); //默认绑定最后一个组件
                    Component   target   = null;
                    Type        addType  = typeof(Hugula.Databinding.BindableObject);
                    Type        findType;
                    foreach (var comp in allcomps)
                    {
                        if (comp is BindableObject)
                        {
                            bindable = (BindableObject)comp;
                            break;
                        }
                        else if ((findType = BindalbeObjectUtilty.FindBinderType(comp.GetType())) != null)
                        {
                            target  = comp;
                            addType = findType;
                        }
                    }

                    if (bindable == null)
                    {
                        bindable = (BindableObject)obj.gameObject.AddComponent(addType);
                    }
                }
            }

            if (bindable != null && children.IndexOf(bindable) < 0)
            {
                refer.AddChild(bindable);
            }
        }
        // public void RemoveAtbindableObjects(BindableContainer refer, int index)
        // {
        //     var children = refer.children;
        //     children.RemoveAt(index);
        // }

        public void AddHierarchyChildren(Transform transform, BindableContainer container, bool checkChildren = false)
        {
            var children = transform.GetComponents <BindableObject>();


            var oldChildren = container.children;

            if (oldChildren == null)
            {
                oldChildren        = new List <BindableObject>();
                container.children = oldChildren;
            }

            bool needDeep = true;
            bool isSelf   = false;

            foreach (var child in children)
            {
                isSelf = System.Object.Equals(child, container);
                if (oldChildren.IndexOf(child) == -1 && !isSelf)
                {
                    container.AddChild(child);
                }

                if (!isSelf && (child is BindableContainer ||
                                child is LoopScrollRectBinder ||
                                child is LoopVerticalScrollRectBinder ||
                                child is CollectionViewBinder)) //如果遇到容器不需要遍历
                {
                    needDeep = false;
                }
            }

            if (needDeep)
            {
                for (int i = 0; i < transform.childCount; i++)
                {
                    AddHierarchyChildren(transform.GetChild(i), container);
                }
            }
        }
Beispiel #4
0
        public void AddHierarchyChildren(Transform transform, BindableContainer container, bool checkChildren = false)
        {
            var children = transform.GetComponents <BindableObject>();


            var oldChildren = container.children;

            if (oldChildren == null)
            {
                oldChildren        = new List <BindableObject>();
                container.children = oldChildren;
            }

            bool needDeep = true;

            foreach (var child in children)
            {
                if (oldChildren.IndexOf(child) == -1 && !System.Object.Equals(child, container))
                {
                    container.AddChild(child);
                }

                if (child is BindableContainer && !checkChildren) //如果遇到容器不需要遍历
                {
                    needDeep = false;
                }
            }

            if (needDeep)
            {
                for (int i = 0; i < transform.childCount; i++)
                {
                    AddHierarchyChildren(transform.GetChild(i), container);
                }
            }
        }
Beispiel #5
0
        public void AddbindableObjects(BindableContainer refer, UnityEngine.Component obj)
        {
            if (refer.children == null) //需要新增加
            {
                List <Binding> bindings = new List <Binding> ();
                // if (refer.bindableObjects != null) bindings.AddRange (refer.bindableObjects);
                // if (i == -1) i = bindings.Count;
                // while (bindings.Count <= i)
                //     bindings.Add (new Binding () { expression = @"{}" });

                refer.children = new List <BindableObject> (); // bindings.ToArray ();
                // Debug.Log (bindings.Count);
            }

            var            children = refer.children;
            BindableObject bindable = null;

            if (obj is BindableObject)
            {
                bindable = obj as BindableObject;
                // bindable.target = obj;
            }
            else
            {
                // BindableObject bindable = obj.<BindableObject> ();

                if (bindable == null)
                {
                    Component[] allcomps = obj.GetComponents <Component> (); //默认绑定最后一个组件
                    Component   target   = null;
                    int         index    = 0;
                    int         tpId     = -1;
                    foreach (var comp in allcomps)
                    {
                        if (comp is BindableObject)
                        {
                            bindable = (BindableObject)comp;
                            break;
                        }
                        else if ((index = BinderCheckTypes.IndexOf(comp.GetType())) >= 0)
                        {
                            target = comp;
                            tpId   = index;
                        }
                    }

                    if (bindable == null)
                    {
                        Type createBinderType = typeof(Hugula.Databinding.Binder.UIBehaviourBinder);
                        if (tpId >= 0)
                        {
                            createBinderType = BinderCreateTypes[tpId];
                        }

                        bindable        = (BindableObject)obj.gameObject.AddComponent(createBinderType);
                        bindable.target = target;
                    }
                }
            }

            bindable.targetName = obj.name;
            // bindable.binderType = GetBinderType (bindable.target.GetType ());
            if (children.IndexOf(bindable) < 0)
            {
                refer.AddChild(bindable);
            }

            // Binding binditem = bindableObjects[i];
            // binditem.target = obj;
            // if (obj) {
            //     binditem.binderType = GetBinderType (obj.GetType ());
            //     binditem.targetName = obj.name.Trim ();
            // }
        }