public bool ApplyStyleDataToTarget(BaseStyleElement p_target, StyleData p_styleData) { if (p_target != null) { var v_template = p_styleData != null ? p_styleData.Asset : null; if (v_template != null) { var v_excludedElementsList = new List <string>(p_target.DisabledFieldStyles); v_excludedElementsList.AddRange(v_template.DisabledFieldStyles); return(ApplyTemplateToTarget(p_target, v_template, v_excludedElementsList)); } } return(false); }
//Only add Color or Graphic Assets (Sprite/Font/TMP_Font/VectorImageData/Texture2D) public HashSet <object> CollectStyleResources(object p_target, HashSet <BaseStyleElement> p_excludedElements = null) { var v_targetAsBaseStyleElement = p_target as BaseStyleElement; if (p_excludedElements == null) { p_excludedElements = new HashSet <BaseStyleElement>(); } HashSet <object> v_resourcesList = new HashSet <object>(); if (p_target != null && (v_targetAsBaseStyleElement == null || !p_excludedElements.Contains(v_targetAsBaseStyleElement))) { //Prevent circular references adding self to ExcludeHash if (v_targetAsBaseStyleElement != null) { p_excludedElements.Add(v_targetAsBaseStyleElement); } var v_members = GetMembers(); foreach (var v_pair in v_members) { var v_member = v_pair.Value; if (v_member.HasGetDelegate()) { var v_value = v_member.GetValue(p_target); if (v_member.IsType <BaseStyleElement>()) { BaseStyleElement v_element = v_value as BaseStyleElement; if (v_element != null && !p_excludedElements.Contains(v_element)) { p_excludedElements.Add(v_element); //Collect resouces checking if not previous collected the resources var v_internalResources = v_element.CollectStyleResources(p_excludedElements); foreach (var v_resource in v_internalResources) { v_resourcesList.Add(v_element); } } } if (v_member.IsType <Graphic>()) { object v_resourceAsset = StyleUtils.GetStyleResource(v_value as Graphic); if (v_resourceAsset is VectorImageData || ((v_resourceAsset is Object) && ((Object)v_resourceAsset) != null) ) { v_resourcesList.Add(v_resourceAsset); } } else if (v_member.IsType <Color>() || v_member.IsType <Color32>()) { Color32 v_resourceColor = v_value is Color ? (Color32)((Color)v_value) : (v_value is Color32 ? (Color32)v_value : default(Color32)); v_resourceColor = StyleUtils.GetStyleColor(v_resourceColor); v_resourcesList.Add(v_resourceColor); } } } } return(v_resourcesList); }