예제 #1
0
        public static bool ApplyAndCompare(ref StyleValue <CursorStyle> current, StyleValue <CursorStyle> other)
        {
            CursorStyle oldValue = current.value;

            if (current.Apply(other, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity))
            {
                return(oldValue != other.value);
            }
            return(false);
        }
예제 #2
0
        // Note: this should not box values since we use a generic constraint
        public static bool ApplyAndCompare <T>(ref StyleValue <T> current, StyleValue <T> other) where T : struct, IEquatable <T>
        {
            T oldValue = current.value;

            if (current.Apply(other, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity))
            {
                return(!oldValue.Equals(other.value));
            }
            return(false);
        }
예제 #3
0
        public static bool ApplyAndCompare <T>(ref StyleValue <T> current, StyleValue <T> other) where T : Object
        {
            T oldValue = current.value;

            if (current.Apply(other, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity))
            {
                return(oldValue != other.value);
            }
            return(false);
        }
예제 #4
0
        public void ApplyCustomProperty(string propertyName, ref StyleValue <Texture2D> target)
        {
            CustomProperty         property;
            StyleValue <Texture2D> tmp = new StyleValue <Texture2D>();

            if (m_CustomProperties != null && m_CustomProperties.TryGetValue(propertyName, out property))
            {
                property.data.Apply(property.handles, property.specificity, ref tmp, StyleSheetApplicator.ApplyImage);
            }
            target.Apply(tmp, StylePropertyApplyMode.CopyIfNotInline);
        }
예제 #5
0
        public void ApplyCustomProperty(string propertyName, ref StyleValue <string> target)
        {
            CustomProperty      property;
            StyleValue <string> tmp = new StyleValue <string>(string.Empty);

            if (m_CustomProperties != null && m_CustomProperties.TryGetValue(propertyName, out property))
            {
                tmp.value       = property.data.ReadAsString(property.handles[0]);
                tmp.specificity = property.specificity;
            }
            target.Apply(tmp, StylePropertyApplyMode.CopyIfNotInline);
        }
예제 #6
0
        public static void ApplyFont(StyleSheet sheet, StyleValueHandle[] handles, int specificity,
                                     ref StyleValue <Font> property)
        {
            StyleValueHandle handle = handles[0];
            Font             font   = null;

            switch (handle.valueType)
            {
            case StyleValueType.ResourcePath:
            {
                string path = sheet.ReadResourcePath(handle);

                if (!string.IsNullOrEmpty(path))
                {
                    font = Panel.loadResourceFunc(path, typeof(Font)) as Font;
                }

                if (font == null)
                {
                    Debug.LogWarning(string.Format("Font not found for path: {0}", path));
                }
            }
            break;

            case StyleValueType.AssetReference:
            {
                font = sheet.ReadAssetReference(handle) as Font;

                if (font == null)
                {
                    Debug.LogWarning("Invalid font reference");
                }
            }
            break;

            default:
                Debug.LogWarning("Invalid value for font " + handle.valueType);
                break;
            }

            if (font != null)
            {
                Apply(font, specificity, ref property);
            }
        }
예제 #7
0
        internal void ApplyCustomProperty <T>(string propertyName, ref StyleValue <T> target, StyleValueType valueType, HandlesApplicatorFunction <T> applicatorFunc)
        {
            CustomProperty property;
            StyleValue <T> tmp = new StyleValue <T>();

            if (m_CustomProperties != null && m_CustomProperties.TryGetValue(propertyName, out property))
            {
                // CustomProperty only support one value
                var handle = property.handles[0];
                if (handle.valueType == valueType)
                {
                    property.data.Apply(property.handles, property.specificity, ref tmp, applicatorFunc);
                }
                else
                {
                    Debug.LogWarning(string.Format("Trying to read value as {0} while parsed type is {1}", valueType, handle.valueType));
                }
            }
            target.Apply(tmp, StylePropertyApplyMode.CopyIfNotInline);
        }
