public void SetAttribute(string attribute, string value) { if (attribute == "class") { Debug.LogWarning("[XmlLayout][XmlElement][SetAttribute]:: Please use 'SetClass', 'AddClass', and/or 'RemoveClass' to manipulate the class attribute."); return; } if (HasAttribute(attribute)) { attributes[attribute] = value; } else { attributes.Add(attribute, value); elementAttributes.Add(attribute); } }
protected void ClassRemoved(params string[] classesRemoved) { if (!xmlLayout.defaultAttributeValues.ContainsKey(this.tagType)) { return; } List <string> attributesReset = new List <string>(); foreach (var classRemoved in classesRemoved) { if (!xmlLayout.defaultAttributeValues[this.tagType].ContainsKey(classRemoved)) { continue; } var attributesDefinedByClass = xmlLayout.defaultAttributeValues[this.tagType][classRemoved].Select(a => a.Key).ToList(); // add all attributes defined by this class that are not defined by the element attributesReset.AddRange(attributesDefinedByClass.Where(a => !elementAttributes.Contains(a))); } if (!attributesReset.Any()) { return; } var _classes = classes; _classes.Insert(0, "all"); // remove any attributes covered by other classes (no need to reset them) foreach (var _class in _classes) { if (!xmlLayout.defaultAttributeValues[this.tagType].ContainsKey(_class)) { continue; } var attributesDefinedByClass = xmlLayout.defaultAttributeValues[this.tagType][_class].Select(a => a.Key).ToList(); attributesReset.RemoveAll(a => attributesDefinedByClass.Contains(a)); } if (attributesReset.Any()) { // Now for the hard part: we need to determine the default values for these attributes AttributeDictionary defaultAttributesToApply = new AttributeDictionary(); foreach (var attributeToReset in attributesReset) { var value = tagHandler.GetDefaultValueForAttribute(attributeToReset); defaultAttributesToApply.Add(attributeToReset, value); } if (defaultAttributesToApply.Any()) { ApplyAttributes(defaultAttributesToApply); } } }
public XmlLayoutAnimation(AttributeDictionary attributes) { if (attributes.ContainsKey("type")) { type = (eAnimationType)Enum.Parse(typeof(eAnimationType), attributes["type"]); } if (attributes.ContainsKey("attribute")) { attribute = attributes["attribute"]; } if (attributes.ContainsKey("duration")) { duration = attributes["duration"].ToFloat(); } if (attributes.ContainsKey("animations")) { animations = attributes["animations"].ToClassList(); } if (!attributes.ContainsKey("valueType")) { attributes.Add("valueType", "float"); } switch (attributes["valueType"]) { case "float": valueType = typeof(float); break; case "Vector2": valueType = typeof(Vector2); break; case "Vector3": valueType = typeof(Vector3); break; case "Color": valueType = typeof(Color); break; } if (attributes.ContainsKey("to")) { valueTo = attributes["to"].ChangeToType(valueType); } if (attributes.ContainsKey("from")) { valueFrom = attributes["from"].ChangeToType(valueType); hasValueFrom = true; } if (attributes.ContainsKey("curve")) { curve = attributes["curve"]; } }