// Update is called once per frame
        //private void Update()
        //{

        //}


        //Check for permission (using local value)
        public void CheckPermission()
        {
            if (string.IsNullOrEmpty(permission))
            {
                return;
            }

#if UNITY_EDITOR
            Debug.Log("PermissionCheckController.CheckPermission called.");
#elif UNITY_ANDROID
            bool granted = AndroidPlugin.CheckPermission(permission);
            if (OnResult != null)
            {
                OnResult.Invoke(permission, granted);
            }

            if (granted)
            {
                if (OnGranted != null)
                {
                    OnGranted.Invoke();
                }
            }
            else
            {
                if (OnDenied != null)
                {
                    OnDenied.Invoke();
                }
            }
#endif
        }
    bool isSaving     = false;          //Ignore while saving.

    //Run screenshot
    public void ScreenShot()
    {
        if (isSaving)
        {
            return;     //Ignore while saving.
        }
        string fileName = filePrefix + DateTime.Now.ToString("yyMMdd_HHmmss") + ".png";
        string dir      = Application.persistentDataPath;

#if UNITY_EDITOR
        dir = Application.dataPath + "/..";
#elif UNITY_ANDROID
        if (!AndroidPlugin.CheckPermission("android.permission.WRITE_EXTERNAL_STORAGE"))
        {
            XDebug.Log("'WRITE_EXTERNAL_STORAGE' permission denied.");
            return;
        }

        dir = AndroidPlugin.GetExternalStorageDirectoryPictures();
        if (string.IsNullOrEmpty(dir))
        {
            dir = AndroidPlugin.GetExternalStorageDirectory();
        }
#endif

        string path = dir + "/" + fileName;
        StartCoroutine(StartScreenshot(path));
    }
    //Image loading and setting.    //画像の読み込みとセット
    private void LoadAndSetImage(string path, int width, int height)
    {
        Texture2D texture = LoadToTexture2D(path, width, height, TextureFormat.ARGB32, false, FilterMode.Bilinear);

        if (texture != null)
        {
            RectTransform rt = image.rectTransform;
            int           h  = (int)rt.sizeDelta.y;
            int           w  = width * h / height;
            rt.sizeDelta = new Vector2(w, h);   //Make the same ratio as the image with the height as the reference.  //縦を基準として画像と同じ比率にする

            try
            {
                Sprite sprite = Sprite.Create(texture, new Rect(0, 0, width, height), new Vector2(0.5f, 0.5f));
                image.sprite           = sprite;
                textureMat.mainTexture = texture;
            }
            catch (Exception)
            {
                XDebug.Log("Sprite.Create failed.");
            }
        }
        else
        {
            XDebug.Log("CreateTexture2D failed.");
#if !UNITY_EDITOR && UNITY_ANDROID
            XDebug.Log("'READ_EXTERNAL_STORAGE' permission = " + AndroidPlugin.CheckPermission("android.permission.READ_EXTERNAL_STORAGE"));
#endif
        }
    }
Пример #4
0
        // Update is called once per frame
        //private void Update()
        //{

        //}


        //Run screenshot with automatic path
        public void StartScreenshot()
        {
            string fileName = filePrefix + DateTime.Now.ToString("yyMMdd_HHmmss") + ".png";
            string dir      = Application.persistentDataPath;

            //I think that you may add processing for each platform here.
#if UNITY_EDITOR
            dir = Application.dataPath + "/..";
#elif UNITY_ANDROID
            if (toExternalStorageOnAndroid)
            {
                if (!AndroidPlugin.CheckPermission("android.permission.WRITE_EXTERNAL_STORAGE"))
                {
                    if (OnError != null)
                    {
                        OnError.Invoke("'WRITE_EXTERNAL_STORAGE' permission denied.");
                    }
                    return;
                }

                dir = AndroidPlugin.GetExternalStorageDirectoryPictures();
                if (string.IsNullOrEmpty(dir))
                {
                    dir = AndroidPlugin.GetExternalStorageDirectory();
                }
            }
#endif
            string path = dir + "/" + fileName;
            StartScreenshot(path);
        }
