Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.24 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using UnityEngine.XR;
  7.  
  8.  
  9. namespace Arul_script
  10. {
  11.  
  12.  
  13.  
  14.  
  15. public class App_Root : MonoBehaviour
  16. {
  17. public static App_Root Instance { private set; get; }
  18.  
  19. public bool Is_GVR;
  20. public GameObject Server_Pan, Client_Pan;
  21. public string Device_Name;
  22.  
  23. // Server UI Globals
  24. public InputField Server_Portaddress;
  25. public Text Server_Ipaddress,Connected_Device_Count_text;
  26. public GameObject ClientParent_GO, Client_Ins_Prefab_GO;
  27.  
  28. public bool issuccessfullyloaded_firstiem;
  29.  
  30. // Client UI Globals
  31. public InputField Client_Ipaddress, Client_Portaddress, Client_Name;
  32. public Text Debug_Text;
  33. public GameObject VR_buffer_GO, Server_buffer_GO;
  34. public bool Is_Cardboard, Is_Oculas;
  35.  
  36. public bool Pref_Data_present;
  37.  
  38. public string IP_address;
  39.  
  40. // Use this for initialization
  41. void Start()
  42. {
  43. issuccessfullyloaded_firstiem = false;
  44.  
  45. Pref_Data_present = false;
  46. Instance = this;
  47.  
  48. CheckPrefdata();
  49.  
  50. //Startup();
  51.  
  52. if (Is_GVR)
  53. {
  54. //DESCOMENTAR APÓS TESTES
  55. StartCoroutine(LoadDevice("cardboard"));
  56. Hide_All_Pan();
  57. StartAsClient();
  58.  
  59. }
  60. else
  61. {
  62. Hide_All_Pan();
  63. StartAsServer();
  64. }
  65.  
  66.  
  67. }
  68.  
  69. public void App_Close()
  70. {
  71. Application.Quit();
  72. }
  73.  
  74.  
  75. public void CheckPrefdata()
  76. {
  77.  
  78.  
  79. if (PlayerPrefs.HasKey("PlayerName"))
  80. {
  81. Client_Name.text = PlayerPrefs.GetString("PlayerName");
  82. Debug.Log("Pref has PlayerName : " + Client_Name.text);
  83.  
  84. }
  85.  
  86.  
  87. if (PlayerPrefs.HasKey("PortAddress"))
  88. {
  89. Client_Portaddress.text = PlayerPrefs.GetString("PortAddress");
  90. Debug.Log("Pref has PortAddress : " + Client_Portaddress.text);
  91.  
  92. }
  93.  
  94.  
  95. if (PlayerPrefs.HasKey("IPAddress"))
  96. {
  97. Client_Ipaddress.text = PlayerPrefs.GetString("IPAddress");
  98. Debug.Log("Pref has IPAddress : " + Client_Ipaddress.text);
  99. IP_address = PlayerPrefs.GetString("IPAddress");
  100. Pref_Data_present = true;
  101. }
  102. else
  103. {
  104. Pref_Data_present = false;
  105. Debug.Log("Pref data not present");
  106. Debug.Log("Pref_Data_present :" + Pref_Data_present);
  107. }
  108.  
  109.  
  110.  
  111. }
  112.  
  113. public void Startup()
  114. {
  115. VR_buffer_GO.SetActive(false);
  116. Server_buffer_GO.SetActive(false);
  117. Server_Pan.SetActive(false);
  118. Client_Pan.SetActive(false);
  119.  
  120. }
  121.  
  122. public void Hide_All_Pan()
  123. {
  124.  
  125. VR_buffer_GO.SetActive(false);
  126. Server_buffer_GO.SetActive(false);
  127. Server_Pan.SetActive(false);
  128. Client_Pan.SetActive(false);
  129.  
  130. }
  131.  
  132.  
  133. /// <summary>
  134. /// SErver Code Here
  135. /// </summary>
  136.  
  137.  
  138. public void StartAsServer()
  139. {
  140. Hide_All_Pan();
  141. Server_buffer_GO.SetActive(true);
  142. Network_Manager_UI.Instance.Start_Host();
  143. Device_Name = "Server";
  144. }
  145.  
  146. public void CleaR_aLL_Nodes()
  147. {
  148. foreach (Transform T in ClientParent_GO.transform)
  149. Destroy(T.gameObject);
  150. }
  151.  
  152. public GameObject CreateListNode(string con_idd, string ipaddresssX, string Player_nameX)
  153. {
  154.  
  155. GameObject tempg = Instantiate(Client_Ins_Prefab_GO, ClientParent_GO.transform);
  156.  
  157. tempg.GetComponent<Client_Node_Manger>().setInstanceValues(con_idd, ipaddresssX, Player_nameX);
  158.  
  159. return tempg;
  160. }
  161.  
  162.  
  163. public void Start_Show() {
  164. NETWORK_CALLS.Instance.RpcStartShow();
  165. }
  166.  
  167.  
  168. public void Play_Video() {
  169. NETWORK_CALLS.Instance.RpcPlay();
  170. }
  171. public void Pause_Video() {
  172. NETWORK_CALLS.Instance.RpcPause();
  173. }
  174.  
  175.  
  176. public void seek_time(Slider seekslider) {
  177. NETWORK_CALLS.Instance.RpcSeek(seekslider.value);
  178. }
  179.  
  180. public void Replay()
  181. {
  182. NETWORK_CALLS.Instance.RpcSeek(0);
  183. }
  184.  
  185. public void Reboot() {
  186. Animation_Manager.Instance.IsVideoPlaying = false;
  187. NETWORK_CALLS.Instance.Rpcreboot();
  188. }
  189.  
  190. public void Langenglish() { NETWORK_CALLS.Instance.RpcLangenglish(); }
  191. public void Langportugees() { NETWORK_CALLS.Instance.RpcLangportugees(); }
  192. public void Langmute() { NETWORK_CALLS.Instance.RpcLangmute(); }
  193. public void Langsign() { NETWORK_CALLS.Instance.RpcLangsign(); }
  194.  
  195.  
  196.  
  197. /// <summary>
  198. /// Client Code Here
  199. /// </summary>
  200.  
  201.  
  202. public void StartAsClient()
  203. {
  204. Debug.Log("StartAsClient");
  205.  
  206. if (!Pref_Data_present)
  207. {
  208. GetIpAddress();
  209. }
  210. else
  211. {
  212. VR_buffer_GO.SetActive(true);
  213. Debug.Log("IP_address"+ IP_address);
  214. if (IP_address == "")
  215. IP_address = "192.168.0.0";
  216. Network_Manager_UI.Instance.Client_Connect(IP_address, 7777);
  217. }
  218. }
  219.  
  220.  
  221. public void GetIpAddress()
  222. {
  223. // COMENTAR PARA HABILITAR MODO GEAR VR
  224. StartCoroutine(LoadDevice("None"));
  225. //COMENTAR PARA HABILITAR MODO GEAR VR
  226.  
  227. Debug.Log("GetIpAddress");
  228. Hide_All_Pan();
  229. Client_Pan.SetActive(true);
  230.  
  231. // for temp code
  232. }
  233.  
  234. public void Update_IP_port_and_connect()
  235. {
  236. Debug.Log("Update_IP_port_and_connect");
  237.  
  238. // Observacao:ativar abaixo para mudar canvas do client
  239.  
  240. PlayerPrefs.SetString("PlayerName", Client_Name.text);
  241. App_Root.Instance.Device_Name = Client_Name.text;
  242. PlayerPrefs.SetString("PortAddress", Client_Portaddress.text);
  243. PlayerPrefs.SetString("IPAddress", Client_Ipaddress.text);
  244. PlayerPrefs.Save();
  245.  
  246. VR_buffer_GO.SetActive(true);
  247. Network_Manager_UI.Instance.Client_Connect(Client_Ipaddress.text, Convert.ToInt32(Client_Portaddress.text));
  248.  
  249.  
  250.  
  251.  
  252. // for gearvr input
  253.  
  254. /*
  255.  
  256. PlayerPrefs.SetString("PlayerName", Client_Name.text);
  257. App_Root.Instance.Device_Name = Client_Name.text;
  258. PlayerPrefs.SetString("PortAddress", Client_Portaddress.text);
  259. PlayerPrefs.SetString("IPAddress", Client_Ipaddress.text);
  260. PlayerPrefs.Save();
  261.  
  262. VR_buffer_GO.SetActive(true);
  263. Network_Manager_UI.Instance.Client_Connect(IP_address, 7777); */
  264.  
  265. }
  266.  
  267.  
  268.  
  269.  
  270. // ON Client Connect
  271. public void Onclient_Connect_GVR_Server()
  272. {
  273. Hide_All_Pan();
  274.  
  275. issuccessfullyloaded_firstiem = true;
  276. //COMENTAR PARA HABILITAR MODO GEAR VR
  277. //switching VR mode
  278. //Debug.Log("XRSettings.loadedDeviceName :"+ XRSettings.loadedDeviceName);
  279.  
  280. XRSettings.LoadDeviceByName("cardboard");
  281.  
  282.  
  283.  
  284. //else if(Is_Oculas)
  285. //StartCoroutine(LoadDevice("Oculus"));
  286.  
  287. StartCoroutine(LoadDevice("cardboard"));
  288. //COMENTAR PARA HABILITAR MODO GEAR VR
  289. }
  290.  
  291.  
  292. public void ConnectServerSilent() {
  293. Network_Manager_UI.Instance.Client_Connect(IP_address, 7777);
  294. }
  295.  
  296.  
  297. IEnumerator LoadDevice(string newDevice)
  298. {
  299. Debug.Log("LoadDevice :" + newDevice);
  300. XRSettings.LoadDeviceByName(newDevice);
  301. yield return null;
  302. XRSettings.enabled = true;
  303. }
  304.  
  305.  
  306.  
  307. }
  308.  
  309. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement