Skip to content

Overview

Seperation of Game Logic And Presentation

Your game logic should only be implemented in the IFrameSync interfaces. All the Unity MonoBehaviour events/messages are considered indeterministic, you should use them for presentation only.

Deterministic Description
IFrameSyncOnStart Called before the first IFrameSyncPlayerUpdate and IFrameSyncComputerUpdate . Implement this interface to initialzie the component.
IFrameSyncPlayerUpdate Called by the FrameSyncEngine to update the player owned FrameSyncBehaviour during frame simulation.
IFrameSyncComputerUpdate Called by the FrameSyncEngine to update the computer owned FrameSyncBehaviour during frame simulation.
IFrameSyncTimerEventHandler Called when a FrameSyncTimer event occurs.
Indeterministic Description
Start called when the GameObject begins to exist (either when the Scene is loaded, or the GameObject is instantiated).
Update called every frame.
FixedUpdate called every physics timestep.
OnCollisionEnter and OnTriggerEnter called when physics collisions or triggers occur.

Networked Input

Before the frame simulation starts, the FrameSyncEngine reads the input data of the frame and assign the input values to the players.

During a frame simulaiton, the FrameSyncEngine updates the FrameSyncBehaviours and your IFrameSyncPlayerUpdate MonoBehaivours will be updated. The player that owns the FrameSyncBehaviour will be passed into the OnPlayerUpdate() method. You can read the inputs of the player by calling player.GetInput{InputName}();

Info

The player.GetInput{InputName}() method is generated when you save the InputSettings of the game. See InputSettings for more details.

Example Script Showing The Seperation of Game Logic And Presentation

public class MyExampleScript : MonoBehaviour, IFrameSyncOnStart, IFrameSyncPlayerUpdate
{
    //Displays player's score in a label, not used in the Game Logic
    public Text playerScoreLabel;

    //the player score, this value is used in the Game Logic
    int playerScore

    //==========Unity Events==========
    //only used to read playerScore and update the playerScoreLabel
    void Update()
    {
        playerScoreLabel.text = playerScore.ToString();
    }

    //==========Game Logic==========
    //IFrameSyncOnStart
    //used for initialize the component
    public void OnStart(FrameSyncBehaviour frameSyncBehaviour)
    {
        playerScore = 0;
    }

    //IFrameSyncPlayerUpdate
    //used to read player input and change player score
    public void OnPlayerUpdate(FrameSyncPlayer player, FrameSyncGame game, FrameSyncUpdateType frameSyncUpdateType)
    {
        bool addScore = player.GetInputAddScore();

        if(addScore)
        {
            playerScore++;
        }
    }
}