liveBook · Manning

Static class

As explained in High Performance Unity Game Development

A class that cannot be instantiated and whose members are associated with the class itself rather than with object instances.

A static class provides logic methods callable from anywhere. In this game architecture, those methods take in data, transform it, and return results; GameData is modified only through a logic method. section 4.4

Listing 4.3 Our static logic class
public static class Logic
{
   public static void AllocateGameData(GameData gameData, Balance balance)
    {
        #A
    }
 
    public static void StartGame(GameData gameData, Balance balance)
    {
        #B
    }
 
    static Vector2 getEnemySpawnPosition(GameData gameData, Balance balance)
    {
        #C
    }
 
    static Vector2 rotateVector(Vector2 a, double degrees)
    {
        #D
    }
 
    public static void Tick(
        GameData gameData, 
        Balance balance, 
        float dt, 
        out bool gameOver)
    {
        #E
    }
 
    static void moveEnemies(GameData gameData, Balance balance, float dt)
    {
        #F
    }
 
    static void doEnemyToEnemyCollision(GameData gameData, Balance balance)
    {
        #G
    }
 
    static void checkEnemyOutOfBounds(GameData gameData, Balance balance)
    {
        #H
    }
 
    static void movePlayer(GameData gameData, Balance balance, float dt)
    {
        #I
    }
 
    public static void MouseMove(GameData gameData, 
                                 Vector2 mouseCurrentPos, 
                                 Vector2 mouseDownPos)
    {
        #J
    }
 
    public static void MouseUp(GameData gameData)
    {
        #K
    }
 
    static bool checkGameOver(GameData gameData, Balance balance)
    {
        #L
    }
}

The Logic class groups public entry points such as AllocateGameData and Tick with private helper methods. section 4.4

How High Performance Unity Game Development covers it

How deep it goes
Explains static access and shows public and private static methods without detailing runtime implementation.
Examples
Demonstrates AllocateGameData, StartGame, and Tick in a game-logic class.
What you can do after
Apply it via static methods to call game logic from anywhere and restrict GameData changes to logic methods.
How it connects
Connects static classes to data-oriented functions that take data, transform it, and output results.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of High Performance Unity Game Development. The section links point to the parts of the book it draws on.