예제 #8
0
        public static void ApplyImage(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <Texture2D> property)
        {
            Texture2D source = null;

            StyleValueHandle handle = handles[0];

            if (handle.valueType == StyleValueType.Keyword)
            {
                if (handle.valueIndex != (int)StyleValueKeyword.None)
                {
                    Debug.LogWarning("Invalid keyword for image source " + (StyleValueKeyword)handle.valueIndex);
                }
                else
                {
                    // it's OK, we let none be assigned to the source
                }
            }
            else if (TryGetSourceFromHandle(sheet, handle, out source) == false)
            {
                // Load a stand-in picture to make it easier to identify which image element is missing its picture
                source = Panel.loadResourceFunc("d_console.warnicon", typeof(Texture2D)) as Texture2D;
            }
            Apply(source, specificity, ref property);
        }
예제 #9
0
        public static void ApplyColor(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <Color> property)
        {
            Color val = sheet.ReadColor(handles[0]);

            StyleSheetApplicator.Apply <Color>(val, specificity, ref property);
        }
예제 #10
0
        public static bool ApplyAndCompare <T>(ref StyleValue <T> current, StyleValue <T> other) where T : UnityEngine.Object
        {
            T value = current.value;

            return(current.Apply(other, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity) && value != other.value);
        }
예제 #11
0
        public static void ApplyColor(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <Color> property)
        {
            var value = sheet.ReadColor(handles[0]);

            Apply(value, specificity, ref property);
        }
예제 #12
0
        public static void ApplyInt(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <int> property)
        {
            var value = (int)sheet.ReadFloat(handles[0]);

            Apply(value, specificity, ref property);
        }
예제 #13
0
        public static void ApplyBool(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <bool> property)
        {
            bool value = sheet.ReadKeyword(handles[0]) == StyleValueKeyword.True;

            Apply(value, specificity, ref property);
        }
예제 #14
0
 public void ApplyCustomProperty(string propertyName, ref StyleValue <bool> target)
 {
     ApplyCustomProperty(propertyName, ref target, StyleValueType.Keyword, StyleSheetApplicator.ApplyBool);
 }
예제 #15
0
 public void ApplyCustomProperty(string propertyName, ref StyleValue <int> target)
 {
     ApplyCustomProperty(propertyName, ref target, StyleValueType.Float, StyleSheetApplicator.ApplyInt);
 }
예제 #16
0
 public static void Apply <T>(this StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <T> property, HandlesApplicatorFunction <T> applicatorFunc)
 {
     if (handles[0].valueType == StyleValueType.Keyword && handles[0].valueIndex == 2)
     {
         StyleSheetApplicator.ApplyDefault <T>(specificity, ref property);
     }
     else
     {
         applicatorFunc(sheet, handles, specificity, ref property);
     }
 }
예제 #17
0
 public static void ApplyDefault <T>(int specificity, ref StyleValue <T> property)
 {
     StyleSheetApplicator.Apply <T>(default(T), specificity, ref property);
 }
예제 #18
0
        public static void ApplyResource <T>(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <T> property) where T : UnityEngine.Object
        {
            StyleValueHandle handle = handles[0];

            if (handle.valueType == StyleValueType.Keyword && handle.valueIndex == 5)
            {
                StyleSheetApplicator.Apply <T>((T)((object)null), specificity, ref property);
            }
            else
            {
                T      t    = (T)((object)null);
                string text = sheet.ReadResourcePath(handle);
                if (!string.IsNullOrEmpty(text))
                {
                    t = (Panel.loadResourceFunc(text, typeof(T)) as T);
                    if (t != null)
                    {
                        StyleSheetApplicator.Apply <T>(t, specificity, ref property);
                    }
                    else
                    {
                        if (typeof(T) == typeof(Texture2D))
                        {
                            t = (Panel.loadResourceFunc("d_console.warnicon", typeof(T)) as T);
                            StyleSheetApplicator.Apply <T>(t, specificity, ref property);
                        }
                        Debug.LogWarning(string.Format("{0} resource/file not found for path: {1}", typeof(T).Name, text));
                    }
                }
            }
        }
