You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
using System; |
|
using System.Linq; |
|
|
|
namespace ET.PeopleBehave |
|
{ |
|
public class PeopleBehaveComponentAwakeSystem: AwakeSystem<PeopleBehaveComponent> |
|
{ |
|
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; |
|
} |
|
} |
|
} |
|
}
|
|
|