DemoHubManager.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. "BasicTutorial",
  43. new DemoData()
  44. {
  45. Title = "Basic Tutorial",
  46. Description = "All custom code for connection, player and scene management.\n" +
  47. "Auto synchronization of room levels.\n" +
  48. "Uses PhotonAnimatoView for Animator synch.\n" +
  49. "New Unity UI all around, for Menus and player health HUD.\n" +
  50. "Full step by step tutorial available online.",
  51. Scene = "PunBasics-Launcher" ,
  52. TutorialLink = "https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/intro"
  53. }
  54. );
  55. _data.Add(
  56. "Chat",
  57. new DemoData()
  58. {
  59. Title = "Chat",
  60. Description = "Uses the Chat API.\n" +
  61. "Simple UI.\n" +
  62. "You can enter any User ID.\n" +
  63. "Automatically subscribes some channels.\n" +
  64. "Allows simple commands via text.\n" +
  65. "\n" +
  66. "Requires configuration of Chat App ID in ServerSettings.",
  67. Scene = "DemoChat-Scene",
  68. DocLink = "http://j.mp/2iwQkPJ"
  69. }
  70. );
  71. _data.Add(
  72. "Asteroids",
  73. new DemoData()
  74. {
  75. Title = "Asteroids",
  76. Description = "Simple asteroid game based on the Unity learning asset.\n",
  77. Scene = "DemoAsteroids-LobbyScene",
  78. TutorialLink = "https://doc.photonengine.com/pun/current/demos-and-tutorials/package-demos/asteroidsdemo"
  79. }
  80. );
  81. _data.Add(
  82. "SlotRacer",
  83. new DemoData()
  84. {
  85. Title = "Slot Racer",
  86. Description = "Simple SlotRacing game.\n",
  87. Scene = "SlotCar-Scene"
  88. }
  89. );
  90. _data.Add(
  91. "Procedural",
  92. new DemoData()
  93. {
  94. Title = "Procedural World",
  95. Description = "Shows how to synchronize the seed of a procedural world with deterministic generation.\n" +
  96. "Simple modifications to the world are possible." +
  97. "\n" +
  98. "This is a simple test scene to connect and join a random room, without using PUN but the actual LoadBalancing api only",
  99. Scene = "Procedural-Scene",
  100. TutorialLink = "https://doc.photonengine.com/pun/current/demos-and-tutorials/package-demos/proceduraldemo"
  101. }
  102. );
  103. _data.Add(
  104. "PunCockpit",
  105. new DemoData()
  106. {
  107. Title = "Cockpit",
  108. Description = "Controls most aspect of PUN.\n" +
  109. "Connection, Lobby, Room access, Player control",
  110. Scene = "PunCockpit-Scene"
  111. }
  112. );
  113. }
  114. public void SelectDemo(string Reference)
  115. {
  116. currentSelection = Reference;
  117. TitleText.text = _data[currentSelection].Title;
  118. DescriptionText.text = _data[currentSelection].Description;
  119. OpenSceneButton.SetActive(!string.IsNullOrEmpty(_data[currentSelection].Scene));
  120. OpenTutorialLinkButton.SetActive(!string.IsNullOrEmpty(_data[currentSelection].TutorialLink));
  121. OpenDocLinkButton.SetActive(!string.IsNullOrEmpty(_data[currentSelection].DocLink));
  122. }
  123. public void OpenScene()
  124. {
  125. if (string.IsNullOrEmpty(currentSelection))
  126. {
  127. Debug.LogError("Bad setup, a CurrentSelection is expected at this point");
  128. return;
  129. }
  130. SceneManager.LoadScene(_data[currentSelection].Scene);
  131. }
  132. public void OpenTutorialLink()
  133. {
  134. if (string.IsNullOrEmpty(currentSelection))
  135. {
  136. Debug.LogError("Bad setup, a CurrentSelection is expected at this point");
  137. return;
  138. }
  139. Application.OpenURL(_data[currentSelection].TutorialLink);
  140. }
  141. public void OpenDocLink()
  142. {
  143. if (string.IsNullOrEmpty(currentSelection))
  144. {
  145. Debug.LogError("Bad setup, a CurrentSelection is expected at this point");
  146. return;
  147. }
  148. Application.OpenURL(_data[currentSelection].DocLink);
  149. }
  150. public void OpenMainWebLink()
  151. {
  152. Application.OpenURL(MainDemoWebLink);
  153. }
  154. }
  155. }