Ejemplo n.º 1
0
 public virtual void Apply(XmlElement xmlElement, string value, AttributeDictionary attributes)
 {
 }
Ejemplo n.º 2
0
 public virtual AttributeDictionary Convert(string value, AttributeDictionary attributes, XmlElement xmlElement)
 {
     return(null);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Called when the tag is opened
 /// </summary>
 public virtual void Open(AttributeDictionary elementAttributes)
 {
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Apply the specified attributes to the XmlElement (and its other relevant components)
        /// </summary>
        /// <param name="attributesToApply"></param>
        public virtual void ApplyAttributes(AttributeDictionary attributesToApply)
        {
            if (currentInstanceTransform == null || currentXmlLayoutInstance == null)
            {
                Debug.LogWarning("[XmlLayout][Warning] Please call ElementTagHandler.SetInstance() before using XmlElement.ApplyAttributes()");
                return;
            }

            //var startTime = DateTime.Now;
            attributesToApply = HandleCustomAttributes(attributesToApply);
            var _primaryComponent = primaryComponent;

            // the vast majority of events require the element to block raycasts, so rather than expecting the users to set this value every time,
            // lets set it here
            if (attributesToApply.Any(a => !String.Equals("onValueChanged", a.Key, StringComparison.OrdinalIgnoreCase) && eventAttributeNames.Contains(a.Key, StringComparer.OrdinalIgnoreCase)))
            {
                attributesToApply.AddIfKeyNotExists("raycastTarget", "true");
            }

            if (attributesToApply.ContainsKey("allowDragging") && attributesToApply["allowDragging"].ToBoolean())
            {
                var dragEventHandler = currentXmlElement.GetComponent <XmlLayoutDragEventHandler>();
                if (dragEventHandler == null)
                {
                    currentXmlElement.gameObject.AddComponent <XmlLayoutDragEventHandler>();
                }
            }

            foreach (var attribute in attributesToApply)
            {
                string name  = attribute.Key;
                string value = attribute.Value;

                if (eventAttributeNames.Contains(name, StringComparer.OrdinalIgnoreCase))
                {
                    // As it happens, events don't work anyway unless they are processed at runtime (which is why we have 'ForceRebuildOnAwake')
                    // so we may as well not process any event attributes at all in edit mode
                    // (this also helps avoid triggering event handlers in edit mode)
                    if (Application.isPlaying)
                    {
                        HandleEventAttribute(name, value);
                    }
                    continue;
                }

                var propertySetOnComponent = _primaryComponent != null?SetPropertyValue(_primaryComponent, name, value) : false;

                // if we failed to set the property on the component, perhaps it is a transform value instead
                if (!propertySetOnComponent)
                {
                    var propertySetOnTransform = SetPropertyValue(currentInstanceTransform, name, value);

                    // perhaps it is a layout value
                    if (!propertySetOnTransform)
                    {
                        var propertySetOnLayoutComponent = SetPropertyValue(layoutElement, name, value);

                        // or, perhaps it is an image value
                        if (!propertySetOnLayoutComponent)
                        {
                            // lastly, check the XmlElement
                            var propertySetOnXmlElement = SetPropertyValue(currentXmlElement, name, value);

                            if (!propertySetOnXmlElement)
                            {
                                var _imageComponent = imageComponent;
                                if (_imageComponent != null)
                                {
                                    SetPropertyValue(imageComponent, name, value);
                                }
                            }
                        }
                    }
                }
            }

#if !ENABLE_IL2CPP
            if (!dontCallHandleDataSourceAttributeAutomatically && attributesToApply.ContainsKey("vm-dataSource"))
            {
                HandleDataSourceAttribute(attributesToApply["vm-dataSource"]);
            }
#endif
        }
 public ReadOnlyAttributeDictionary(AttributeDictionary dictionary)
 {
     this.dictionary = dictionary;
 }
        public static AttributeDictionary MergeAttributes(AttributeDictionary defaults, AttributeDictionary elementAttributes)
        {
            var result = defaults.Clone();

            if (elementAttributes == null)
            {
                return(result);
            }

            foreach (var attribute in elementAttributes)
            {
                if (!result.ContainsKey(attribute.Key))
                {
                    result.Add(attribute.Key, attribute.Value);
                }
                else
                {
                    result[attribute.Key] = attribute.Value;
                }
            }

            return(result);
        }