Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        gameFixedUpdate.GameFramesPerLockstep = gameFramesPerLockstep;
        gameFixedUpdate.FixedStepTime         = fixedTimestepMilliseconds / 1000.0f;

        if (Input.GetKeyUp(KeyCode.S))
        {
            var gameState = GetGameState();
            SaveState(gameState);
            Debug.Log((gameState as MyCustomGameState).GetStateString());
        }

        if (Input.GetKeyUp(KeyCode.P))
        {
            StartPlayback();
            return;
        }

        if (Input.GetKeyUp(KeyCode.R))
        {
            // resets game fixed update state...
            StartRecording();

            return;
        }

        if (_replayController.IsRecording)
        {
            gameFixedUpdate.Update(Time.deltaTime);

            if (Input.GetMouseButtonUp(1))
            {
                Vector2 position = camera.ScreenToWorldPoint(Input.mousePosition);

                _commandSender.EnqueueCommand(ConfigureCommand(new MoveCommand(position)));

                feedbackClick.ShowFeedback(position);
            }

            if (Input.touchCount > 0)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Ended)
                {
                    Vector2 position = camera.ScreenToWorldPoint(Input.GetTouch(0).position);

                    _commandSender.EnqueueCommand(ConfigureCommand(new MoveCommand(position)));

                    feedbackClick.ShowFeedback(position);
                }
            }
        }
        else
        {
            // playback...

            // if already at last frame, then dont update anymore...
            if (_replayController.IsFinished())
            {
                return;
            }

            gameFixedUpdate.Update(Time.deltaTime * replayPlaybackSpeedMultiplier);

//			_replay.ReplayCommands ();
        }
    }