2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.1 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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));
}
}
}