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; } }
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; } }
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; } }