Example #1
0
        private UIElementMeta _renderNode(XmlNode node, Transform parent, object context)
        {
            if (this._handlers.ContainsKey(node.Name))
            {
                UIElementMeta k = _handlers [node.Name].Make(this, node, parent, context);
                this._selection.Add(k);
                this._ellements.Add(k);

                if (k.ContinueRenderChildren)
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        if (k.Object != null)
                        {
                            k.AddChild(_renderNode(childNode, k.Object.transform, context));
                        }
                    }
                }
                return(k);
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        protected void foreachChild(UI render, GameObject self, UIElementMeta meta, object context)
        {
            if (meta.Node.Attributes["foreach"] != null)
            {
                UIElementBinding binding = () => {
                    meta.ContinueRenderChildren = false;

                    string       propName = meta.Node.Attributes ["foreach"].Value;
                    Type         t        = context.GetType();
                    PropertyInfo prop     = t.GetProperty(propName);

                    if (prop != null)
                    {
                        if (prop.PropertyType.GetInterfaces().Contains(typeof(IList)))
                        {
                            IList data = (IList)prop.GetValue(context, null);

                            /* Create needed ellements */
                            if (meta.Object.transform.childCount < data.Count)
                            {
                                int needed = data.Count - meta.Object.transform.childCount;
                                for (int i = 0; i < needed; i++)
                                {
                                    foreach (XmlNode child in meta.Node.ChildNodes)
                                    {
                                        meta.AddChild(render.Render(child, self.transform, context));
                                    }
                                }
                            }

                            //Toggle on ellements that we'll be using, disable the ones we won't be using
                            int ellementsNeeded         = 0;
                            List <UIElementMeta> active = new List <UIElementMeta> ();
                            foreach (UIElementMeta child in meta)
                            {
                                //Enable ellements
                                if (ellementsNeeded < data.Count)
                                {
                                    child.Object.SetActive(true);
                                    child.BindPath = propName;
                                    active.Add(child);
                                }
                                else                                     //Disable elements
                                {
                                    child.Object.SetActive(false);
                                }
                                ellementsNeeded++;
                            }

                            //Layout enabled ellements
                            this.groupLayout(active);
                        }
                    }
                };

                binding.Invoke();
                meta.UpdateBinding += binding;
            }
        }