Last active
February 23, 2021 08:38
-
-
Save mu-777/0509fb8f51e0655af4cd3eca26afc14e to your computer and use it in GitHub Desktop.
Realsense In Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
#if PLATFORM_ANDROID | |
using UnityEngine.Android; | |
#endif | |
public class DeviceConnect : MonoBehaviour | |
{ | |
private static AndroidJavaObject _deviceConnect; | |
private bool _isRequesting = false; | |
#if PLATFORM_ANDROID | |
IEnumerator Start() | |
{ | |
if (!Permission.HasUserAuthorizedPermission(Permission.Camera)) | |
{ | |
yield return RequestUserPermission(Permission.Camera); | |
} | |
if (Permission.HasUserAuthorizedPermission(Permission.Camera)) | |
{ | |
Debug.Log("granted"); | |
_deviceConnect = new AndroidJavaObject("com.intel.realsense.librealsense.DeviceConnect"); | |
} | |
else | |
{ | |
Debug.Log("not granted"); | |
} | |
} | |
IEnumerator OnApplicationFocus(bool hasFocus) | |
{ | |
yield return null; | |
if (_isRequesting && hasFocus) | |
{ | |
_isRequesting = false; | |
} | |
} | |
IEnumerator RequestUserPermission(string permission) | |
{ | |
_isRequesting = true; | |
Permission.RequestUserPermission(permission); | |
float timeElapsed = 0; | |
while (_isRequesting) | |
{ | |
if (timeElapsed > 0.5f) | |
{ | |
_isRequesting = false; | |
yield break; | |
} | |
timeElapsed += Time.deltaTime; | |
yield return null; | |
} | |
yield break; | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment