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.
47 lines
1.3 KiB
47 lines
1.3 KiB
using System.Collections.Generic;
|
|
using CoreGame;
|
|
using UnityEngine;
|
|
|
|
namespace CoreGame.Render
|
|
{
|
|
[Combat]
|
|
public class Collider2DProxy : ProxyBase
|
|
{
|
|
public List<Collider2D> cs;
|
|
|
|
protected override void Initialize(GameObject go, CombatEntity ent)
|
|
{
|
|
cs = ListPool<Collider2D>.Pop();
|
|
go.GetComponentsInChildren(false, cs);
|
|
var fac = ent.faction;
|
|
// 巨型怪物可能多个碰撞体
|
|
for (int i = 0; i < cs.Count; i++)
|
|
{
|
|
AddCollider(cs[i], fac, ent.isObstacle);
|
|
}
|
|
}
|
|
|
|
public void AddCollider(Collider2D c, FactionComponent fac, bool isObstacle)
|
|
{
|
|
c.enabled = true;
|
|
c.gameObject.layer = isObstacle ? ColliderSrv.s_ObstacleLayer : ColliderSrv.GetLayer(fac.faction);
|
|
ColliderSrv.AddCollider(c, ent.creationIndex);
|
|
}
|
|
|
|
public void FillColliderByInit(Collider2D c, FactionComponent fac, bool isObstacle)
|
|
{
|
|
AddCollider(c, fac, isObstacle);
|
|
cs.Add(c);
|
|
}
|
|
|
|
public void OnComponentRemoved()
|
|
{
|
|
for (int i = 0; i < cs.Count; i++)
|
|
{
|
|
ColliderSrv.RemoveCollider(cs[i]);
|
|
}
|
|
|
|
ListPool<Collider2D>.Push(ref cs);
|
|
}
|
|
}
|
|
}
|