private T AddResource <T>(string path, T resource, IntMap <AssetEntry <T> > map) where T : UnityEngine.Object { if (resource == null || path == null) { return(null); } int pathId = path.GetHashCode(); int id = resource.GetHashCode(); AssetEntry <T> pathEntry; AssetEntry <T> idEntry; if (map.TryGetValue(pathId, out pathEntry)) { return(resource); } idEntry.id = id; idEntry.linkedId = pathId; idEntry.asset = resource; pathEntry.id = id; pathEntry.linkedId = id; pathEntry.asset = resource; map.Add(pathId, pathEntry); map.Add(id, idEntry); return(resource); }
void Start() { vaule.key = 2; vaule.vaule = "****"; IntMap.Add(0, "--"); IntMap.Add(1, "+++"); IntMap += vaule; print(IntMap.GetKey(1).vaule); }
static StyleUtil() { s_NameMap = new IntMap <string>(); InheritedProperties = new List <StylePropertyId>(); StylePropertyId[] values = (StylePropertyId[])Enum.GetValues(typeof(StylePropertyId)); StylePropertyId[] ignored = { }; int idx = 0; StylePropertyIdList = new StylePropertyId[values.Length - ignored.Length]; for (int i = 0; i < values.Length; i++) { if (Array.IndexOf(ignored, values[i]) != -1) { continue; } StylePropertyIdList[idx++] = values[i]; s_NameMap.Add((int)values[i], values[i].ToString()); if (IsInherited(values[i])) { InheritedProperties.Add(values[i]); } } }
public Aspect(SparseComponentArray sparseComponents, TypeIndexer typeIndexer, int maxEntities, int maxComponentTypes, Type[] types) { Debug.Assert(maxEntities > 0); Debug.Assert(maxComponentTypes > 0); this.maxEntities = maxEntities; this.typeIndexer = typeIndexer; this.sparseComponents = sparseComponents; typeMap = new IntMap(maxComponentTypes); entities = new PackedArray <Entity>(maxEntities); components = new IArrayWrapper[types.Length]; addedEntities = new Entity[maxEntities]; removedEntities = new Entity[maxEntities]; foreach (Type type in types) { int typeIndex = typeIndexer.GetIndex(type); int packedIndex = typeMap.Add(typeIndex); Type genericArrayWrapper = typeof(ArrayWrapper <>).MakeGenericType(type); IArrayWrapper array = (IArrayWrapper)Activator.CreateInstance(genericArrayWrapper, maxEntities); components[packedIndex] = array; Bitmask = Bitmask.Set(typeIndex); } }
internal void ClearPropertyMap() { // when clearing the property map we want to retain the styles that we have inherited from elsewhere // to do this, we need to read in the inherited values, store them, clear the map, then write the values back LightList <StyleProperty> inherited = LightList <StyleProperty> .Get(); inherited.EnsureCapacity(StyleUtil.InheritedProperties.Count); StyleProperty[] inheritedArray = inherited.Array; for (int i = 0; i < StyleUtil.InheritedProperties.Count; i++) { int key = BitUtil.SetHighLowBits(1, (int)StyleUtil.InheritedProperties[i]); if (propertyMap.TryGetValue(key, out StyleProperty inheritedValue)) { inherited.AddUnchecked(inheritedValue); } } propertyMap.Clear(); // re-apply values for (int i = 0; i < inherited.Count; i++) { int key = BitUtil.SetHighLowBits(1, (int)inheritedArray[i].propertyId); propertyMap.Add(key, inheritedArray[i]); } LightList <StyleProperty> .Release(ref inherited); }
private T AddResource <T>(T resource, IntMap <AssetEntry <T> > map) where T : UnityEngine.Object { int id = resource.GetHashCode(); AssetEntry <T> entry; if (map.TryGetValue(id, out entry)) { return(resource); } entry.id = id; entry.linkedId = -1; entry.asset = resource; map.Add(id, entry); return(resource); }
private static IntMap <TextKerningPair> ConvertKerning(Dictionary <int, KerningPair> tmpKerning) { IntMap <TextKerningPair> retn = new IntMap <TextKerningPair>(tmpKerning.Count); foreach (KeyValuePair <int, KerningPair> pair in tmpKerning) { TextKerningPair tkp = new TextKerningPair(); tkp.firstGlyph = pair.Value.firstGlyph; tkp.firstGlyphAdjustments = pair.Value.firstGlyphAdjustments; tkp.secondGlyph = pair.Value.secondGlyph; tkp.secondGlyphAdjustments = pair.Value.secondGlyphAdjustments; retn.Add(pair.Key, tkp); } return(retn); }
private T GetResource <T>(string path, IntMap <AssetEntry <T> > map) where T : UnityEngine.Object { T resource; if (path == null) { return(null); } AssetEntry <T> pathEntry; int pathId = path.GetHashCode(); if (map.TryGetValue(pathId, out pathEntry)) { return(pathEntry.asset); } else { // this might be null, but we want to mark the map to show that we tried to load it // during the lifecycle of an application we can expect Resources not to be updated resource = Resources.Load <T>(path); pathEntry.id = pathId; pathEntry.asset = resource; pathEntry.linkedId = -1; if (resource != null) { // see if we already have it loaded by id and update linkedId accordingly int resourceId = resource.GetHashCode(); AssetEntry <T> idEntry; idEntry.id = resourceId; idEntry.linkedId = pathId; idEntry.asset = resource; map[idEntry.id] = idEntry; pathEntry.linkedId = idEntry.id; } map.Add(pathId, pathEntry); } return(resource); }
private static IntMap <TextGlyph> ConvertCharacters(TMP_FontAsset asset) { List <Glyph> glyphList = asset.glyphTable; IntMap <TextGlyph> retn = new IntMap <TextGlyph>(glyphList.Count); for (int i = 0; i < asset.characterTable.Count; i++) { TextGlyph glyph = new TextGlyph(); Glyph tmpGlyph = asset.characterTable[i].glyph; glyph.id = (int)tmpGlyph.index; glyph.height = tmpGlyph.metrics.height; glyph.width = tmpGlyph.metrics.width; glyph.x = tmpGlyph.glyphRect.x; glyph.y = tmpGlyph.glyphRect.y; glyph.scale = tmpGlyph.scale; glyph.xAdvance = tmpGlyph.metrics.horizontalAdvance; glyph.xOffset = tmpGlyph.metrics.horizontalBearingX; glyph.yOffset = tmpGlyph.metrics.horizontalBearingY; retn.Add((int)asset.characterTable[i].unicode, glyph); } return(retn); }
private static IntMap <TextGlyph> ConvertCharacters(Dictionary <int, TMP_Glyph> tmpGlyphs) { IntMap <TextGlyph> retn = new IntMap <TextGlyph>(tmpGlyphs.Count); foreach (KeyValuePair <int, TMP_Glyph> pair in tmpGlyphs) { TMP_Glyph tmpGlyph = pair.Value; TextGlyph glyph = new TextGlyph(); glyph.id = tmpGlyph.id; glyph.height = tmpGlyph.height; glyph.width = tmpGlyph.width; glyph.x = tmpGlyph.x; glyph.y = tmpGlyph.y; glyph.scale = tmpGlyph.scale; glyph.xAdvance = tmpGlyph.xAdvance; glyph.xOffset = tmpGlyph.xOffset; glyph.yOffset = tmpGlyph.yOffset; retn.Add(pair.Key, glyph); } return(retn); }