using System; using System.Linq; namespace ET.PeopleBehave { public class PeopleBehaveComponentAwakeSystem: AwakeSystem { public override void Awake(PeopleBehaveComponent self) { PeopleBehaveComponent.Instance = self; self.Awake(); } } [FriendClass(typeof(PeopleBehaveComponent))] public static class PeopleBehaveComponentSystem { public static void Awake(this PeopleBehaveComponent self) { var behaves = Game.EventSystem.GetTypes(typeof (BehaveAttribute)); foreach (var type in behaves) { object[] attrs = type.GetCustomAttributes(typeof (BehaveAttribute), false); if (attrs.Length == 0) { continue; } BehaveAttribute behaveAttribute = attrs[0] as BehaveAttribute; BehaveBase behave = Activator.CreateInstance(type) as BehaveBase; self.AllBehaveDict.Add(behaveAttribute.BehaveID, behave); } } public static void HandlePeopleBehave(this PeopleBehaveComponent self, People people) { int behaveId = people.GetBehaveType(); if (!self.AllBehaveDict.ContainsKey(behaveId)) { return; } try { self.AllBehaveDict[behaveId].Handle(people); } catch (Exception e) { Log.Error(e); throw; } } } }