コード例 #1
0
 void OnCollisionExit2D(Collision2D collision)
 {
     foreach (var tag in _exit.Where(item => collision.gameObject.GetEnumTagName() == item))
     {
         CollisionBus.Notify(CollisionBus.Timing.Exit, gameObject, collision.gameObject, collision);
     }
 }
コード例 #2
0
 void OnCollisionStay2D(Collision2D collision)
 {
     foreach (var tag in _stay.Where(item => collision.gameObject.GetEnumTagName() == item))
     {
         CollisionBus.Notify(CollisionBus.Timing.Stay, gameObject, collision.gameObject, collision);
     }
 }
コード例 #3
0
    void Awake()
    {
        CollisionBus.Subscribe(CollisionBus.Timing.Enter, TagName.Enemy, TagName.Ball, (enemy, ball, collision) =>
        {
            var killable = enemy.GetComponent <Killable>();
            killable.TakeDamage(_ballDamage);
        });

        CollisionBus.Subscribe(CollisionBus.Timing.Enter, TagName.Wall, TagName.Ball, (wall, ball, collision) =>
        {
            GlobalAudioSource.PlayOneShot(_wallHitSE);
        });

        CollisionBus.Subscribe(CollisionBus.Timing.Enter, TagName.Player, TagName.Ball, (player, ball, collision) =>
        {
            GlobalAudioSource.PlayOneShot(_barHitSE);
        });

        CollisionBus.Subscribe(CollisionBus.Timing.Enter, TagName.PlayerBullet, TagName.Ball, (bullet, ball, collision) =>
        {
            GlobalAudioSource.PlayOneShot(_barHitSE);
            var vfx = ObjectPool.Alloc(_bulletHitVFX);
            vfx.transform.position = bullet.transform.position;
            ObjectPool.Free(vfx, 1f);
            ObjectPool.Free(bullet);
        });

        CollisionBus.Subscribe(CollisionBus.Timing.Enter, TagName.PlayerBullet, TagName.Enemy, (bullet, enemy, collision) =>
        {
            var killable = enemy.GetComponent <Killable>();
            killable.TakeDamage(_bulletDamage);
            GlobalAudioSource.PlayOneShot(_bulletHitSE);
            var vfx = ObjectPool.Alloc(_bulletHitVFX);
            vfx.transform.position = bullet.transform.position;
            ObjectPool.Free(vfx, 1f);
            ObjectPool.Free(bullet);
        });

        CollisionBus.Subscribe(CollisionBus.Timing.Enter, TagName.LaserFence, TagName.Ball, (fence, ball, collision) =>
        {
            var vfx = ObjectPool.Alloc(_ballDieVFX);
            vfx.transform.position = ball.transform.position;
            ObjectPool.Free(vfx, 1f);
            ObjectPool.Free(ball);

            GlobalAudioSource.PlayOneShot(_ballDieSE);

            Observable.Timer(System.TimeSpan.FromSeconds(1f)).Subscribe(_ =>
            {
                var newBall  = ObjectPool.Alloc(_ball);
                var spawnVFX = ObjectPool.Alloc(_ballSpawnVFX);
                newBall.transform.position  = Vector2.zero;
                spawnVFX.transform.position = newBall.transform.position;
                ObjectPool.Free(spawnVFX, 1f);
            });

            Camera.main.transform.DOComplete();
            Camera.main.transform.DOShakePosition(0.5f, 0.3f);
        });
    }
コード例 #4
0
ファイル: TestCode.cs プロジェクト: tsuki-fox/InvaderKuzushi
    public void CollisionBusTest()
    {
        var goA = new GameObject("objA");
        var goB = new GameObject("objB");

        CollisionBus.Notify(CollisionBus.Timing.Enter, goA, goB, null);
        CollisionBus.Subscribe(CollisionBus.Timing.Enter, TagName.Untagged, TagName.Untagged, (v1, v2, v3) => { });
    }
コード例 #5
0
 void OnDestroy()
 {
     CollisionBus.Clean();
 }