# PlayerCreatorUtilities

### Member

`private static MonoBehaviorHook _monoBehaviorHook;`

* Stores monobehaviour to use coroutine operations

### Methods

1. <pre class="language-csharp" data-overflow="wrap"><code class="lang-csharp">public static void TryCreatePlayerOrReplace(NetworkConnection conn, GameObject prefab, Action&#x3C;GameObject> onCompleted = null)
   </code></pre>
   * 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. <pre class="language-csharp" data-overflow="wrap"><code class="lang-csharp">public static void CreatePlayer(NetworkConnection conn, GameObject prefab, Action&#x3C;GameObject> onCompleted = null)
   </code></pre>
   * 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. <pre class="language-csharp" data-overflow="wrap"><code class="lang-csharp">public static void ReplacePlayer(NetworkConnection conn, GameObject prefab, Action&#x3C;GameObject> onCompleted = null)
   </code></pre>
   * 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. ```csharp
   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. ```csharp
   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. ```csharp
   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.
