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); }
// 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); }
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); }
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); }
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); }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public void ApplyCustomProperty(string propertyName, ref StyleValue <bool> target) { ApplyCustomProperty(propertyName, ref target, StyleValueType.Keyword, StyleSheetApplicator.ApplyBool); }
public void ApplyCustomProperty(string propertyName, ref StyleValue <int> target) { ApplyCustomProperty(propertyName, ref target, StyleValueType.Float, StyleSheetApplicator.ApplyInt); }
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); } }
public static void ApplyDefault <T>(int specificity, ref StyleValue <T> property) { StyleSheetApplicator.Apply <T>(default(T), specificity, ref property); }
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)); } } } }
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); } }
static void Apply <T>(T val, int specificity, ref StyleValue <T> property) { property.Apply(new StyleValue <T>(val, specificity), StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity); }
public static void ApplyValue <T>(int specificity, ref StyleValue <T> property, T value = default(T)) { Apply(value, specificity, ref property); }
public void ApplyCustomProperty(string propertyName, ref StyleValue <Color> target) { ApplyCustomProperty(propertyName, ref target, StyleValueType.Color, StyleSheetApplicator.ApplyColor); }
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); }
public void ApplyCustomProperty <T>(string propertyName, ref StyleValue <T> target) where T : Object { ApplyCustomProperty(propertyName, ref target, StyleValueType.ResourcePath, StyleSheetApplicator.ApplyResource); }
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); }
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); }
public static bool ApplyAndCompare(ref StyleValue <float> current, StyleValue <float> other) { float value = current.value; return(current.Apply(other, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity) && value != other.value); }
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); }
internal bool Apply(StyleValue <T> other, StylePropertyApplyMode mode) { return(this.Apply(other.value, other.specificity, mode)); }
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); }