ComAICell.ObjectEvent.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using CommonLang;
  3. using CommonAIClient.Unity.Utils;
  4. namespace CommonAIClient.Unity.Battle
  5. {
  6. public partial class ComAICell
  7. {
  8. private HashMap<Type, Action<CommonAI.Zone.ObjectEvent>> mObjectEvens = new HashMap<Type, Action<CommonAI.Zone.ObjectEvent>>();
  9. public void DoObjectEvent(CommonAI.Zone.ObjectEvent ev)
  10. {
  11. Action<CommonAI.Zone.ObjectEvent> action = null;
  12. if (mObjectEvens.TryGetValue(ev.GetType(), out action))
  13. {
  14. action(ev);
  15. }
  16. }
  17. protected virtual void RegistAllObjectEvent()
  18. {
  19. RegistObjectEvent<CommonAI.Zone.UnitEffectEvent>(ObjectEvent_UnitEffectEvent);
  20. }
  21. protected void RegistObjectEvent<T>(Action<T> action) where T : CommonAI.Zone.ObjectEvent
  22. {
  23. Type type = typeof(T);
  24. Action<CommonAI.Zone.ObjectEvent> outVal = null;
  25. if (!mObjectEvens.TryGetValue(type, out outVal))
  26. {
  27. mObjectEvens.Add(type, (e) =>
  28. {
  29. action((T)e);
  30. });
  31. }
  32. }
  33. protected virtual void ObjectEvent_UnitEffectEvent(CommonAI.Zone.UnitEffectEvent ev)
  34. {
  35. PlayEffect(ev.effect, EffectRoot.Position(), EffectRoot.Rotation());
  36. }
  37. }
  38. }