コード例 #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 (button != null)
            {
                sprites = type == "background" ? button.backgroundSprites : button.foregroundSprites;
            }

            if (sprites != null && 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
                {
                    if (sprites != null)
                    {
                        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), 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;
                }
                if (ConfigManager.IgnoreMissingComponents)
                {
                    Debug.LogWarning(string.Format("Component: {0} doesn't contain {1} - node: {3}", setNode.Name, component, node));
                    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;

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