예제 #1
0
        protected void bindText(UI render, GameObject self, UIElementMeta meta, object context)
        {
            if (meta.Node.Attributes["bind"] != null)
            {
                string bind = meta.Node.Attributes ["bind"].Value;

                //If the bind is set to value, we presume the super structure contianing the ellement is handling the setting of the bindpath. Otherwise we pull the bind path.
                if (bind != "value")
                {
                    meta.BindPath = bind;
                }

                UIElementBinding binding = () => {
                    if (meta.BindPath != null)
                    {
                        string propName  = null;
                        int    propIndex = -1;

                        //Array indexed values are refed using #name:#index
                        int pos = meta.BindPath.IndexOf(":");
                        if (pos != -1)
                        {
                            propName  = meta.BindPath.Substring(0, pos);
                            propIndex = Convert.ToInt32(meta.BindPath.Substring(pos + 1, meta.BindPath.Length - (pos + 1)));
                        }
                        else
                        {
                            propName = meta.BindPath;
                        }

                        Type         type = context.GetType();
                        PropertyInfo info = type.GetProperty(propName);
                        if (info != null)
                        {
                            if (propIndex == -1)
                            {
                                meta.Text.text = info.GetValue(context, null).ToString();
                            }
                            else if (info.PropertyType.GetInterfaces().Contains(typeof(IList)))                           // Because I'm lazey, currently only implementing for lists
                            {
                                IList value = (IList)info.GetValue(context, null);
                                meta.Text.text = value [propIndex].ToString();
                            }
                            else
                            {
                                meta.Text.text = meta.Node.Value;
                            }
                        }
                        else
                        {
                            meta.Text.text = meta.Node.Value;
                        }
                    }
                };


                binding.Invoke();
                meta.UpdateBinding += binding;
            }
        }
예제 #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;
            }
        }
예제 #3
0
        protected void bindImg(UI render, GameObject self, UIElementMeta meta, object context)
        {
            if (meta.Node.Attributes["bindImage"] != null)
            {
                meta.Data = context;
                UIElementBinding binding = () => {
                    Type         type = context.GetType();
                    PropertyInfo info = type.GetProperty(meta.Node.Attributes["bindImage"].Value);

                    if (info != null)
                    {
                        if (info.PropertyType == typeof(Sprite))
                        {
                            meta.Image.sprite = (Sprite)info.GetValue(context, null);
                        }
                    }
                };

                binding.Invoke();
                meta.UpdateBinding += binding;
            }
        }
예제 #4
0
        protected void bindSlider(UI render, GameObject self, UIElementMeta meta, object context)
        {
            if (meta.Node.Attributes ["bind"] != null)
            {
                meta.Data = context;
                UIElementBinding binding = () => {
                    Type         type = context.GetType();
                    PropertyInfo info = type.GetProperty(meta.Node.Attributes["bind"].Value);
                    if (info != null)
                    {
                        float value = 0;
                        if (info.PropertyType == typeof(float))
                        {
                            value = (float)info.GetValue(context, null);
                        }

                        meta.Slider.normalizedValue = value;
                    }
                };

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