static ITypeSerialize GetByType(ILRuntimeFieldInfo fieldInfo) { if (FieldInfoTypes.TryGetValue(fieldInfo, out var ts)) { return(ts); } var fieldType = fieldInfo.FieldType; if (fieldType is ILRuntimeWrapperType) { fieldType = ((ILRuntimeWrapperType)fieldType).RealType; } if (Help.isType(fieldType, typeof(UnityEngine.Object))) { ts = unityObjectSerialize; } else if (Help.isDictionaryType(fieldType)) { ts = new DictionaryType(fieldType, fieldInfo); } else { bool isListType = false; if (fieldType.IsArray || (isListType = Help.isListType(fieldType))) { int arrayCount = 0; string elementType = null; ILRuntimeFieldInfo ilFieldInfo = (ILRuntimeFieldInfo)fieldInfo; GetElementType(ilFieldInfo.Definition.FieldType, ref arrayCount, out elementType); var et = GetType(elementType); if (et is ILRuntimeType) // 不是热更当中的类型 { ts = new HotArrayAnyType(et, isListType, arrayCount); } else { ts = GetByType(fieldType); } } else { ts = GetByType(fieldType); } } FieldInfoTypes.Add(fieldInfo, ts); return(ts); }
public static ITypeSerialize GetByType(System.Type type) { ITypeSerialize ts = null; string fullname = type.FullName; if (AllTypes.TryGetValue(fullname, out ts)) { return(ts); } if (Help.isType(type, typeof(UnityEngine.Object))) { ts = unityObjectSerialize; } else if (type == typeof(object)) { ts = objectSerialize; } else { if (type.IsEnum) { #if USE_HOT if (type is ILRuntimeType) { var atts = type.GetCustomAttributes(typeof(EnumString), false); if (atts != null && atts.Length != 0) { ts = new HotEnumStringTypeSerialize(type as ILRuntimeType); } else { ts = new HotEnumTypeSerialize(type as ILRuntimeType); } } else { #endif var atts = type.GetCustomAttributes(typeof(EnumString), false); if (atts != null && atts.Length != 0) { ts = new EnumStringTypeSerialize(type); } else { ts = new EnumTypeSerialize(type); } #if USE_HOT } #endif } else if (type.IsArray) { ts = new ArrayAnyType(type); } else if (Help.isListType(type)) { ts = new ListAnyType(type); } else if (Help.isDictionaryType(type)) { // map对象 ts = new DictionaryType(type, null); } else { var atts = type.GetCustomAttributes(typeof(SmartAttribute), false); if (atts != null && atts.Length > 0) { ts = new SmartSerializer(type, new AnyTypeSerialize(type, Help.GetSerializeField(type))); } else { atts = type.GetCustomAttributes(typeof(CSharpAgent), false); if (atts != null && atts.Length > 0) { ts = new CSharpAgentSerialize(type); } else { List <FieldInfo> fieldinfos = Help.GetSerializeField(type); ts = new AnyTypeSerialize(type, fieldinfos); } } } } AllTypes.Add(fullname, ts); return(ts); }