PlayerCreatorUtilities

It is a helper class that performs operations related to creating the player object or changing the existing object.

Member

private static MonoBehaviorHook _monoBehaviorHook;

  • Stores monobehaviour to use coroutine operations

Methods

  1. public static void TryCreatePlayerOrReplace(NetworkConnection conn, GameObject prefab, Action<GameObject> onCompleted = null)
    • Parameters

      • conn: Owner of the player to be created or replaced

      • prefab: Prefab of the object to be created

      • onCompleted: action called when creation or replace is complete

    • If the identitiy value of the connecti is not null, it means that the player object exists and calls the replace method.

    • If null, it calls the CreatePlayer method.

  2. public static void CreatePlayer(NetworkConnection conn, GameObject prefab, Action<GameObject> onCompleted = null)
    • Paramters

      • conn: Owner of the player to be created

      • prefab: Prefab of the object to be created

      • onCompleted: action called when creation is complete

    • Returns connection if it is not connected to the client.

    • Creates the player object with the spawnPlayer method.

    • then add it to the connection as player.

    • After these operations, onCompleted action is triggered.

  3. public static void ReplacePlayer(NetworkConnection conn, GameObject prefab, Action<GameObject> onCompleted = null)
    • Paramters

      • conn: Owner of the player to be replaced

      • prefab: Prefab of the object to be created

      • onCompleted: action called when replace is complete

    • It first calls the removePlayer function.

    • When the player deletion process is completed, it creates the player with the CreatePlayer method.

  4. public static void RemovePlayer(NetworkConnection conn)
    • Paramters

      • conn: Owner of the player to be created

    • Removes and deletes the connection's player object from the connection

  5. private static GameObject SpawnPlayer(NetworkConnection conn, GameObject prefab)
    • Paramters

      • conn: Owner of the player to be created

      • prefab: Prefab of the object to be created

    • Gets the room information of the connection.

    • If it is in the room and the room has a scene, it creates the object for that scene.

    • If it doesn't exist, it creates it for the currently active scene.

  6. private static void Init()
    • Returns if monoBehaviourHook is not null.

    • If it is null, it creates a new object and performs donDestroyOnLoad.

    • Then, it adds the MonoBehaviorHook script to the object and assigns it to the variable.

Last updated