/// <summary> /// Registers a new handler for a command /// </summary> /// <param name="Command"></param> /// <param name="handler"></param> public void RegisterHandler(string Command, AerInputHandler handler) { if (!_EventRegistry.ContainsKey(Command)) { _EventRegistry.Add(Command, handler); } else { AerDebug.LogError("Re-registered command to new handler, command=" + Command); _EventRegistry[Command] = handler; //Maybe it should just be thrown away? } }
/// <summary> /// Uses reflection to pull out all SpeechHandlerAttribute tags and creates a Rule->Delegate dictionary /// from the data. /// </summary> private void _RegisterDefaultHandlers() { Assembly assembly = Assembly.GetExecutingAssembly(); IEnumerable <MemberInfo> handlers = assembly.GetTypes().SelectMany(type => type.GetMembers()) .Union(assembly.GetTypes()) .Where(type => Attribute.IsDefined(type, typeof(SpeechHandlerAttribute))); foreach (MemberInfo mi in handlers) { Object[] attribs = mi.GetCustomAttributes(typeof(SpeechHandlerAttribute), false); for (int i = 0; i < attribs.Length; i++) { //AerDebug.Log("Found Handler: " + ((SpeechHandlerAttribute)attribs[i]).GrammarRule); if (mi.MemberType == MemberTypes.Method) { AerInputHandler Call = (AerInputHandler)Delegate.CreateDelegate(typeof(AerInputHandler), this, mi.Name); RegisterHandler(((SpeechHandlerAttribute)attribs[i]).GrammarRule, Call); } } } }
/// <summary> /// Registers a new handler for a command /// </summary> /// <param name="Command"></param> /// <param name="handler"></param> public void RegisterHandler(string Command, AerInputHandler handler) { if (!_EventRegistry.ContainsKey(Command)) _EventRegistry.Add(Command, handler); else { NMDebug.LogError("Re-registered command to new handler, command=" + Command); _EventRegistry[Command] = handler; //Maybe it should just be thrown away? } }