Пример #1
0
        public virtual StyleData GetStyleDataTemplate(bool p_force = false)
        {
            if (m_styleGroup != null &&
                (_styleData == null || p_force ||
                 (!string.IsNullOrEmpty(m_styleDataName) && _styleData.Name != m_styleDataName)))
            {
                if (m_supportStyleGroup)
                {
                    if (!string.IsNullOrEmpty(m_styleDataName) && m_styleGroup.TryGetStyleData(m_styleDataName, GetSupportedStyleAssetType(), out _styleData))
                    {
                        //Clone StyleData to prevent references to StyleSheetAsset
                        _styleData = _styleData != null ? new StyleData(_styleData.Name, _styleData.Asset) : new StyleData();
                    }
                    else
                    {
                        //Prevent try find null asset again (we only recalculate if StyleData is Null)
                        _styleData = new StyleData();
                    }
                }
                else
                {
                    _styleData = null;
                }

                return(_styleData);
            }

            if (!m_supportStyleGroup || m_styleGroup == null)
            {
                _styleData = null;
            }

            return(_styleData);
        }
Пример #2
0
 protected internal bool IsSupportedStyleData(StyleData p_styleData)
 {
     if (p_styleData != null && p_styleData.Asset != null)
     {
         return(IsSupportedStyleElement(p_styleData.Asset));
     }
     return(false);
 }
Пример #3
0
 protected internal bool UnregisterFromStyleGroup()
 {
     if (m_styleGroup != null)
     {
         _styleData = null;
         var v_sucess = m_styleGroup.UnregisterStyleBehaviour(this);
         m_styleGroup = null;
         return(v_sucess);
     }
     return(false);
 }
Пример #4
0
        protected override bool OnLoadStyles(StyleData p_styleData)
        {
            var sucess = base.OnLoadStyles(p_styleData);

            if (sucess)
            {
                UpdateColorToggleState(false);
                UpdateGraphicToggleState();
            }
            return(sucess);
        }
Пример #5
0
 public bool TryGetStyleData(string p_name, System.Type p_acceptedType, out StyleData p_style)
 {
     if (m_styleAsset != null)
     {
         return(m_styleAsset.TryGetStyleData(p_name, p_acceptedType, out p_style));
     }
     else
     {
         p_style = null;
         return(false);
     }
 }
Пример #6
0
        protected virtual bool LoadGenericStyles(StyleData p_styleData)
        {
            //Cache StyleData Asset
            _styleData = p_styleData;

            var v_template = p_styleData != null ? p_styleData.Asset : null;

            if (v_template != null)
            {
                Dictionary <string, StyleProperty>[] v_otherStyleMaps = new Dictionary <string, StyleProperty>[] { v_template.ExtraStylePropertiesMap };
                Dictionary <string, StyleProperty>[] v_selfStyleMaps  = new Dictionary <string, StyleProperty>[] { ExtraStylePropertiesMap };

                for (int i = 0; i < v_otherStyleMaps.Length; i++)
                {
                    //Apply Style Properties
                    foreach (var v_pair in v_otherStyleMaps[i])
                    {
                        StyleProperty v_selfStyleProperty = null;
                        v_selfStyleMaps[i].TryGetValue(v_pair.Key, out v_selfStyleProperty);
                        if (v_selfStyleProperty != null && v_pair.Value != null)
                        {
                            var v_otherStyleProperty = v_pair.Value;
                            v_selfStyleProperty.LoadStyles(v_otherStyleProperty);


                            //Disable/Enable GameObject based in Template (prevent apply if selfStyleProperty.Target is self transform)
                            if (v_selfStyleProperty.Target != this.transform && v_selfStyleProperty.Target != null && v_otherStyleProperty.Target != null)
                            {
                                StyleUtils.ApplyObjectActive(v_selfStyleProperty.Target, v_otherStyleProperty.Target);
                            }

                            //Apply Graphic if Supported
                            if (v_selfStyleProperty.UseStyleGraphic)
                            {
                                StyleUtils.ApplyGraphic(v_selfStyleProperty.Target, v_otherStyleProperty.Target);
                            }
                        }
                    }
                }

                var v_metaType = StyleMetaType.GetOrCreateStyleMetaType(GetType());
                v_metaType.ApplyStyleDataToTarget(this, p_styleData);

#if UNITY_EDITOR
                UnityEditor.EditorUtility.SetDirty(this);
#endif

                return(true);
            }
            return(false);
        }
Пример #7
0
        public bool TryGetStyleData(string p_name, System.Type p_acceptedType, out StyleData p_style)
        {
            StyleObjectsMap.TryGetValue(p_name, out p_style);

            if (p_acceptedType != null && p_style != null && p_style.Asset != null)
            {
                var v_type = p_style.Asset.GetType();
                if (p_acceptedType != v_type && !v_type.IsSubclassOf(p_acceptedType))
                {
                    p_style = null;
                }
            }
            return(p_style != null);
        }
Пример #8
0
        protected internal bool RegisterToStyleGroup(bool p_force = false)
        {
            if (SupportStyleGroup)
            {
                if (m_styleGroup == null || p_force)
                {
                    var v_styleGroup = GetComponentInParent <CanvasStyleGroup>();
                    _styleData = null;
                    if (m_styleGroup != null)
                    {
                        UnregisterFromStyleGroup();
                    }
                    m_styleGroup = v_styleGroup;
                }

                if (m_styleGroup != null)
                {
                    return(m_styleGroup.RegisterStyleBehaviour(this));
                }
            }
            return(false);
        }
Пример #9
0
 protected virtual bool OnLoadStyles(StyleData p_styleData)
 {
     return(LoadGenericStyles(p_styleData));
 }
Пример #10
0
 public bool TryGetStyleData(string p_name, out StyleData p_style)
 {
     return(TryGetStyleData(p_name, null, out p_style));
 }
Пример #11
0
        public bool TryGetStyleDataOrFirstValid(string p_name, System.Type p_acceptedType, out StyleData p_style)
        {
            TryGetStyleData(p_name, p_acceptedType, out p_style);

            var v_type = p_style != null?p_style.Asset.GetType() : null;

            if (p_acceptedType != null && (p_style == null || v_type != null))
            {
                //Find First Valid of the type
                if (p_style == null || (p_acceptedType != v_type && !v_type.IsSubclassOf(p_acceptedType)))
                {
                    p_style = null;
                    foreach (var v_style in m_styles)
                    {
                        if (v_style != null)
                        {
                            var v_styleValueType = v_style.Asset != null?v_style.Asset.GetType() : null;

                            if (v_styleValueType == null || (p_acceptedType == v_styleValueType || v_styleValueType.IsSubclassOf(p_acceptedType)))
                            {
                                p_style = v_style;
                                break;
                            }
                        }
                    }
                }
            }
            return(p_style != null);
        }