示例#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 imageRenderMode(UI render, GameObject self, UIElementMeta meta, object context)
 {
     if (meta.Node.Attributes["renderMode"] != null)
     {
         meta.Image.type = (Image.Type)Enum.Parse(typeof(Image.Type), meta.Node.Attributes["renderMode"].Value);
     }
 }
示例#3
0
 protected void textFontSize(UI render, GameObject self, UIElementMeta meta, object context)
 {
     if (meta.Node.Attributes["size"] != null)
     {
         meta.Text.fontSize = Convert.ToInt32(meta.Node.Attributes ["size"].Value);
     }
 }
示例#4
0
        /*End Text*/

        /*Start Image*/

        protected void imageColor(UI render, GameObject self, UIElementMeta meta, object context)
        {
            if (meta.Node.Attributes["color"] != null)
            {
                meta.Image.color = this.readColor(meta.Node.Attributes ["color"].Value);
            }
        }
示例#5
0
 protected void textMaterial(UI render, GameObject self, UIElementMeta meta, object context)
 {
     if (meta.Node.Attributes["material"] != null && UIAssets.Self != null)
     {
         meta.Text.material = UIAssets.Self.Materials.Find(x => x.name == meta.Node.Attributes["material"].Value);
     }
 }
示例#6
0
        //Calculate the positioning of an ellement
        protected void position(UI renderer, GameObject self, UIElementMeta meta, object context)
        {
            Vector2 min = Vector2.zero;
            Vector2 max = Vector2.one;

            //If the min and max fields have been set use them, otherwise default to fullscreen
            if (meta.Node.Attributes["min"] != null)
            {
                min = readCord(meta.Node.Attributes["min"].Value);
            }

            if (meta.Node.Attributes["max"] != null)
            {
                max = readCord(meta.Node.Attributes ["max"].Value);
            }

            meta.Rect.anchorMin = min;
            meta.Rect.anchorMax = max;

            meta.Rect.localScale = Vector3.one;
            meta.Rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 1);
            meta.Rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 1);
            meta.Rect.offsetMin = Vector2.zero;
            meta.Rect.offsetMax = Vector2.zero;
        }
示例#7
0
 protected void dragRecieveInit(UI render, GameObject self, UIElementMeta meta, object context)
 {
     if (meta.Node.Attributes ["recieveDrag"] != null)
     {
         DragableRecieve recieve = meta.DragableRecieve;
     }
 }
示例#8
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);
            }
        }
示例#9
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;
            }
        }
示例#10
0
        /*End Image*/

        /*Start Drag*/

        protected void dragInit(UI render, GameObject self, UIElementMeta meta, object context)
        {
            if (meta.Node.Attributes ["dragable"] != null)
            {
                Dragable drag = meta.Dragable;
                drag.Meta = meta;
            }
        }
示例#11
0
 /* Start Binding */
 protected void attachView(UI render, GameObject self, UIElementMeta meta, object context)
 {
     if (context.GetType().GetInterfaces().Contains(typeof(IUIBindable)) && meta.Node.ParentNode == null)
     {
         IUIBindable bindable = (IUIBindable)context;
         bindable.View = meta;
     }
 }
示例#12
0
 protected void textFont(UI render, GameObject self, UIElementMeta meta, object context)
 {
     if (meta.Node.Attributes["font"] != null && UIAssets.Self != null)
     {
         Font font = UIAssets.Self.Fonts.Find(x => x.name == meta.Node.Attributes ["font"].Value);
         if (font != null)
         {
             meta.Text.font = font;
         }
     }
 }
示例#13
0
        /*End Binding*/

        /*Start Slider*/
        protected void sliderInit(UI render, GameObject self, UIElementMeta meta, object context)
        {
            meta.Slider.fillRect.anchorMin = Vector2.zero;
            meta.Slider.fillRect.anchorMax = Vector2.one;

            meta.Slider.fillRect.localScale = Vector3.one;
            meta.Slider.fillRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 1);
            meta.Slider.fillRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 1);
            meta.Slider.fillRect.offsetMin = Vector2.zero;
            meta.Slider.fillRect.offsetMax = Vector2.zero;
        }
