コード例 #1
0
        private void ApplyUIMultiStateButtonSpriteStateProperty(XmlNode node, UIComponent component)
        {
            var index = XmlUtil.GetIntAttribute(node, "index");

            var type = XmlUtil.GetStringAttribute(node, "type");
            if (type != "background" && type != "foreground")
            {
                throw new ParseException(String.Format
                    ("Invalid value for SpriteState attribute \"type\" (only \"foreground\" and \"background\" are allowed - \"{0}\"",
                        index), node);
            }

            var button = component as UIMultiStateButton;
            UIMultiStateButton.SpriteSetState sprites = null;

            if (type == "background")
            {
                sprites = button.backgroundSprites;
            }
            else
            {
                sprites = button.foregroundSprites;
            }

            if (index >= sprites.Count)
            {
                throw new ParseException(String.Format
                ("Invalid value for SpriteState attribute \"index\", object has only \"{1}\" states - \"{0}\"",
                   index, sprites.Count), node);
            }

            foreach (XmlNode stateNode in node.ChildNodes)
            {
                try
                {
                    var property = ReflectionCache.GetPropertyForType(sprites[index].GetType(), stateNode.Name);
                    if (property == null)
                    {
                        throw new ParseException(String.Format
                        ("Invalid property \"{0}\" for SpriteState, allowed are \"normal\", \"hovered\", \"focused\", \"pressed\", \"disabled\"",
                            stateNode.InnerText), node);
                    }

                    SetPropertyValueWithRollback(sprites[index], property, stateNode.InnerText);
                }
                catch (Exception ex)
                {
                    throw new ParseException(String.Format
                        ("Exception while processing SpriteState node - {0}",
                            ex.ToString()), node);
                }
            }
        }
コード例 #2
0
        private void SetPropertyValue(XmlNode setNode, XmlNode node, UIComponent component, bool optional, bool rollback)
        {
            var property = ReflectionCache.GetPropertyForType(component.GetType(), setNode.Name);

            if (property == null)
            {
                if (optional)
                {
                    return;
                }

                throw new MissingComponentPropertyException(setNode.Name, component, node);
            }

            if (!property.CanWrite)
            {
                throw new ParseException(String.Format("Property \"{0}\" of component \"{1}\" is read-only", property.Name, component.name), setNode);
            }

            object value = null;

            bool raw = XmlUtil.TryGetBoolAttribute(setNode, "raw");

            if (property.PropertyType == typeof(Color32) && !raw)
            {
                value = skin.GetNamedColor(setNode.InnerText);
            }
            else
            {
                value = XmlUtil.GetValueForType(setNode, property.PropertyType, setNode.InnerText, skin.spriteAtlases);
            }

            if (rollback)
            {
                SetPropertyValueWithRollback(component, property, value);
            }
            else
            {
                SetPropertyValue(component, property, value);
            }
        }