|  |  | using System;
 | 
						
						
						
							|  |  | using System.Collections.Generic;
 | 
						
						
						
							|  |  | using Entitas;
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  | //本项目出于体量和易用性考虑,只使用一个context 以及一个系统组
 | 
						
						
						
							|  |  | //为了简化ecs用法,这里做封装
 | 
						
						
						
							|  |  | namespace Game
 | 
						
						
						
							|  |  | {
 | 
						
						
						
							|  |  |     public abstract partial class Util
 | 
						
						
						
							|  |  |     {
 | 
						
						
						
							|  |  |         public static GameEntity GetEntity(int id)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return Contexts.sharedInstance.game.GetEntityWithID(id);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static void TryGetEntity(int id, Action<GameEntity> action, Action action2 = null)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             var entity = GetEntity(id);
 | 
						
						
						
							|  |  |             if (entity != null)
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 action(entity);
 | 
						
						
						
							|  |  |             }
 | 
						
						
						
							|  |  |             else
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 action2?.Invoke();
 | 
						
						
						
							|  |  |             }
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static void DestroyEntity(int id)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             DestroyEntity(Util.GetEntity(id));
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static void DestroyEntity(GameEntity entity)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             var id = entity.iD;
 | 
						
						
						
							|  |  |             id.Data.IsDestroy = true;
 | 
						
						
						
							|  |  |             if (!string.IsNullOrEmpty(id.Data.EffectDestroy))
 | 
						
						
						
							|  |  |             {
 | 
						
						
						
							|  |  |                 Util.CastHitEffect(id.Data.EffectDestroy, entity.ID());
 | 
						
						
						
							|  |  |             }
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static GameEntity GetMaster()
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return EcsManager.Instance.GetMaster();
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static int GetMasterID()
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return EcsManager.Instance.GetMasterID();
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static void GetAllEntities(List<int> allEnemies, ETeam team)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             EcsManager.Instance.GetAllEntities(allEnemies, team);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  |         
 | 
						
						
						
							|  |  |         public static void ForeachEnemies(ETeam team, Action<GameEntity> f)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             EcsManager.Instance.ForeachEnemies(team, f);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static GameEntity GetMasterSoul()
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return EcsManager.Instance.GetMasterSoul();
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static int GetMasterSoulID()
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return EcsManager.Instance.GetMasterSoulID();
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static IGroup<GameEntity> AllOf(params int[] indices)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return Contexts.sharedInstance.game.GetGroup(Matcher<GameEntity>.AllOf(indices));
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static IGroup<GameEntity> AllOf(params IMatcher<GameEntity>[] matchers)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return Contexts.sharedInstance.game.GetGroup(Matcher<GameEntity>.AllOf(matchers));
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static IGroup<GameEntity> AnyOf(params int[] indices)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return Contexts.sharedInstance.game.GetGroup(Matcher<GameEntity>.AnyOf(indices));
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static IGroup<GameEntity> AnyOf(params IMatcher<GameEntity>[] matchers)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return Contexts.sharedInstance.game.GetGroup(Matcher<GameEntity>.AnyOf(matchers));
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static IGroup<GameEntity> GetGroup(IMatcher<GameEntity> matcher)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return Contexts.sharedInstance.game.GetGroup(matcher);
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  | 
 | 
						
						
						
							|  |  |         public static IGroup<GameEntity> GetGroup(params IMatcher<GameEntity>[] matchers)
 | 
						
						
						
							|  |  |         {
 | 
						
						
						
							|  |  |             return GetGroup((Entitas.Matcher<GameEntity>)Matcher<GameEntity>.AnyOf(matchers));
 | 
						
						
						
							|  |  |         }
 | 
						
						
						
							|  |  |     }
 | 
						
						
						
							|  |  | } |