Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / manager / ObjectManager.cs
@小李xl 小李xl on 8 Nov 2023 937 bytes 给子弹加上了对象池回收功能

public static class ObjectManager
{
    public static Explode GetExplode(string resPath)
    {
        var explode = ObjectPool.GetItem<Explode>(resPath);
        if (explode == null)
        {
            explode = ResourceManager.LoadAndInstantiate<Explode>(resPath);
            explode.Logotype = resPath;
        }

        return explode;
    }

    public static Bullet GetBullet(string id)
    {
        var bullet = ObjectPool.GetItem<Bullet>(id);
        if (bullet == null)
        {
            bullet = ActivityObject.Create<Bullet>(id);
            bullet.Logotype = id;
        }

        return bullet;
    }
    
    public static Laser GetLaser(string resPath)
    {
        var bullet = ObjectPool.GetItem<Laser>(resPath);
        if (bullet == null)
        {
            bullet = ResourceManager.LoadAndInstantiate<Laser>(resPath);
            bullet.Logotype = resPath;
        }

        return bullet;
    }
}