Пример #5
0
    //Needs check for IsSupportedSensor when display initialized
    private void InitDisplayNeedIsSupport()
    {
#if !UNITY_EDITOR && UNITY_ANDROID
        if (displaySignificantMotion != null)
        {
            displaySignificantMotion.text = "SignificantMotion : " + (AndroidPlugin.IsSupportedSensor(SensorType.SignificantMotion) ? "(supported)" : "(not supported)");
        }
        if (displayStepDetector != null)
        {
            displayStepDetector.text = "StepDetector : " + (AndroidPlugin.IsSupportedSensor(SensorType.StepDetector) ? "(supported)" : "(not supported)");
        }
        if (displayHeartRate != null)
        {
            if (!AndroidPlugin.CheckPermission("android.permission.BODY_SENSORS"))
            {
                displayHeartRate.text = "HeartRate : (permission denied)";
            }
            else
            {
                displayHeartRate.text = "HeartRate : " + (AndroidPlugin.IsSupportedSensor(SensorType.HeartRate) ? "(supported)" : "(not supported)");
            }
        }
        if (displayStationaryDetect != null)
        {
            displayStationaryDetect.text = "StationaryDetect : " + (AndroidPlugin.IsSupportedSensor(SensorType.StationaryDetect) ? "(supported)" : "(not supported)");
        }
        if (displayMotionDetect != null)
        {
            displayMotionDetect.text = "MotionDetect : " + (AndroidPlugin.IsSupportedSensor(SensorType.MotionDetect) ? "(supported)" : "(not supported)");
        }
        if (displayHeartBeat != null)
        {
            displayHeartBeat.text = "HeartBeat : " + (AndroidPlugin.IsSupportedSensor(SensorType.HeartBeat) ? "(supported)" : "(not supported)");
        }
        if (displayLowLatencyOffbodyDetect != null)
        {
            displayLowLatencyOffbodyDetect.text = "LowLatencyOffbodyDetect : " + (AndroidPlugin.IsSupportedSensor(SensorType.LowLatencyOffbodyDetect) ? "(supported)" : "(not supported)");
        }

        if (displayTest != null && testSensorTypeInt > 0)
        {
            displayTest.text = testSensorTypeInt + " : " + (AndroidPlugin.IsSupportedSensor(testSensorTypeInt) ? "(supported)" : "(not supported)");
        }
#endif
        //Unity built-in
        if (displayInputGyro != null)
        {
            Input.gyro.enabled = true;
        }

        if (displayInputCompass != null)
        {
            Input.compass.enabled = true;
        }
    }
Пример #6
0
    // Update is called once per frame
    //private void Update () {

    //}


    //Check for permissions are granted.    //パーミッションのチェック
    public void CheckPermissions()
    {
#if !UNITY_EDITOR && UNITY_ANDROID
        XDebug.Log("RECORD_AUDIO : " + (AndroidPlugin.CheckPermission("android.permission.RECORD_AUDIO") ? "Granted":"Denied"));
        XDebug.Log("WRITE_EXTERNAL_STORAGE : " + (AndroidPlugin.CheckPermission("android.permission.WRITE_EXTERNAL_STORAGE") ? "Granted":"Denied"));
        XDebug.Log("READ_EXTERNAL_STORAGE : " + (AndroidPlugin.CheckPermission("android.permission.READ_EXTERNAL_STORAGE") ? "Granted":"Denied"));  //If 'WRITE_EXTERNAL_STORAGE' is present, it gets granted.  //'WRITE_EXTERNAL_STORAGE' があれば、granted になる
        XDebug.Log("BLUETOOTH : " + (AndroidPlugin.CheckPermission("android.permission.BLUETOOTH") ? "Granted":"Denied"));
        XDebug.Log("VIBRATE : " + (AndroidPlugin.CheckPermission("android.permission.VIBRATE") ? "Granted":"Denied"));
        XDebug.Log("BODY_SENSORS : " + (AndroidPlugin.CheckPermission("android.permission.BODY_SENSORS") ? "Granted":"Denied"));
#endif
    }
    // Use this for initialization
    private void Start()
    {
        if (cube != null)
        {
            cube.SetActive(false);
        }
        if (sphere != null)
        {
            sphere.SetActive(false);
        }
        if (chara != null)
        {
            chara.SetActive(false);
        }
#if !UNITY_EDITOR && UNITY_ANDROID
        XDebug.Log("'WRITE_EXTERNAL_STORAGE' permission = " + AndroidPlugin.CheckPermission("android.permission.WRITE_EXTERNAL_STORAGE"));
#endif
    }
