public static IScenarioContentExecutor[] GetOrCreateInstances( Type[] executorTypes, Action <int, string> triggerError = null, bool fromCache = true) { if (executorTypes == null) { return(new IScenarioContentExecutor[0]); } IScenarioContentExecutor[] executors = new IScenarioContentExecutor[executorTypes.Length]; string error; for (int i = 0; i < executorTypes.Length; i++) { executors[i] = GetOrCreateInstance(executorTypes[i], out error, fromCache); if (!string.IsNullOrEmpty(error)) { if (triggerError != null) { triggerError(i, error); } error = null; } } return(executors); }
public static IScenarioContentExecutor CreateInstance(Type executorType, out string error) { if (executorType == null) { error = "ScenarioContentExecutor -> CreateInstance: type of executor is null."; return(null); } if (executorType.IsAbstract) { error = string.Format( "ScenarioContentExecutor -> CreateInstance: type `{0}` of executor is abstract or interface.", executorType.FullName); return(null); } if (!typeof(IScenarioContentExecutor).IsAssignableFrom(executorType)) { error = string.Format( "ScenarioContentExecutor -> CreateInstance: type `{0}` dose not inhert `IScenarioContentExecutor`.", executorType.FullName); return(null); } IScenarioContentExecutor executor = Activator.CreateInstance(executorType) as IScenarioContentExecutor; if (executor == null) { error = string.Format( "ScenarioContentExecutor -> CreateInstance: type `{0}` create failure.", executorType.FullName); return(null); } if (executor.code == null) { error = string.Format( "ScenarioContentExecutor -> CreateInstance: code of type `{0}` is null.", executorType.FullName); return(null); } error = null; return(executor); }
/// <summary> /// 添加或设置Executor /// </summary> /// <param name="executor"></param> /// <param name="existOverride"></param> /// <returns></returns> public bool SetExecutor(IScenarioContentExecutor executor, bool existOverride = true) { if (executor == null) { return(false); } if (executor.code == null) { return(false); } if (!existOverride && m_ExecutorDict.ContainsKey(executor.code)) { return(false); } m_ExecutorDict[executor.code] = executor; return(true); }
public static void GetOrCreateInstances( Type[] executorTypes, Action <int, IScenarioContentExecutor> loaded, Action <int, string> triggerError = null, bool fromCache = true, bool ignorEmpty = true) { if (executorTypes == null) { return; } string error; for (int i = 0; i < executorTypes.Length; i++) { IScenarioContentExecutor executor = GetOrCreateInstance(executorTypes[i], out error, fromCache); if (!string.IsNullOrEmpty(error)) { if (triggerError != null) { triggerError(i, error); } error = null; } if (executor == null && ignorEmpty) { continue; } if (loaded != null) { loaded(i, executor); } } }