예제 #19
0
        public static void ApplyCursor(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <CursorStyle> property)
        {
            StyleValueHandle handle = handles[0];
            bool             flag   = handle.valueType == StyleValueType.ResourcePath;

            if (flag)
            {
                string    pathName  = sheet.ReadResourcePath(handles[0]);
                Texture2D texture2D = Panel.loadResourceFunc(pathName, typeof(Texture2D)) as Texture2D;
                if (texture2D != null)
                {
                    Vector2 zero = Vector2.zero;
                    sheet.TryReadFloat(handles, 1, out zero.x);
                    sheet.TryReadFloat(handles, 2, out zero.y);
                    CursorStyle val = new CursorStyle
                    {
                        texture = texture2D,
                        hotspot = zero
                    };
                    StyleSheetApplicator.Apply <CursorStyle>(val, specificity, ref property);
                }
            }
            else if (StyleSheetApplicator.createDefaultCursorStyleFunc != null)
            {
                CursorStyle val2 = StyleSheetApplicator.createDefaultCursorStyleFunc(sheet, handle);
                StyleSheetApplicator.Apply <CursorStyle>(val2, specificity, ref property);
            }
        }
예제 #20
0
 static void Apply <T>(T val, int specificity, ref StyleValue <T> property)
 {
     property.Apply(new StyleValue <T>(val, specificity), StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity);
 }
예제 #21
0
 public static void ApplyValue <T>(int specificity, ref StyleValue <T> property, T value = default(T))
 {
     Apply(value, specificity, ref property);
 }
예제 #22
0
 public void ApplyCustomProperty(string propertyName, ref StyleValue <Color> target)
 {
     ApplyCustomProperty(propertyName, ref target, StyleValueType.Color, StyleSheetApplicator.ApplyColor);
 }
예제 #23
0
        public static void ApplyFloatOrKeyword(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <FloatOrKeyword> property)
        {
            var            handle = handles[0];
            FloatOrKeyword fk;

            if (handle.valueType == StyleValueType.Keyword)
            {
                fk = new FloatOrKeyword((StyleValueKeyword)handle.valueIndex);
            }
            else
            {
                fk = new FloatOrKeyword(sheet.ReadFloat(handle));
            }
            Apply(fk, specificity, ref property);
        }
예제 #24
0
 public void ApplyCustomProperty <T>(string propertyName, ref StyleValue <T> target) where T : Object
 {
     ApplyCustomProperty(propertyName, ref target, StyleValueType.ResourcePath, StyleSheetApplicator.ApplyResource);
 }
예제 #25
0
        public static void ApplyEnum <T>(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <int> property)
        {
            var value = StyleSheetCache.GetEnumValue <T>(sheet, handles[0]);

            Apply(value, specificity, ref property);
        }
예제 #26
0
        public static void ApplyInt(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <int> property)
        {
            int val = (int)sheet.ReadFloat(handles[0]);

            StyleSheetApplicator.Apply <int>(val, specificity, ref property);
        }
예제 #27
0
        public static bool ApplyAndCompare(ref StyleValue <float> current, StyleValue <float> other)
        {
            float value = current.value;

            return(current.Apply(other, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity) && value != other.value);
        }
예제 #28
0
        public static void ApplyCursor(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <CursorStyle> property)
        {
            float     hotspotX;
            float     hotspotY;
            int       cursorId;
            Texture2D texture;

            CompileCursor(sheet, handles, out hotspotX, out hotspotY, out cursorId, out texture);
            CursorStyle cursor = new CursorStyle()
            {
                texture = texture, hotspot = new Vector2(hotspotX, hotspotY), defaultCursorId = cursorId
            };

            Apply(cursor, specificity, ref property);
        }
예제 #29
0
 internal bool Apply(StyleValue <T> other, StylePropertyApplyMode mode)
 {
     return(this.Apply(other.value, other.specificity, mode));
 }
예제 #30
0
        public static void ApplyEnum <T>(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <int> property)
        {
            int enumValue = StyleSheetCache.GetEnumValue <T>(sheet, handles[0]);

            StyleSheetApplicator.Apply <int>(enumValue, specificity, ref property);
        }