DemoHubManager.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="DemoHubManager.cs" company="Exit Games GmbH">
  3. // Part of: Photon Unity Demos
  4. // </copyright>
  5. // <summary>
  6. // Used as starting point to let developer choose amongst all demos available.
  7. // </summary>
  8. // <author>developer@exitgames.com</author>
  9. // --------------------------------------------------------------------------------------------------------------------
  10. using UnityEngine;
  11. using UnityEngine.UI;
  12. using UnityEngine.SceneManagement;
  13. using System.Collections.Generic;
  14. using Photon.Pun.Demo.Cockpit;
  15. namespace Photon.Pun.Demo.Hub
  16. {
  17. public class DemoHubManager : MonoBehaviour {
  18. public Text TitleText;
  19. public Text DescriptionText;
  20. public GameObject OpenSceneButton;
  21. public GameObject OpenTutorialLinkButton;
  22. public GameObject OpenDocLinkButton;
  23. string MainDemoWebLink = "https://doc.photonengine.com/en-us/pun/v2/getting-started/pun-intro";
  24. struct DemoData
  25. {
  26. public string Title;
  27. public string Description;
  28. public string Scene;
  29. public string TutorialLink;
  30. public string DocLink;
  31. }
  32. Dictionary<string,DemoData> _data = new Dictionary<string, DemoData>();
  33. string currentSelection;
  34. // Use this for initialization
  35. void Awake () {
  36. PunCockpit.Embedded = false;
  37. OpenSceneButton.SetActive(false);
  38. OpenTutorialLinkButton.SetActive(false);
  39. OpenDocLinkButton.SetActive(false);
  40. // Setup data
  41. _data.Add(
  42. "DemoBoxes",
  43. new DemoData()
  44. {
  45. Title = "Demo Boxes",
  46. Description = "Uses ConnectAndJoinRandom script.\n" +
  47. "(joins a random room or creates one)\n" +
  48. "\n" +
  49. "Instantiates simple prefabs.\n" +
  50. "Synchronizes positions without smoothing.\n" +
  51. "Shows that RPCs target a specific object.",
  52. Scene = "DemoBoxes-Scene"
  53. }
  54. );
  55. _data.Add(
  56. "DemoWorker",
  57. new DemoData()
  58. {
  59. Title = "Demo Worker",
  60. Description = "Joins the default lobby and shows existing rooms.\n" +
  61. "Lets you create or join a room.\n" +
  62. "Instantiates an animated character.\n" +
  63. "Synchronizes position and animation state of character with smoothing.\n" +
  64. "Implements simple in-room Chat via RPC calls.",
  65. Scene = "DemoWorker-Scene"
  66. }
  67. );
  68. _data.Add(
  69. "MovementSmoothing",
  70. new DemoData()
  71. {
  72. Title = "Movement Smoothing",
  73. Description = "Uses ConnectAndJoinRandom script.\n" +
  74. "Shows several basic ways to synchronize positions between controlling client and remote ones.\n" +
  75. "The TransformView is a good default to use.",
  76. Scene = "DemoSynchronization-Scene"
  77. }
  78. );
  79. _data.Add(
  80. "BasicTutorial",
  81. new DemoData()
  82. {
  83. Title = "Basic Tutorial",
  84. Description = "All custom code for connection, player and scene management.\n" +
  85. "Auto synchronization of room levels.\n" +
  86. "Uses PhotonAnimatoView for Animator synch.\n" +
  87. "New Unity UI all around, for Menus and player health HUD.\n" +
  88. "Full step by step tutorial available online.",
  89. Scene = "PunBasics-Launcher" ,
  90. TutorialLink = "https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/intro"
  91. }
  92. );
  93. _data.Add(
  94. "OwnershipTransfer",
  95. new DemoData()
  96. {
  97. Title = "Ownership Transfer",
  98. Description = "Shows how to transfer the ownership of a PhotonView.\n" +
  99. "The owner will send position updates of the GameObject.\n" +
  100. "Transfer can be edited per PhotonView and set to Fixed (no transfer), Request (owner has to agree) or Takeover (owner can't object).",
  101. Scene = "DemoChangeOwner-Scene"
  102. }
  103. );
  104. _data.Add(
  105. "PickupTeamsScores",
  106. new DemoData()
  107. {
  108. Title = "Pickup, Teams, Scores",
  109. Description = "Uses ConnectAndJoinRandom script.\n" +
  110. "Implements item pickup with RPCs.\n" +
  111. "Uses Custom Properties for Teams.\n" +
  112. "Counts score per player and team.\n" +
  113. "Uses Player extension methods for easy Custom Property access.",
  114. Scene = "DemoPickup-Scene"
  115. }
  116. );
  117. _data.Add(
  118. "Chat",
  119. new DemoData()
  120. {
  121. Title = "Chat",
  122. Description = "Uses the Chat API.\n" +
  123. "Simple UI.\n" +
  124. "You can enter any User ID.\n" +
  125. "Automatically subscribes some channels.\n" +
  126. "Allows simple commands via text.\n" +
  127. "\n" +
  128. "Requires configuration of Chat App ID in ServerSettings.",
  129. Scene = "DemoChat-Scene",
  130. DocLink = "http://j.mp/2iwQkPJ"
  131. }
  132. );
  133. _data.Add(
  134. "RPGMovement",
  135. new DemoData()
  136. {
  137. Title = "RPG Movement",
  138. Description = "Demonstrates how to use the PhotonTransformView component to synchronize position updates smoothly using inter- and extrapolation.\n" +
  139. "\n" +
  140. "This demo also shows how to setup a Mecanim Animator to update animations automatically based on received position updates (without sending explicit animation updates).",
  141. Scene = "DemoRPGMovement-Scene"
  142. }
  143. );
  144. _data.Add(
  145. "MecanimAnimations",
  146. new DemoData()
  147. {
  148. Title = "Mecanim Animations",
  149. Description = "This demo shows how to use the PhotonAnimatorView component to easily synchronize Mecanim animations.\n" +
  150. "\n" +
  151. "It also demonstrates another feature of the PhotonTransformView component which gives you more control how position updates are inter-/extrapolated by telling the component how fast the object moves and turns using SetSynchronizedValues().",
  152. Scene = "DemoMecanim-Scene"
  153. }
  154. );
  155. _data.Add(
  156. "2DGame",
  157. new DemoData()
  158. {
  159. Title = "2D Game Demo",
  160. Description = "Synchronizes animations, positions and physics in a 2D scene.",
  161. Scene = "Demo2DJumpAndRunWithPhysics-Scene"
  162. }
  163. );
  164. _data.Add(
  165. "FriendsAndAuth",
  166. new DemoData()
  167. {
  168. Title = "Friends & Authentication",
  169. Description = "Shows connect with or without (server-side) authentication.\n" +
  170. "\n" +
  171. "Authentication requires minor server-side setup (in Dashboard).\n" +
  172. "\n" +
  173. "Once connected, you can find (made up) friends.\nJoin a room just to see how that gets visible in friends list.",
  174. Scene = "DemoFriends-Scene"
  175. }
  176. );
  177. _data.Add(
  178. "TurnBasedGame",
  179. new DemoData()
  180. {
  181. Title = "'Rock Paper Scissor' Turn Based Game",
  182. Description = "Demonstrate TurnBased Game Mechanics using PUN.\n" +
  183. "\n" +
  184. "It makes use of the TurnBasedManager Utility Script",
  185. Scene = "DemoRPS-Scene"
  186. }
  187. );
  188. _data.Add(
  189. "Asteroids",
  190. new DemoData()
  191. {
  192. Title = "Asteroids",
  193. Description = "Simple asteroid game based on the Unity learning asset.\n",
  194. Scene = "DemoAsteroids-LobbyScene"
  195. }
  196. );
  197. _data.Add(
  198. "SlotRacer",
  199. new DemoData()
  200. {
  201. Title = "Slot Racer",
  202. Description = "Simple SlotRacing game.\n",
  203. Scene = "SlotCar-Scene"
  204. }
  205. );
  206. _data.Add(
  207. "LoadBalancing",
  208. new DemoData()
  209. {
  210. Title = "Load Balancing",
  211. Description = "Shows how to use the raw LoadBalancing system.\n" +
  212. "\n" +
  213. "This is a simple test scene to connect and join a random room, without using PUN but the actual LoadBalancing api only",
  214. Scene = "DemoLoadBalancing-Scene"
  215. }
  216. );
  217. _data.Add(
  218. "PunCockpit",
  219. new DemoData()
  220. {
  221. Title = "Cockpit",
  222. Description = "Controls most aspect of PUN.\n" +
  223. "Connection, Lobby, Room access, Player control",
  224. Scene = "PunCockpit-Scene"
  225. }
  226. );
  227. }
  228. public void SelectDemo(string Reference)
  229. {
  230. currentSelection = Reference;
  231. TitleText.text = _data[currentSelection].Title;
  232. DescriptionText.text = _data[currentSelection].Description;
  233. OpenSceneButton.SetActive(!string.IsNullOrEmpty(_data[currentSelection].Scene));
  234. OpenTutorialLinkButton.SetActive(!string.IsNullOrEmpty(_data[currentSelection].TutorialLink));
  235. OpenDocLinkButton.SetActive(!string.IsNullOrEmpty(_data[currentSelection].DocLink));
  236. }
  237. public void OpenScene()
  238. {
  239. if (string.IsNullOrEmpty(currentSelection))
  240. {
  241. Debug.LogError("Bad setup, a CurrentSelection is expected at this point");
  242. return;
  243. }
  244. SceneManager.LoadScene(_data[currentSelection].Scene);
  245. }
  246. public void OpenTutorialLink()
  247. {
  248. if (string.IsNullOrEmpty(currentSelection))
  249. {
  250. Debug.LogError("Bad setup, a CurrentSelection is expected at this point");
  251. return;
  252. }
  253. Application.OpenURL(_data[currentSelection].TutorialLink);
  254. }
  255. public void OpenDocLink()
  256. {
  257. if (string.IsNullOrEmpty(currentSelection))
  258. {
  259. Debug.LogError("Bad setup, a CurrentSelection is expected at this point");
  260. return;
  261. }
  262. Application.OpenURL(_data[currentSelection].DocLink);
  263. }
  264. public void OpenMainWebLink()
  265. {
  266. Application.OpenURL(MainDemoWebLink);
  267. }
  268. }
  269. }