示例#14
0
 protected void bindClick(UI render, GameObject self, UIElementMeta meta, object context)
 {
     if (meta.Node.Attributes["onClick"] != null)
     {
         meta.Data = context;
         meta.Button.onClick.AddListener(() => {
             Type type       = context.GetType();
             MethodInfo info = type.GetMethod(meta.Node.Attributes["onClick"].Value);
             if (info != null)
             {
                 info.Invoke(context, null);
             }
         });
     }
 }
示例#15
0
 protected void imgBackground(UI render, GameObject self, UIElementMeta meta, object context)
 {
     if (meta.Node.Attributes["image"] != null && UIAssets.Self != null)
     {
         if (meta.Node.Attributes ["image"].Value.IndexOf("$") == 0)
         {
         }
         else
         {
             Sprite s = UIAssets.Self.Images.Find(x => x.name == meta.Node.Attributes ["image"].Value);
             if (s != null)
             {
                 meta.Image.sprite = s;
             }
         }
     }
 }
示例#16
0
        /*End Drag*/

        /*Verbs*/

        protected void show(UI render, GameObject self, UIElementMeta meta, object context)
        {
            if (meta.Node.Attributes["show"] != null)
            {
                meta.UpdateBinding += () => {
                    Type         type = context.GetType();
                    PropertyInfo info = type.GetProperty(meta.Node.Attributes["show"].Value);
                    if (info != null)
                    {
                        if (info.PropertyType == typeof(bool))
                        {
                            self.SetActive((bool)info.GetValue(context, null));
                        }
                    }
                };
            }
        }
示例#17
0
        //Creates ellement
        public UIElementMeta Make(UI ui, XmlNode node, Transform parent, object context)
        {
            //Filter Attributes
            string tags = this._name;

            //Creating object.
            GameObject g = new GameObject(this._name);

            g.transform.parent = parent;

            UIElementMeta meta = new UIElementMeta(g, node, tags);

            if (this.Builder != null)
            {
                this.Builder(ui, g, meta, context);
            }

            return(meta);
        }
示例#18
0
        private void _render(string xml, object context)
        {
            if (!String.IsNullOrEmpty(xml))
            {
                this._selection = new List <UIElementMeta> ();
                UIElementMeta root = null;

                XmlReader   reader   = XmlReader.Create(new StringReader(xml));
                XmlDocument document = new XmlDocument();
                while (reader.Read())
                {
                    if (!String.IsNullOrEmpty(reader.Name))
                    {
                        root = this._renderNode(document.ReadNode(reader), this._root, context);
                    }
                }

                root.Update();
            }
        }
示例#19
0
        protected void dragRecieveBind(UI render, GameObject self, UIElementMeta meta, object context)
        {
            if (meta.Node.Attributes ["recieveDragBind"] != null)
            {
                string name = meta.Node.Attributes["recieveDragBind"].Value;

                UIElementBinding bind = () => {;
                                               DragRecieve del = (DragRecieve)Delegate.CreateDelegate(typeof(DragRecieve), context, name);
                                               if (del != null)
                                               {
                                                   meta.DragableRecieve.Dragable += del;
                                               }
                                               else
                                               {
                                                   Debug.LogError("Method " + name + " does not match delegate DragRecieve");
                                               } };

                meta.UpdateBinding += bind;
            }
        }
示例#20
0
        protected void bindDiv(UI render, GameObject self, UIElementMeta meta, object context)
        {
            if (meta.Node.Attributes ["bind"] != null)
            {
                UIElementBinding bind = () => {
                    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 (info.PropertyType.GetInterfaces().Contains(typeof(IList)) && propIndex != -1)                          // Because I'm lazey, currently only implementing for lists
                            {
                                IList value = (IList)info.GetValue(context, null);
                                meta.Data = value [propIndex];
                                return;
                            }
                        }

                        meta.Data = null;
                    }
                };
                meta.UpdateBinding += bind;
            }
        }
示例#21
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;
            }
        }
示例#22
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;
            }
        }
示例#23
0
        /*End Slider*/

        /*Start Text*/
        protected void txtDefaultValue(UI render, GameObject self, UIElementMeta meta, object context)
        {
            meta.Text.text = meta.Node.InnerText;
        }