Beispiel #1
0
    protected override void Awake()
    {
        base.Awake();

        CorouWaiter.WaitFor(() => PlayerController.I != null, Subscribe, () => this == null);
        void Subscribe()
        {
            this.userControl.OnMove += dir =>
            {
                if (!isActive)
                {
                    return;
                }
                PlayerController.I.Player.Motor.Move(dir);
            };
            this.userControl.OnStartShoot += () =>
            {
                if (!isActive)
                {
                    return;
                }
                Debug.Log($"Start shooting");
                PlayerController.I.Player.Combat.StartShooting();
            };
            this.userControl.OnStopShoot += () =>
            {
                if (!isActive)
                {
                    return;
                }
                Debug.Log($"Stop shooting");
                PlayerController.I.Player.Combat.StopShooting();
            };
        }
    }
        public Coroutine Unload(Action <float> onProgress = null)
        {
            if (this.isUnloading)
            {
                return(null);
            }
            if (!IsLoaded)
            {
                return(null);
            }
            return(CorouWaiter.Start(GetRoutine()));

            IEnumerator GetRoutine()
            {
                try { OnStartUnload(); } catch (Exception e) { Debug.LogError(e); }
                this.isUnloading = true;
                var  operation = SceneManager.UnloadSceneAsync(this.BuildIndex);
                bool done      = false;

                OnUnload += Unloaded;
                void Unloaded(SceneWrapper wrapper)
                {
                    OnUnload -= Unloaded;
                    done      = true;
                }

                while (!done)
                {
                    onProgress?.Invoke(operation.progress / 0.9f);
                    yield return(null);
                }
                this.isUnloading = false;
                try { OnFinishUnload(); } catch (Exception e) { Debug.LogError(e); }
            }
        }
Beispiel #3
0
    public static Coroutine StopGame()
    {
        return(CorouWaiter.Start(Routine()));

        IEnumerator Routine()
        {
            PauseManager.PauseEnabled = false;
            yield return(SceneLoadingManager.LoadMenu());
        }
    }
Beispiel #4
0
    public static void StartLevel(int id)
    {
        _currentLevelId = id;
        Debug.LogWarning($"START LEVEL: {_currentLevelId}");
        CorouWaiter.Start(Routine());
        IEnumerator Routine()
        {
            PauseManager.PauseEnabled = true;
            yield return(SceneLoadingManager.LoadGame());

            MatchController.I.StartMatch(id);
        }
    }
    public static Coroutine FirstLoad()
    {
        return(CorouWaiter.Start(GetRoutine()));

        IEnumerator GetRoutine()
        {
            yield return(ShowWaitScreen(true));

            yield return(UnloadAll());

            yield return(LoadScenes(MainMenuScenes));

            yield return(HideWaitScreen());
        }
    }
Beispiel #6
0
    public static Coroutine StartGame()
    {
        return(CorouWaiter.Start(Routine()));

        IEnumerator Routine()
        {
            yield return(SceneLoadingManager.LoadGame(onCompleteLoad: () => InitGame()));
        }

        void InitGame()
        {
            GameView.I.Init();
            PauseManager.PauseEnabled = true;
        }
    }
    public static Coroutine LoadGame()
    {
        return(CorouWaiter.Start(GetRoutine()));

        IEnumerator GetRoutine()
        {
            yield return(ShowWaitScreen());

            yield return(UnloadAll());

            yield return(LoadScenes(GameScenes));

            yield return(HideWaitScreen());
        }
    }
Beispiel #8
0
    public static Coroutine StartGame()
    {
        return(CorouWaiter.Start(Routine()));

        IEnumerator Routine()
        {
            yield return(SceneLoadingManager.LoadGame(onCompleteLoad: () => InitGame()));
        }

        void InitGame()
        {
            GameView.I.Init();
            GameView.I.Player.OnAllPlanetsCaptured += () => PopupManager.OpenPopup <EndLevelPopup>().SetWindow(true);
            PauseManager.PauseEnabled = true;
        }
    }
    public static Coroutine LoadGame(Action onStartLoad = null, Action onCompleteLoad = null)
    {
        return(CorouWaiter.Start(GetRoutine()));

        IEnumerator GetRoutine()
        {
            yield return(ShowWaitScreen());

            onStartLoad?.Invoke();
            yield return(UnloadAll());

            yield return(LoadScenes(GameScenes));

            onCompleteLoad?.Invoke();
            yield return(HideWaitScreen());
        }
    }
