private string ReadClassType(EndianStream stream, long stringPosition) { ushort typeIndex = stream.ReadUInt16(); bool isCustomType = stream.ReadUInt16() == 0; if (isCustomType) { //memTypeIndex is an offset in the string block long memberPosition = stream.BaseStream.Position; stream.BaseStream.Position = stringPosition + typeIndex; string typeName = stream.ReadStringZeroTerm(); stream.BaseStream.Position = memberPosition; return(typeName); } else { //memTypeIndex is an index in an internal strig array SerializeClassType classType = (SerializeClassType)typeIndex; if (!Enum.IsDefined(typeof(SerializeClassType), classType)) { throw new Exception($"Unsupported asset class type name '{classType}' for asset file '{Name}'"); } return(classType.ToTypeString()); } }
public static string ToTypeString(this SerializeClassType _this) { if (m_typeNames.TryGetValue(_this, out string name)) { return(name); } if (!Enum.IsDefined(typeof(SerializeClassType), _this)) { return($"Unknown {(int)_this}"); } return(_this.ToString()); }
static AssetClassTypeExtentions() { Type type = typeof(SerializeClassType); SerializeClassType[] values = (SerializeClassType[])Enum.GetValues(type); FieldInfo[] fields = type.GetFields(); for (int i = 1; i < fields.Length; i++) { MemberInfo member = fields[i]; EnumNameAttribute name = member.GetCustomAttribute <EnumNameAttribute>(); if (name == null) { continue; } SerializeClassType value = values[i - 1]; m_typeNames.Add(value, name.Name); } }