示例#1
0
        /// <summary>
        /// Entry point to create a new level
        /// </summary>
        public void Init(int level, float animationSpeed = 1f, float delayScale = 1f, bool restart = false)
        {
            if (level < 0 || level > _puzzleSpawner.LevelCount)
            {
                Debug.LogWarning("Requested level is outside of bounds, ignoring request");
                return;
            }

            // Destroy the previous level
            _puzzleSpawner.DestroyBoard();

            _saveState.Started = true;

            // Spawn the new level
            _puzzle      = _puzzleSpawner.SpawnBoard(level, animationSpeed, delayScale, restart);
            _playerState = _puzzle.PlayerState;
            CurrentLevel = level;

            // Reset the puzzle view state
            _arcMap.Reset(_puzzleSpawner.ArcMap);
            _fieldMap.Reset(_puzzleSpawner.FieldMap);
            _nodeMap = _puzzleSpawner.NodeMap;

            // Init all scripts that require additional information on startup
            _boardAction.Init();
            _puzzleView.Init(_puzzle.StartNode.Position, _puzzle.BoardSize);
            _boardInput.Init(_puzzleSpawner.NodeMap);

            gameObject.name = $"PuzzleGame ({level})*";

            TimeElapsed += Metadata.TimeElapsed;

            // Start with a pulled node if defined
            if (Metadata.StartPull == Direction.None)
            {
                return;
            }

            var startNode = _nodeMap[_puzzle.StartNode.Position];

            Play(startNode, Metadata.StartPull);

            _puzzleView.Rotate(startNode, PulledArcView, Metadata.StartPull, true);
            _boardAction.HighlightAll();

            LevelStateChanged?.Invoke(LevelState(), _puzzle.Win);
        }