123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using UnityEngine;
- #if(UNITY_2018_3_OR_NEWER && UNITY_ANDROID)
- using UnityEngine.Android;
- #endif
- using System.Collections;
- /// <summary>
- /// TestHome serves a game controller object for this application.
- /// </summary>
- public class TestHome : MonoBehaviour
- {
- // Use this for initialization
- #if (UNITY_2018_3_OR_NEWER && UNITY_ANDROID)
- private ArrayList permissionList = new ArrayList();
- #endif
- static TestHelloUnityVideo app = null;
- private string HomeSceneName = "SceneHome";
- private string PlaySceneName = "SceneHelloVideo";
- // PLEASE KEEP THIS App ID IN SAFE PLACE
- // Get your own App ID at https://dashboard.agora.io/
- [SerializeField]
- private string AppID = "your_appid";
- void Awake()
- {
- #if (UNITY_2018_3_OR_NEWER && UNITY_ANDROID)
- permissionList.Add(Permission.Microphone);
- permissionList.Add(Permission.Camera);
- #endif
- // keep this alive across scenes
- DontDestroyOnLoad(this.gameObject);
- }
- void Start()
- {
- CheckAppId();
- }
- void Update()
- {
- CheckPermissions();
- }
- private void CheckAppId()
- {
- Debug.Assert(AppID.Length > 10, "Please fill in your AppId first on Game Controller object.");
- GameObject go = GameObject.Find("AppIDText");
- if (go != null)
- {
- Text appIDText = go.GetComponent<Text>();
- if (appIDText != null)
- {
- if (string.IsNullOrEmpty(AppID))
- {
- appIDText.text = "AppID: " + "UNDEFINED!";
- }
- else
- {
- appIDText.text = "AppID: " + AppID.Substring(0, 4) + "********" + AppID.Substring(AppID.Length - 4, 4);
- }
- }
- }
- }
- /// <summary>
- /// Checks for platform dependent permissions.
- /// </summary>
- private void CheckPermissions()
- {
- #if (UNITY_2018_3_OR_NEWER && UNITY_ANDROID)
- foreach(string permission in permissionList)
- {
- if (!Permission.HasUserAuthorizedPermission(permission))
- {
- Permission.RequestUserPermission(permission);
- }
- }
- #endif
- }
- public void onJoinButtonClicked()
- {
- // get parameters (channel name, channel profile, etc.)
- GameObject go = GameObject.Find("ChannelName");
- InputField field = go.GetComponent<InputField>();
- // create app if nonexistent
- if (ReferenceEquals(app, null))
- {
- app = new TestHelloUnityVideo(); // create app
- app.loadEngine(AppID); // load engine
- }
- // join channel and jump to next scene
- app.join(field.text);
- SceneManager.sceneLoaded += OnLevelFinishedLoading; // configure GameObject after scene is loaded
- SceneManager.LoadScene(PlaySceneName, LoadSceneMode.Single);
- }
- public void onLeaveButtonClicked()
- {
- if (!ReferenceEquals(app, null))
- {
- app.leave(); // leave channel
- app.unloadEngine(); // delete engine
- app = null; // delete app
- SceneManager.LoadScene(HomeSceneName, LoadSceneMode.Single);
- }
- Destroy(gameObject);
- }
- public void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
- {
- if (scene.name == PlaySceneName)
- {
- if (!ReferenceEquals(app, null))
- {
- app.onSceneHelloVideoLoaded(); // call this after scene is loaded
- }
- SceneManager.sceneLoaded -= OnLevelFinishedLoading;
- }
- }
- void OnApplicationPause(bool paused)
- {
- if (!ReferenceEquals(app, null))
- {
- app.EnableVideo(paused);
- }
- }
- void OnApplicationQuit()
- {
- if (!ReferenceEquals(app, null))
- {
- app.unloadEngine();
- }
- }
- }
|