Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using UnityEngine.XR;
- namespace Arul_script
- {
- public class App_Root : MonoBehaviour
- {
- public static App_Root Instance { private set; get; }
- public bool Is_GVR;
- public GameObject Server_Pan, Client_Pan;
- public string Device_Name;
- // Server UI Globals
- public InputField Server_Portaddress;
- public Text Server_Ipaddress,Connected_Device_Count_text;
- public GameObject ClientParent_GO, Client_Ins_Prefab_GO;
- public bool issuccessfullyloaded_firstiem;
- // Client UI Globals
- public InputField Client_Ipaddress, Client_Portaddress, Client_Name;
- public Text Debug_Text;
- public GameObject VR_buffer_GO, Server_buffer_GO;
- public bool Is_Cardboard, Is_Oculas;
- public bool Pref_Data_present;
- public string IP_address;
- // Use this for initialization
- void Start()
- {
- issuccessfullyloaded_firstiem = false;
- Pref_Data_present = false;
- Instance = this;
- CheckPrefdata();
- //Startup();
- if (Is_GVR)
- {
- //DESCOMENTAR APÓS TESTES
- StartCoroutine(LoadDevice("cardboard"));
- Hide_All_Pan();
- StartAsClient();
- }
- else
- {
- Hide_All_Pan();
- StartAsServer();
- }
- }
- public void App_Close()
- {
- Application.Quit();
- }
- public void CheckPrefdata()
- {
- if (PlayerPrefs.HasKey("PlayerName"))
- {
- Client_Name.text = PlayerPrefs.GetString("PlayerName");
- Debug.Log("Pref has PlayerName : " + Client_Name.text);
- }
- if (PlayerPrefs.HasKey("PortAddress"))
- {
- Client_Portaddress.text = PlayerPrefs.GetString("PortAddress");
- Debug.Log("Pref has PortAddress : " + Client_Portaddress.text);
- }
- if (PlayerPrefs.HasKey("IPAddress"))
- {
- Client_Ipaddress.text = PlayerPrefs.GetString("IPAddress");
- Debug.Log("Pref has IPAddress : " + Client_Ipaddress.text);
- IP_address = PlayerPrefs.GetString("IPAddress");
- Pref_Data_present = true;
- }
- else
- {
- Pref_Data_present = false;
- Debug.Log("Pref data not present");
- Debug.Log("Pref_Data_present :" + Pref_Data_present);
- }
- }
- public void Startup()
- {
- VR_buffer_GO.SetActive(false);
- Server_buffer_GO.SetActive(false);
- Server_Pan.SetActive(false);
- Client_Pan.SetActive(false);
- }
- public void Hide_All_Pan()
- {
- VR_buffer_GO.SetActive(false);
- Server_buffer_GO.SetActive(false);
- Server_Pan.SetActive(false);
- Client_Pan.SetActive(false);
- }
- /// <summary>
- /// SErver Code Here
- /// </summary>
- public void StartAsServer()
- {
- Hide_All_Pan();
- Server_buffer_GO.SetActive(true);
- Network_Manager_UI.Instance.Start_Host();
- Device_Name = "Server";
- }
- public void CleaR_aLL_Nodes()
- {
- foreach (Transform T in ClientParent_GO.transform)
- Destroy(T.gameObject);
- }
- public GameObject CreateListNode(string con_idd, string ipaddresssX, string Player_nameX)
- {
- GameObject tempg = Instantiate(Client_Ins_Prefab_GO, ClientParent_GO.transform);
- tempg.GetComponent<Client_Node_Manger>().setInstanceValues(con_idd, ipaddresssX, Player_nameX);
- return tempg;
- }
- public void Start_Show() {
- NETWORK_CALLS.Instance.RpcStartShow();
- }
- public void Play_Video() {
- NETWORK_CALLS.Instance.RpcPlay();
- }
- public void Pause_Video() {
- NETWORK_CALLS.Instance.RpcPause();
- }
- public void seek_time(Slider seekslider) {
- NETWORK_CALLS.Instance.RpcSeek(seekslider.value);
- }
- public void Replay()
- {
- NETWORK_CALLS.Instance.RpcSeek(0);
- }
- public void Reboot() {
- Animation_Manager.Instance.IsVideoPlaying = false;
- NETWORK_CALLS.Instance.Rpcreboot();
- }
- public void Langenglish() { NETWORK_CALLS.Instance.RpcLangenglish(); }
- public void Langportugees() { NETWORK_CALLS.Instance.RpcLangportugees(); }
- public void Langmute() { NETWORK_CALLS.Instance.RpcLangmute(); }
- public void Langsign() { NETWORK_CALLS.Instance.RpcLangsign(); }
- /// <summary>
- /// Client Code Here
- /// </summary>
- public void StartAsClient()
- {
- Debug.Log("StartAsClient");
- if (!Pref_Data_present)
- {
- GetIpAddress();
- }
- else
- {
- VR_buffer_GO.SetActive(true);
- Debug.Log("IP_address"+ IP_address);
- if (IP_address == "")
- IP_address = "192.168.0.0";
- Network_Manager_UI.Instance.Client_Connect(IP_address, 7777);
- }
- }
- public void GetIpAddress()
- {
- // COMENTAR PARA HABILITAR MODO GEAR VR
- StartCoroutine(LoadDevice("None"));
- //COMENTAR PARA HABILITAR MODO GEAR VR
- Debug.Log("GetIpAddress");
- Hide_All_Pan();
- Client_Pan.SetActive(true);
- // for temp code
- }
- public void Update_IP_port_and_connect()
- {
- Debug.Log("Update_IP_port_and_connect");
- // Observacao:ativar abaixo para mudar canvas do client
- PlayerPrefs.SetString("PlayerName", Client_Name.text);
- App_Root.Instance.Device_Name = Client_Name.text;
- PlayerPrefs.SetString("PortAddress", Client_Portaddress.text);
- PlayerPrefs.SetString("IPAddress", Client_Ipaddress.text);
- PlayerPrefs.Save();
- VR_buffer_GO.SetActive(true);
- Network_Manager_UI.Instance.Client_Connect(Client_Ipaddress.text, Convert.ToInt32(Client_Portaddress.text));
- // for gearvr input
- /*
- PlayerPrefs.SetString("PlayerName", Client_Name.text);
- App_Root.Instance.Device_Name = Client_Name.text;
- PlayerPrefs.SetString("PortAddress", Client_Portaddress.text);
- PlayerPrefs.SetString("IPAddress", Client_Ipaddress.text);
- PlayerPrefs.Save();
- VR_buffer_GO.SetActive(true);
- Network_Manager_UI.Instance.Client_Connect(IP_address, 7777); */
- }
- // ON Client Connect
- public void Onclient_Connect_GVR_Server()
- {
- Hide_All_Pan();
- issuccessfullyloaded_firstiem = true;
- //COMENTAR PARA HABILITAR MODO GEAR VR
- //switching VR mode
- //Debug.Log("XRSettings.loadedDeviceName :"+ XRSettings.loadedDeviceName);
- XRSettings.LoadDeviceByName("cardboard");
- //else if(Is_Oculas)
- //StartCoroutine(LoadDevice("Oculus"));
- StartCoroutine(LoadDevice("cardboard"));
- //COMENTAR PARA HABILITAR MODO GEAR VR
- }
- public void ConnectServerSilent() {
- Network_Manager_UI.Instance.Client_Connect(IP_address, 7777);
- }
- IEnumerator LoadDevice(string newDevice)
- {
- Debug.Log("LoadDevice :" + newDevice);
- XRSettings.LoadDeviceByName(newDevice);
- yield return null;
- XRSettings.enabled = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement