/// <summary> /// /// </summary> /// <returns></returns> public GameEntityT CreateNewInstance <GameEntityT>() where GameEntityT : WorldEntity { if (m_ConstructorInstance != null) { object returnObject = m_ConstructorInstance.Invoke(); GameEntityT creature = returnObject as GameEntityT; if (creature == null) { LOGs.WriteLine(LogMessageType.MSG_ERROR, "GameEntity.CreateNewInstance(...) - creature == null error!"); return(null); } return(creature); } else { m_ConstructorInstance = DynamicCalls.GetInstanceCreator(GetType()); if (m_ConstructorInstance == null) { throw new Exception("GameEntity.CreateNewInstance(...) - m_ConstructorInstance == null error!"); } GameEntityT creature = m_ConstructorInstance.Invoke() as GameEntityT; if (creature == null) { LOGs.WriteLine(LogMessageType.MSG_ERROR, "GameEntity.CreateNewInstance(...) - creature == null error!"); return(null); } return(creature); } }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="fProbability"></param> public Loot(Type type, float fProbability) { m_ConstructorInstance = DynamicCalls.GetInstanceCreator(type); if (m_ConstructorInstance == null) { throw new Exception("Loot.Loot(...) - m_ConstructorInstance == null error!"); } m_fProbability = fProbability; }
public void GetInstanceCreatorTest() { Type type = null; // TODO: 初始化为适当的值 FastCreateInstanceHandler expected = null; // TODO: 初始化为适当的值 FastCreateInstanceHandler actual; actual = DynamicCalls.GetInstanceCreator(type); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
/// <summary> /// 快速实例化一个FastCreateInstanceHandler /// </summary> /// <param name="type"></param> /// <returns></returns> public static FastCreateInstanceHandler Create(Type type) { return(DynamicCalls.GetInstanceCreator(type)); }