Example #1
0
        /// <summary>
        /// Convert custom attributes (that aren't found via reflection, e.g. width/height) into useable values
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        protected AttributeDictionary HandleCustomAttributes(AttributeDictionary attributes)
        {
            var elementName = XmlLayoutUtilities.GetTagName(GetType());
            //var elementName = this.GetType().Name.Replace("TagHandler", String.Empty);
            var customAttributes = attributes.Where(k => XmlLayoutUtilities.IsCustomAttribute(k.Key)).ToList();

            foreach (var attribute in customAttributes)
            {
                var customAttribute = XmlLayoutUtilities.GetCustomAttribute(attribute.Key);

                if (customAttribute.RestrictToPermittedElementsOnly)
                {
                    if (!customAttribute.PermittedElements.Contains(elementName, StringComparer.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                }

                if (customAttribute.UsesConvertMethod)
                {
                    attributes = XmlLayoutUtilities.MergeAttributes(
                        attributes,
                        customAttribute.Convert(attribute.Value, attributes.AsReadOnly(), this.currentXmlElement));
                }

                if (customAttribute.UsesApplyMethod)
                {
                    customAttribute.Apply(currentXmlElement, attribute.Value, attributes.AsReadOnly());
                }

                if (customAttribute.UsesApplyMethod && !defaultAttributeValues.ContainsKey(attribute.Key))
                {
                    defaultAttributeValues.Add(attribute.Key, customAttribute.DefaultValue);
                }

                if (!customAttribute.KeepOriginalTag)
                {
                    attributes.Remove(attribute.Key);
                }
            }

            return(attributes);
        }
Example #2
0
        public void ProcessCustomAttributes()
        {
            var customAttributes = XmlLayoutUtilities.GetGroupedCustomAttributeNames();

            foreach (var group in customAttributes)
            {
                var existingAttributes = GetAttributeGroup(group.Key);

                foreach (var attributeName in group.Value)
                {
                    var _attributeName = Char.ToLower(attributeName[0]) + attributeName.Substring(1);
                    var attribute      = XmlLayoutUtilities.GetCustomAttribute(attributeName);

                    if (attribute.RestrictToPermittedElementsOnly)
                    {
                        // add attribute to permitted elements
                        foreach (var element in attribute.PermittedElements)
                        {
                            if (!customAttributesToAddByElement.ContainsKey(element))
                            {
                                customAttributesToAddByElement.Add(element, new Dictionary <string, CustomXmlAttribute>());
                            }

                            customAttributesToAddByElement[element].Add(_attributeName, attribute);
                        }
                    }
                    else if (!existingAttributes.Contains(attributeName, StringComparer.OrdinalIgnoreCase))
                    {
                        // add attribute to group
                        if (!customAttributesToAddByGroup.ContainsKey(group.Key))
                        {
                            customAttributesToAddByGroup.Add(group.Key, new Dictionary <string, CustomXmlAttribute>());
                        }

                        customAttributesToAddByGroup[group.Key].Add(_attributeName, attribute);
                    }
                }
            }
        }
Example #3
0
        IEnumerator Preload_Internal()
        {
            var tagHandlerNames = XmlLayoutUtilities.GetXmlTagHandlerNames();

            var customAttributeNames = XmlLayoutUtilities.GetCustomAttributeNames();

            foreach (var tagHandlerName in tagHandlerNames)
            {
                // instantiate the tag handler (which will create an instance of it we can use later)
                var tagHandler = XmlLayoutUtilities.GetXmlTagHandler(tagHandlerName);

                // load the prefab (this will cache it)
                XmlLayoutUtilities.LoadResource <GameObject>(tagHandler.prefabPath);
            }

            foreach (var customAttributeName in customAttributeNames)
            {
                // Load the custom attribute (which will create an instance of it we can use later)
                XmlLayoutUtilities.GetCustomAttribute(customAttributeName);
            }

            yield return(null);
        }
Example #4
0
        void Preload_Internal()
        {
            var tagHandlerNames = XmlLayoutUtilities.GetXmlTagHandlerNames();

            var customAttributeNames = XmlLayoutUtilities.GetCustomAttributeNames();

            foreach (var tagHandlerName in tagHandlerNames)
            {
                // instantiate the tag handler (which will create an instance of it we can use later)
                var tagHandler = XmlLayoutUtilities.GetXmlTagHandler(tagHandlerName);

                // load the prefab (this will cache it)
                XmlLayoutUtilities.LoadResource <GameObject>(tagHandler.prefabPath);
            }

            foreach (var customAttributeName in customAttributeNames)
            {
                // Load the custom attribute (which will create an instance of it we can use later)
                XmlLayoutUtilities.GetCustomAttribute(customAttributeName);
            }

            /*foreach (var entry in XmlLayoutResourceDatabase.instance.entries)
             * {
             *  XmlLayoutResourceDatabase.instance.GetResource<UnityEngine.Object>(entry.path);
             * }
             *
             * var resourceDatabases = XmlLayoutResourceDatabase.instance.customResourceDatabases;
             *
             * foreach (var resourceDatabase in resourceDatabases)
             * {
             *  foreach(var entry in resourceDatabase.entries)
             *  {
             *      XmlLayoutResourceDatabase.instance.GetResource<UnityEngine.Object>(entry.path);
             *  }
             * }*/
        }
Example #5
0
        public void ProcessCustomAttributes()
        {
            var customAttributes = XmlLayoutUtilities.GetGroupedCustomAttributeNames();

            foreach (var group in customAttributes)
            {
                var existingAttributes = GetAttributeGroup(group.Key);

                foreach (var attribute in group.Value)
                {
                    if (!existingAttributes.Contains(attribute, StringComparer.OrdinalIgnoreCase))
                    {
                        if (!customAttributesToAdd.ContainsKey(group.Key))
                        {
                            customAttributesToAdd.Add(group.Key, new Dictionary <string, CustomXmlAttribute>());
                        }

                        customAttributesToAdd[group.Key].Add(Char.ToLower(attribute[0]) + attribute.Substring(1), XmlLayoutUtilities.GetCustomAttribute(attribute));
                    }
                }
            }
        }