using System.Collections.Generic; using CoreGame; using UnityEngine; namespace CoreGame.Render { [Combat] public class Collider2DProxy : ProxyBase { public List cs; protected override void Initialize(GameObject go, CombatEntity ent) { cs = ListPool.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.Push(ref cs); } } }