Пример #1
0
 public void BindAttrs(XmlLayoutElement element, BoundAttributeCollection collection)
 {
     for (var i = 0; i < objectBuildActions.Count; i++)
     {
         objectBuildActions[i](element, collection);
     }
 }
Пример #2
0
            public XmlLayoutElement CreateElement(Transform parent, BoundAttributeCollection binders,
                                                  LayoutInflater inflater, Dictionary <string, string> outerAttrs)
            {
                var element = parentElement.CreateObject(parent, binders, inflater, outerAttrs);

                element.RectTransform.anchorMin = new Vector2(0, 1);  // Top left
                element.RectTransform.anchorMax = new Vector2(0, 1);
                element.RectTransform.pivot     = new Vector2(0, 1f); // Center
                element.gameObject.name         = gameObjectName;

                return(element);
            }
Пример #3
0
        protected override XmlLayoutElement CreateObject(Transform parent, BoundAttributeCollection binder,
                                                         LayoutInflater inflater, Dictionary <string, string> outerAttrs)
        {
            var element = inflater.Inflate(parent, documentXml, null, outerAttrs);

            if (element.TryGetComponent <ComponentVariableBinder>(out var addedBinder))
            {
                binder.AddChild(addedBinder);
            }

            return(element);
        }
Пример #4
0
        public void SetBoundAttrs(BoundAttributeCollection attributes)
        {
            attributeCollection?.UnbindFromProvider();
            attributeCollection = attributes;

            attributeCollection.ApplyConstants();

            if (variableProvider != null)
            {
                attributeCollection?.BindToProvider(variableProvider);
            }
        }
Пример #5
0
        protected override XmlLayoutElement CreateObject(Transform parent, BoundAttributeCollection binder,
                                                         LayoutInflater inflater, Dictionary <string, string> outerAttrs)
        {
            var gameObject = new GameObject();

            if (parent is RectTransform)
            {
                gameObject.AddComponent <RectTransform>();
            }

            gameObject.transform.SetParent(parent, false);

            return(gameObject.AddComponent <XmlLayoutElement>());
        }
Пример #6
0
        public XmlLayoutElement CreateXmlInstance(Transform root, string xmlString,
                                                  Dictionary <string, string> outerAttrs)
        {
            Init();

            var rootNode   = ParseXmlElements(xmlString, outerAttrs);
            var boundAttrs = new BoundAttributeCollection();
            var newPrefab  = CreateInstance(null, root, rootNode, boundAttrs);

            newPrefab.DeactivateHierarchy();

            if (!boundAttrs.IsEmpty)
            {
                newPrefab.gameObject.AddComponent <ComponentVariableBinder>()
                .SetBoundAttrs(boundAttrs);
            }

            return(newPrefab);
        }
Пример #7
0
        private XmlLayoutElement CreateInstance(XmlLayoutElement elementRoot, Transform root,
                                                ElementNode element, BoundAttributeCollection binders)
        {
            var instance  = element.factory.CreateElement(root, binders, this, element.ownAttrs);
            var container = instance.Container;

            if (!elementRoot)
            {
                elementRoot = instance;
            }

            for (var i = 0; i < element.childNodes.Count; i++)
            {
                var node = element.childNodes[i];

                switch (node.type)
                {
                case XmlUIUtils.AttrsChildRootName:
                    elementRoot.Container = instance;
                    break;

                default:
                    var childInstance = CreateInstance(elementRoot, container.ChildParentTransform, node, binders);
                    container.AddChild(childInstance);
                    break;
                }
            }

            element.factory.BindAttrs(instance, binders);

            foreach (var c in element.components)
            {
                c.BindAttrs(instance, binders);
            }

            instance.OnCreatedFromXml();
            return(instance);
        }
Пример #8
0
 protected abstract XmlLayoutElement CreateObject(Transform parent, BoundAttributeCollection binder,
                                                  LayoutInflater inflater, Dictionary <string, string> outerAttrs);
Пример #9
0
 protected override XmlLayoutElement CreateObject(Transform parent, BoundAttributeCollection binder,
                                                  LayoutInflater inflater, Dictionary <string, string> outerAttrs)
 {
     return(Object.Instantiate(prefabElement, parent, false));
 }