Пример #1
0
            public IState OnStateUpdate()
            {
                if (owner.Exploding)
                {
                    owner.locations = owner.GetAdjacentLocation(owner.Transform.Position);

                    owner.GetComponent <AnimationRenderer>().Enabled = false;

                    for (int i = 0; i < owner.locations.Count; i++)
                    {
                        owner.explosionList[i].Transform.Position = owner.locations[i];
                        owner.explosionList[i].Active             = true;
                    }

                    if (oneTimeSpawn)
                    {
                        foreach (Explosion item in owner.explosionList)
                        {
                            Spawn(item);
                        }
                        oneTimeSpawn = false;
                    }

                    owner.Exploding = false;
                }

                if (timer.IsActive)
                {
                    timer.Update(false);
                }

                if (!timer.IsActive)
                {
                    #region Explosions recycle

                    for (int i = 0; i < owner.explosionList.Count; i++)
                    {
                        owner.explosionList[i].Active = false;
                        owner.explosionList[i].Reset();
                    }

                    #endregion

                    owner.Active = false;
                    GlobalFactory <Bomb> .Recycle(typeof(Bomb), owner);

                    // Pool<Bomb>.RecycleInstance
                    // (
                    //     owner, x =>
                    //     {
                    //         x.Active = false;
                    //     }
                    // );

                    OnStateExit();
                    Next.OnStateEnter();
                    return(Next);
                }
                return(this);
            }
Пример #2
0
            public IState OnStateUpdate()
            {
                if (Input.IsKeyDown(KeyCode.Space) && !timer.IsActive)
                {
                    Bomb bomb = GlobalFactory <Bomb> .Get(typeof(Bomb));

                    bomb.Active = true;
                    bomb.GetComponent <AnimationRenderer>().Enabled = true;
                    bomb.Transform.Position = new Vector2((int)(owner.Transform.Position.X + 0.5f), (int)(owner.Transform.Position.Y + 0.5f));

                    //AudioManager.PlayClip(AudioType.SOUND_DROP);

                    if (owner.CurrentExplosion == 0)
                    {
                        bomb.IsBig = false;
                    }
                    else
                    {
                        bomb.IsBig = true;
                    }


                    if (firstTimeSpawn)
                    {
                        GameObject.Spawn(bomb);
                        Console.WriteLine("first spawn time of bomb");
                        firstTimeSpawn = false;
                    }

                    timer.Start(true);
                }

                //Maybe no restart
                if (timer.IsActive)
                {
                    timer.Update(true);
                }

                return(this);
            }