devomage

MultiplePrefabSpawnManager

Mar 2nd, 2021 (edited)
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. /// ---------------------------------------------
  2. /// Ultimate Character Controller
  3. /// Copyright (c) Opsive. All Rights Reserved.
  4. /// https://www.opsive.com
  5. /// ---------------------------------------------
  6.  
  7. namespace Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game
  8. {
  9.     using UnityEngine;
  10.     using Photon.Realtime;
  11.  
  12.     /// <summary>
  13.     /// Manages multiple character instantiation within a PUN room.
  14.     /// Add this script to the 'PhotonPUN\Scripts\Game' folder.
  15.     /// 1) Open 'DemoRoom' scene
  16.     /// 2) Find 'PunGame'
  17.     /// 3) Replace SingplePlayerSpawnManager with this component.
  18.     /// </summary>
  19.     public class MultiplePrefabSpawnManager : SpawnManagerBase
  20.     {
  21.         [Tooltip("Index of the prefab array.")]
  22.         [SerializeField] protected CharacterPrefabType m_CharacterType = CharacterPrefabType.Nolan;
  23.         [Tooltip("A reference to the character that PUN should spawn. This character must be setup using the PUN Multiplayer Manager.")]
  24.         [SerializeField] protected GameObject[] m_CharacterList;
  25.  
  26.         public enum CharacterPrefabType
  27.         {
  28.             Nolan = 0,
  29.             RobotKyle = 1,
  30.         }
  31.  
  32.         public CharacterPrefabType CharacterType { get { return m_CharacterType; } set { m_CharacterType = value; } }
  33.         public GameObject Character { get { return m_CharacterList[(int)m_CharacterType]; } }
  34.  
  35.         /// <summary>
  36.         /// Abstract method that allows for a character to be spawned based on the game logic.
  37.         /// </summary>
  38.         /// <param name="newPlayer">The player that entered the room.</param>
  39.         /// <returns>The character prefab that should spawn.</returns>
  40.         protected override GameObject GetCharacterPrefab(Player newPlayer)
  41.         {
  42.             // Return the same character for all instances.
  43.             return Character;
  44.         }
  45.         public GameObject GetCharacterPrefab(Player newPlayer, CharacterPrefabType characterType)
  46.         {
  47.             m_CharacterType = characterType;
  48.             return Character;
  49.         }
  50.     }
  51. }
Add Comment
Please, Sign In to add comment