protected void RegisterMoudle(IMoudle moudle) { Type type = moudle.GetType(); if (m_Moudles.ContainsKey(type)) { Debug.LogError(string.Format("{0}已经注册过,无法重复注册", type.FullName)); } m_Moudles[type] = moudle; }
protected M _GetMoudle <M>() where M : IMoudle, new() { Type type = typeof(M); IMoudle moudle = null; if (!m_Moudles.TryGetValue(type, out moudle)) { Debug.LogError(string.Format("模块{0}没有找到", type.FullName)); //容错处理,自动注册 RegisterMoudle <M>(); } return((M)moudle); }
public IMoudle LoadInstrument(string path) { IMoudle moudle = null; Assembly asm = Assembly.Load(path); foreach (Type t in asm.GetTypes()) { if (t.GetInterface("IMoudle") != null) { moudle = asm.CreateInstance(t.FullName) as IMoudle; } } return(moudle); }