Files
Dec2017-Script-Dump/UnityEngine/Experimental/UIElements/StyleSheets/StyleSheetCache.cs
T
2026-06-04 11:42:34 +02:00

124 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine.StyleSheets;
namespace UnityEngine.Experimental.UIElements.StyleSheets
{
// Token: 0x0200036B RID: 875
internal static class StyleSheetCache
{
// Token: 0x06003537 RID: 13623 RVA: 0x00058028 File Offset: 0x00056228
static StyleSheetCache()
{
FieldInfo[] fields = typeof(VisualElementStyles).GetFields();
foreach (FieldInfo fieldInfo in fields)
{
StylePropertyAttribute stylePropertyAttribute = (StylePropertyAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(StylePropertyAttribute));
if (stylePropertyAttribute != null)
{
StyleSheetCache.s_NameToIDCache.Add(stylePropertyAttribute.propertyName, stylePropertyAttribute.propertyID);
}
}
}
// Token: 0x06003538 RID: 13624 RVA: 0x000580D0 File Offset: 0x000562D0
internal static void ClearCaches()
{
StyleSheetCache.s_EnumToIntCache.Clear();
StyleSheetCache.s_RulePropertyIDsCache.Clear();
}
// Token: 0x06003539 RID: 13625 RVA: 0x000580E8 File Offset: 0x000562E8
internal static int GetEnumValue<T>(StyleSheet sheet, StyleValueHandle handle)
{
Debug.Assert(handle.valueType == StyleValueType.Enum);
StyleSheetCache.SheetHandleKey sheetHandleKey = new StyleSheetCache.SheetHandleKey(sheet, handle.valueIndex);
int num;
if (!StyleSheetCache.s_EnumToIntCache.TryGetValue(sheetHandleKey, out num))
{
string text = sheet.ReadEnum(handle).Replace("-", string.Empty);
object obj = Enum.Parse(typeof(T), text, true);
num = (int)obj;
StyleSheetCache.s_EnumToIntCache.Add(sheetHandleKey, num);
}
Debug.Assert(Enum.GetName(typeof(T), num) != null);
return num;
}
// Token: 0x0600353A RID: 13626 RVA: 0x00058190 File Offset: 0x00056390
internal static StylePropertyID[] GetPropertyIDs(StyleSheet sheet, int ruleIndex)
{
StyleSheetCache.SheetHandleKey sheetHandleKey = new StyleSheetCache.SheetHandleKey(sheet, ruleIndex);
StylePropertyID[] array;
if (!StyleSheetCache.s_RulePropertyIDsCache.TryGetValue(sheetHandleKey, out array))
{
StyleRule styleRule = sheet.rules[ruleIndex];
array = new StylePropertyID[styleRule.properties.Length];
for (int i = 0; i < array.Length; i++)
{
array[i] = StyleSheetCache.GetPropertyID(styleRule.properties[i].name);
}
StyleSheetCache.s_RulePropertyIDsCache.Add(sheetHandleKey, array);
}
return array;
}
// Token: 0x0600353B RID: 13627 RVA: 0x00058214 File Offset: 0x00056414
private static StylePropertyID GetPropertyID(string name)
{
StylePropertyID stylePropertyID;
if (!StyleSheetCache.s_NameToIDCache.TryGetValue(name, out stylePropertyID))
{
stylePropertyID = StylePropertyID.Custom;
}
return stylePropertyID;
}
// Token: 0x04000B89 RID: 2953
private static StyleSheetCache.SheetHandleKeyComparer s_Comparer = new StyleSheetCache.SheetHandleKeyComparer();
// Token: 0x04000B8A RID: 2954
private static Dictionary<StyleSheetCache.SheetHandleKey, int> s_EnumToIntCache = new Dictionary<StyleSheetCache.SheetHandleKey, int>(StyleSheetCache.s_Comparer);
// Token: 0x04000B8B RID: 2955
private static Dictionary<StyleSheetCache.SheetHandleKey, StylePropertyID[]> s_RulePropertyIDsCache = new Dictionary<StyleSheetCache.SheetHandleKey, StylePropertyID[]>(StyleSheetCache.s_Comparer);
// Token: 0x04000B8C RID: 2956
private static Dictionary<string, StylePropertyID> s_NameToIDCache = new Dictionary<string, StylePropertyID>();
// Token: 0x0200036C RID: 876
private struct SheetHandleKey
{
// Token: 0x0600353C RID: 13628 RVA: 0x00058244 File Offset: 0x00056444
public SheetHandleKey(StyleSheet sheet, int index)
{
this.sheetInstanceID = sheet.GetInstanceID();
this.index = index;
}
// Token: 0x04000B8D RID: 2957
public readonly int sheetInstanceID;
// Token: 0x04000B8E RID: 2958
public readonly int index;
}
// Token: 0x0200036D RID: 877
private class SheetHandleKeyComparer : IEqualityComparer<StyleSheetCache.SheetHandleKey>
{
// Token: 0x0600353E RID: 13630 RVA: 0x00058264 File Offset: 0x00056464
public bool Equals(StyleSheetCache.SheetHandleKey x, StyleSheetCache.SheetHandleKey y)
{
return x.sheetInstanceID == y.sheetInstanceID && x.index == y.index;
}
// Token: 0x0600353F RID: 13631 RVA: 0x000582A0 File Offset: 0x000564A0
public int GetHashCode(StyleSheetCache.SheetHandleKey key)
{
return key.sheetInstanceID.GetHashCode() ^ key.index.GetHashCode();
}
}
}
}