Beispiel #10
0
    public Coroutine Hide(bool forced = false)
    {
        return(CorouWaiter.Start(GetRoutine()));

        IEnumerator GetRoutine()
        {
            if (!forced)
            {
                this.background.color = this.background.color.SetAlpha(1f);
                this.spinnerContainer.anchoredPosition = this.spinnerPointOn.anchoredPosition;
                var sequence = DOTween.Sequence()
                               .Append(this.background.DOFade(0f, this.duration).SetEase(Ease.InOutSine))
                               .Join(this.spinnerContainer.DOAnchorPos(this.spinnerPointOff.anchoredPosition, this.duration).SetEase(Ease.InSine));
                yield return(sequence.WaitForCompletion(true));
            }
            this.waitScreenGo.SetActive(false);
            yield break;
        }
    }
        public static bool AppendScene(int buildIndex, Action <float> onProgress = null, Action <Scene> onLoaded = null)
        {
#if UNITY_EDITOR
            Debug.Log("Append Scene!");
#endif
            if (!IsValidIndex(buildIndex))
            {
                throw new InvalidOperationException("Index of scene is wrong!");
            }
            var dict = m_ScenesInLoadActionDict;
            if (dict.ContainsKey(buildIndex))
            {
#if UNITY_EDITOR
                Debug.LogWarning("Append Failed!");
#endif
                return(false);
            }
            var scene = SceneManager.GetSceneByBuildIndex(buildIndex);
            if (scene.isLoaded)
            {
#if UNITY_EDITOR
                Debug.LogWarning("Append Failed!");
#endif
                return(false);
            }
            dict.Add(buildIndex, onLoaded);
            var operation = SceneManager.LoadSceneAsync(buildIndex, LoadSceneMode.Additive);
            if (operation == null)
            {
#if UNITY_EDITOR
                Debug.LogWarning("Append Failed!");
#endif
                return(false);
            }
            operation.allowSceneActivation = true;
            if (onProgress != null)
            {
                CorouWaiter.RepeatInUpdate(
                    () => { onProgress(operation.progress); },
                    () => operation.isDone);
            }
            return(true);
        }
    public static Coroutine UnloadScenes(IList <SceneKind> kinds)
    {
        return(CorouWaiter.Start(GetRoutine()));

        IEnumerator GetRoutine()
        {
            var operations = new List <Coroutine>(kinds.Count);

            foreach (var kind in kinds)
            {
                var wrapper = SceneWrapper.GetWrapper(kind);
                operations.Add(wrapper.Unload());
            }
            foreach (var operation in operations)
            {
                yield return(operation);
            }
            yield break;
        }
    }
        public Coroutine Load(bool allowActivation = true, LoadSceneMode mode = LoadSceneMode.Additive, Action <float> onProgress = null)
        {
            if (this.isLoading)
            {
                return(null);
            }
            if (IsLoaded)
            {
                return(null);
            }
            return(CorouWaiter.Start(GetRoutine()));

            IEnumerator GetRoutine()
            {
                try { OnStartLoad(); } catch (Exception e) { Debug.LogError(e); }
                this.isLoading = true;
                var operation = SceneManager.LoadSceneAsync(this.BuildIndex, mode);

                operation.allowSceneActivation = allowActivation;
                bool done = false;

                OnLoad += Loaded;
                void Loaded(SceneWrapper wrapper)
                {
                    OnLoad -= Loaded;
                    done    = true;
                }

                while (!done)
                {
                    onProgress?.Invoke(operation.progress / 0.9f);
                    yield return(null);
                }
                this.isLoading = false;
                try { OnFinishLoad(); } catch (Exception e) { Debug.LogError(e); }
            }
        }
    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);
            }
        }
    }