SHARE
TWEET

APPController

subere23 Oct 15th, 2017 (edited) 395 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using GoogleARCore;
  3. using System.Collections.Generic;
  4.  
  5. public class AppController : MonoBehaviour
  6. {
  7.     private List<TrackedPlane> m_NewPlanes = new List<TrackedPlane>();
  8.     private List<TrackedPlane> m_AllPlanes = new List<TrackedPlane>();
  9.     private bool m_IsQuitting = false;
  10.  
  11.     // Use this for initialization
  12.     void Start()
  13.     {
  14.         QuitOnConnectionErrors();
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.  
  21.         if (Session.Status != SessionStatus.Tracking)
  22.         {
  23.             const int lostTrackingSleepTimeout = 15;
  24.             Screen.sleepTimeout = lostTrackingSleepTimeout;            
  25.  
  26.             return;
  27.         }
  28.         Screen.sleepTimeout = SleepTimeout.NeverSleep;
  29.  
  30.     }
  31.  
  32.  
  33.     private void QuitOnConnectionErrors()
  34.     {
  35.         if (m_IsQuitting)
  36.         {
  37.             return;
  38.         }
  39.  
  40.         // Quit if ARCore was unable to connect and give Unity some time for the toast to appear.
  41.         if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
  42.         {
  43.             ShowAndroidToastMessage("Camera permission is needed to run this application.");
  44.             m_IsQuitting = true;
  45.             Invoke("_DoQuit", 0.5f);
  46.         }
  47.         else if (Session.Status.IsError())
  48.         {
  49.             ShowAndroidToastMessage("ARCore encountered a problem connecting.  Please start the app again.");
  50.             m_IsQuitting = true;
  51.             Invoke("_DoQuit", 0.5f);
  52.         }
  53.  
  54.     }
  55.  
  56.     private static void ShowAndroidToastMessage(string message)
  57.     {
  58.         AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  59.         AndroidJavaObject unityActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
  60.  
  61.         if (unityActivity != null)
  62.         {
  63.             AndroidJavaClass toastClass = new AndroidJavaClass("android.widget.Toast");
  64.             unityActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
  65.             {
  66.                 AndroidJavaObject toastObject = toastClass.CallStatic<AndroidJavaObject>("makeText", unityActivity,
  67.                     message, 0);
  68.                 toastObject.Call("show");
  69.             }));
  70.         }
  71.     }
  72.  
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top