Пример #8
0
    private int defaultHeight = 384;    //Reference value of height, substitute value when acquisition fails (It will be initialized with UI size).    //高の基準値、または取得に失敗したときの代替値(UIのサイズで初期化されます)


    //==========================================================

    // Use this for initialization
    private void Start()
    {
        if (image != null)
        {
            Vector2 size = image.rectTransform.sizeDelta;
            defaultWidth  = (int)size.x;
            defaultHeight = (int)size.y;
        }

        ToggleImageObject(true);
        ToggleCubeObject(false);
        ToggleSphereObject(false);
        SetEnableShareButtons(false);
        SetEnableVideoButtons(false);

#if !UNITY_EDITOR && UNITY_ANDROID
        XDebug.Log("'WRITE_EXTERNAL_STORAGE' permission = " + AndroidPlugin.CheckPermission("android.permission.WRITE_EXTERNAL_STORAGE"));
#endif
    }
Пример #9
0
    //Image loading and setting.    //画像の読み込みとセット
    private void LoadAndSetImage(string path, int width, int height, int orientation)
    {
        Texture2D texture = LoadToTexture2D(path, width, height, TextureFormat.ARGB32, false, FilterMode.Bilinear);

        if (texture != null && image != null)
        {
            RectTransform rt = image.rectTransform;
            orientation = (int)Mathf.Repeat(orientation, 360);

            int w, h;
            if (orientation == 90 || orientation == 270)
            {
                w = defaultWidth;
                h = height * w / width;
            }
            else
            {
                h = defaultHeight;
                w = width * h / height;
            }

            rt.sizeDelta     = new Vector2(w, h); //Make it the same ratio as the image.  //画像と同じ比率にする
            rt.localRotation = Quaternion.Euler(0, 0, -orientation);

            try
            {
                Sprite sprite = Sprite.Create(texture, new Rect(0, 0, width, height), new Vector2(0.5f, 0.5f));
                image.sprite           = sprite;
                textureMat.mainTexture = texture;
            }
            catch (Exception)
            {
                XDebug.Log("Sprite.Create failed.");
            }
        }
        else
        {
            XDebug.Log("CreateTexture2D failed.");
#if !UNITY_EDITOR && UNITY_ANDROID
            XDebug.Log("'READ_EXTERNAL_STORAGE' permission = " + AndroidPlugin.CheckPermission("android.permission.READ_EXTERNAL_STORAGE"));
#endif
        }
    }
Пример #10
0
        //Check for permission (using local value)
        public void CheckPermission()
        {
            if (string.IsNullOrEmpty(permission))
            {
                return;
            }

#if UNITY_EDITOR
            Debug.Log("PermissionCheckController.CheckPermission called.");
#elif UNITY_ANDROID
            bool granted = oldGranted = AndroidPlugin.CheckPermission(permission);

            if (!granted && requestWhenNotGranted)
            {
                AndroidPlugin.CheckPermissionAndRequest(permission, title, message, gameObject.name, "ReceiveResultPermission", style);
            }
            else
            {
                if (OnResult != null)
                {
                    OnResult.Invoke(permission, granted);
                }

                if (granted)
                {
                    if (OnGranted != null)
                    {
                        OnGranted.Invoke();
                    }
                }
                else
                {
                    if (OnDenied != null)
                    {
                        OnDenied.Invoke();
                    }
                }
            }
#endif
        }