コード例 #1
0
    protected override void OnInit()
    {
        foreach (var btn in this.returnBtns)
        {
            btn.onClick.AddListener(() => Hide(null));
        }
        this.cellReference.GO.SetActive(false);

        var points = this.levelPoints;
        var count  = points.Length;

        for (int i = 0; i < count; ++i)
        {
            int id       = i;
            var preset   = LevelPresetData.GetPreset(id);
            var progress = LevelProgressData.GetProgress(id);
            var cell     = Instantiate(this.cellReference, points[id]);
            cell.GO.SetActive(true);
            cell.Name.text = $"Level {id + 1}";
            cell.SetStars(progress.Stars);
            bool active = id == 0 || LevelProgressData.GetProgress(id - 1).complete;
            cell.SetActive(active);
            if (active)
            {
                cell.StartBtn.onClick.AddListener(() =>
                {
                    var popup = PopupManager.OpenPopup <StartLevelPopup>();
                    popup.SetDescription($"Level {id + 1}\nasteroids: {preset.count}\ntime: {preset.duration}");
                    popup.SetStars(progress.Stars);
                    popup.OnStart += () =>
                    {
                        Hide(null);
                        GameManager.StartLevel(id);
                    };
                });
            }
        }
    }
コード例 #2
0
    public void StartMatch(int levelId)
    {
        this.preset = LevelPresetData.GetPreset(levelId);
        CorouWaiter.Start(Routine());
        IEnumerator Routine()
        {
            yield return(CorouWaiter.WaitFor(() => PlayerController.I != null));

            yield return(CorouWaiter.WaitFor(() => UserHUDController.I != null));

            PlayerController.I.Player.Health.OnDamage += (_, hp) => UserHUDController.I.SetHp(hp);
            PlayerController.I.Player.Health.OnDead   += StopMatch;

            var waitSecond = new WaitForSeconds(1f);
            int counter    = 3;

            while (counter-- > 0)
            {
                Debug.Log(counter + 1);
                yield return(waitSecond);
            }

            Debug.Log("Math started!");

            var waitSpawn = new WaitForSeconds(this.preset.duration / (float)this.preset.count);

            counter = this.preset.count;
            while (counter-- > 0)
            {
                var enemy = spawner.SpawnEnemy();
                enemy.OnCollide += Damage;
                void Damage(Enemy e, Collision c)
                {
                    enemy.OnCollide -= Damage;
                    var health = c.collider.GetComponentInParent <PlayerHealth>();

                    if (health != null)
                    {
                        health.SetDamage(1, enemy.GO);
                    }
                }

                enemy.OnDeadByPlayer += Kill;
                void Kill(Enemy e)
                {
                    enemy.OnDeadByPlayer -= Kill;
                    ++this.killCount;
                }

                enemy.OnDestroyEvent += Destroy;
                void Destroy(Enemy e)
                {
                    enemy.OnDestroyEvent -= Destroy;
                    ++this.destroyCount;
                    if (this.destroyCount == this.preset.count)
                    {
                        StopMatch();
                    }
                }

                yield return(waitSpawn);
            }
        }
    }