|  |  |  | using System; | 
					
						
							|  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  | using System.Linq; | 
					
						
							|  |  |  | using System.Reflection; | 
					
						
							|  |  |  | using DesperateDevs.Utils; | 
					
						
							|  |  |  | using UnityEngine; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Game | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public class BehaviorTreePoolManager : ObjectPoolBase<BehaviorTreePoolManager> | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         private readonly Dictionary<string, EventCallbackCreate> _dict = new Dictionary<string, EventCallbackCreate>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public override void OnCreate() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             var interfaceType = typeof(IAIObject); | 
					
						
							|  |  |  |             foreach (var type in interfaceType.Assembly.GetTypes()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (!interfaceType.IsAssignableFrom(type)) continue; | 
					
						
							|  |  |  |                 if (type.IsGenericType) continue; | 
					
						
							|  |  |  |                 if (type.IsInterface) continue; | 
					
						
							|  |  |  |                 if (type.BaseType?.BaseType == null) continue; | 
					
						
							|  |  |  |                 var method = type.BaseType.BaseType.GetMethod("GetCreator", BindingFlags.Static | BindingFlags.Public); | 
					
						
							|  |  |  |                 if (method == null) continue; | 
					
						
							|  |  |  |                 var creator = (EventCallbackCreate)method.Invoke(null, new object[] { }); | 
					
						
							|  |  |  |                 _dict.Add(type.Name, creator); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public BehaviorTreePoolItem CreateAIEntity(GameEntity entity, string name) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (!_dict.ContainsKey(name)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return CreateAIEntity(entity,"AIEntityDefault"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             var ret = Create<BehaviorTreePoolItem>(name, (item) => | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 item.AIObject = _dict[name](); | 
					
						
							|  |  |  |                 item.AIObject.Create(); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |             ((IAIEntity)ret.AIObject).Reset(entity); | 
					
						
							|  |  |  |             return ret; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public BehaviorTreePoolItem CreateAILevel(string name) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (!_dict.ContainsKey(name)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return CreateAILevel("AIDirectorDefault"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             var ret = Create<BehaviorTreePoolItem>(name, (item) => | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 item.AIObject = _dict[name](); | 
					
						
							|  |  |  |                 item.AIObject.Create(); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |             return ret; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public class BehaviorTreePoolItem : ObjectPoolItemBase | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         public IAIObject AIObject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public void Tick() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             AIObject.Tick(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |