static public void SetTypeTable(Type type) { if (null == sTypeTable || sTypeTable.GetType() != type) { sTypeTable = System.Activator.CreateInstance(type) as ITypeTable; sTypeTable.InitializeTypes(); } }
static public void BindFromJson(string filename) { string jsonContent = FileUtility.ReadStringFromFile(filename); if (string.IsNullOrEmpty(jsonContent)) { Entry.LogError("Try to bind dynamically but no content from json [{0}]!", filename); return; } BindingRecordConfig config = JsonUtility.FromJson <BindingRecordConfig>(jsonContent); if (config.assemblies?.Count > 0) { #if UNITY_IOS Entry.LogError("Dynamic binding is not supported on iOS, since reflection is forbidden!"); #else foreach (BindingRecordConfigAssembly record in config.assemblies) { #if !UNITY_IOS Assembly assembly = Assembly.Load(record.name); if (null == assembly) { Entry.LogError("Try to bind dynamically but load assembly [{0}] failed!", record.name); continue; } #endif foreach (string typename in record.types) { #if UNITY_IOS Type type = sTypeTable?.GetType(typename); #else Type type = assembly.GetType(typename); #endif if (null == type) { Entry.LogError("Try to bind dynamically but load type [{0}] failed!", typename); continue; } Bind(type); } } #endif } }