Esempio n. 1
0
    private static Permission GetMediaFromGallery(MediaPickCallback callback, MediaType mediaType, string mime, string title)
    {
        Permission result = RequestPermission(PermissionType.Read);

        if (result == Permission.Granted && !IsMediaPickerBusy())
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            AJC.CallStatic("PickMedia", Context, new NGMediaReceiveCallbackAndroid(callback, null), (int)mediaType, false, SelectedMediaPath, mime, title);
#elif !UNITY_EDITOR && UNITY_IOS
            if (mediaType == MediaType.Audio)
            {
                Debug.LogError("Picking audio files is not supported on iOS");

                if (callback != null)                  // Selecting audio files is not supported on iOS
                {
                    callback(null);
                }
            }
            else
            {
                NGMediaReceiveCallbackiOS.Initialize(callback, null);
                _NativeGallery_PickMedia(SelectedMediaPath, (int)(mediaType & ~MediaType.Audio), PermissionFreeMode ? 1 : 0, 1);
            }
#else
            if (callback != null)
            {
                callback(null);
            }
#endif
        }

        return(result);
    }
Esempio n. 2
0
    private static Permission GetMediaFromGallery(MediaPickCallback callback, bool imageMode, string mime, string title, int maxSize)
    {
        Permission result = RequestPermission(true);

        if (result == Permission.Granted && !IsMediaPickerBusy())
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            AJC.CallStatic("PickMedia", Context, new NGMediaReceiveCallbackAndroid(callback, null), imageMode, false, mime, title);
#elif !UNITY_EDITOR && UNITY_IOS
            NGMediaReceiveCallbackiOS.Initialize(callback);
            if (imageMode)
            {
                if (maxSize <= 0)
                {
                    maxSize = SystemInfo.maxTextureSize;
                }

                _NativeGallery_PickImage(IOSSelectedImagePath, maxSize);
            }
            else
            {
                _NativeGallery_PickVideo();
            }
#else
            if (callback != null)
            {
                callback(null);
            }
#endif
        }

        return(result);
    }
Esempio n. 3
0
    private static Permission GetMediaFromGallery(MediaPickCallback callback, bool imageMode, string mime, string title, int maxSize)
    {
        Permission result = RequestPermission();

        if (result == Permission.Granted && !IsMediaPickerBusy())
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            object threadLock = new object();
            lock ( threadLock )
            {
                NGMediaReceiveCallbackAndroid nativeCallback = new NGMediaReceiveCallbackAndroid(threadLock);

                AJC.CallStatic("PickMedia", Context, nativeCallback, imageMode, false, mime, title);

                if (string.IsNullOrEmpty(nativeCallback.Path))
                {
                    System.Threading.Monitor.Wait(threadLock);
                }

                string path = nativeCallback.Path;
                if (string.IsNullOrEmpty(path))
                {
                    path = null;
                }

                if (callback != null)
                {
                    callback(path);
                }
            }
#elif !UNITY_EDITOR && UNITY_IOS
            NGMediaReceiveCallbackiOS.Initialize(callback);
            if (imageMode)
            {
                if (maxSize <= 0)
                {
                    maxSize = SystemInfo.maxTextureSize;
                }

                _NativeGallery_PickImage(IOSSelectedImagePath, maxSize);
            }
            else
            {
                _NativeGallery_PickVideo();
            }
#else
            if (callback != null)
            {
                callback(null);
            }
#endif
        }

        return(result);
    }
Esempio n. 4
0
    private static Permission GetLocationSSIDFromGallery(MediaPickCallback callback)
    {
        CheckPermission();

// action 2相册,3拍照
#if !UNITY_EDITOR && UNITY_ANDROID
#elif !UNITY_EDITOR && UNITY_IOS
        if (!IsMediaPickerBusy())
        {
            NGMediaReceiveCallbackiOS.Initialize(callback);
        }
#endif
        return(Permission.Denied);
    }
    private static Permission GetMediaFromGallery(MediaPickCallback callback, bool imageMode, string mime, string title)
    {
        Permission result = RequestPermission();

        if (result == Permission.Granted && !IsMediaPickerBusy())
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            object threadLock = new object();
            lock ( threadLock )
            {
                NGMediaReceiveCallbackAndroid nativeCallback = new NGMediaReceiveCallbackAndroid(threadLock);

                AJC.CallStatic("PickMedia", Context, nativeCallback, imageMode, mime, title);

                if (string.IsNullOrEmpty(nativeCallback.Path))
                {
                    System.Threading.Monitor.Wait(threadLock);
                }

                string path = nativeCallback.Path;
                if (string.IsNullOrEmpty(path))
                {
                    path = null;
                }

                if (callback != null)
                {
                    callback(path);
                }
            }
#elif !UNITY_EDITOR && UNITY_IOS
            NGMediaReceiveCallbackiOS.Initialize(callback);
            if (imageMode)
            {
                _PickImage(Path.Combine(Application.temporaryCachePath, "tmp.png"));
            }
            else
            {
                _PickVideo();
            }
#else
            if (callback != null)
            {
                callback(null);
            }
#endif
        }

        return(result);
    }
    private static Permission GetMediaFromGallery(MediaPickCallback callback, MediaType mediaType, string mime, string title)
    {
        Permission result = RequestPermission(true);

        if (result == Permission.Granted && !IsMediaPickerBusy())
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            string savePath;
            if (mediaType == MediaType.Image)
            {
                savePath = SelectedImagePath;
            }
            else if (mediaType == MediaType.Video)
            {
                savePath = SelectedVideoPath;
            }
            else
            {
                savePath = SelectedAudioPath;
            }

            AJC.CallStatic("PickMedia", Context, new NGMediaReceiveCallbackAndroid(callback, null), (int)mediaType, false, savePath, mime, title);
#elif !UNITY_EDITOR && UNITY_IOS
            NGMediaReceiveCallbackiOS.Initialize(callback);
            if (mediaType == MediaType.Image)
            {
                _NativeGallery_PickImage(SelectedImagePath);
            }
            else if (mediaType == MediaType.Video)
            {
                _NativeGallery_PickVideo(SelectedVideoPath);
            }
            else if (callback != null)              // Selecting audio files is not supported on iOS
            {
                callback(null);
            }
#else
            if (callback != null)
            {
                callback(null);
            }
#endif
        }

        return(result);
    }
Esempio n. 7
0
    private static Permission GetMediaFromGallery(MediaPickCallback callback, MediaType mediaType, string mime, string title, bool crop = true, int action = 0)
    {
        // action 2相册,3拍照
#if !UNITY_EDITOR && UNITY_ANDROID
        string savePath;
        if (mediaType == MediaType.Image)
        {
            savePath = SelectedImagePath;
        }
        else if (mediaType == MediaType.Video)
        {
            savePath = SelectedVideoPath;
        }
        else
        {
            savePath = SelectedAudioPath;
        }

        AJC.CallStatic("PickMedia", Context, new NGMediaReceiveCallbackAndroid(callback, null), (int)mediaType, false, savePath, mime, title, crop, action);
        return(Permission.Granted);
#elif !UNITY_EDITOR && UNITY_IOS
        if (!IsMediaPickerBusy())
        {
            NGMediaReceiveCallbackiOS.Initialize(callback);
            if (mediaType == MediaType.Image)
            {
                _NativeGallery_PickImage(SelectedImagePath);
            }
            else if (mediaType == MediaType.Video)
            {
                _NativeGallery_PickVideo(SelectedVideoPath);
            }
            else if (callback != null)              // Selecting audio files is not supported on iOS
            {
                callback(null);
            }
        }
#else
        if (callback != null)
        {
            callback(null);
        }
#endif
        return(Permission.Denied);
    }
Esempio n. 8
0
    private static Permission IPhoneCameraMakeVideoMediaFromGallery(MediaPickCallback callback, MediaType mediaType, string mime, string title)
    {
        Permission result = RequestIPhonePermission(4);

        if (result == Permission.Granted && !IsMediaPickerBusy())
        {
#if !UNITY_EDITOR && UNITY_ANDROID
#elif !UNITY_EDITOR && UNITY_IOS
            NGMediaReceiveCallbackiOS.Initialize(callback);
            _NativeGallery_PickCameraVideo(SelectedImagePath);
#else
            if (callback != null)
            {
                callback(null);
            }
#endif
        }

        return(result);
    }
Esempio n. 9
0
    // action 1.SSID  2.版本号 + build 号 3.绑定设备 4.build
    public static void GetSomethingFromIPhone(MediaPickCallback callback, int action, string msg)
    {
#if !UNITY_EDITOR && UNITY_ANDROID
        //----
#elif !UNITY_EDITOR && UNITY_IOS
        NGMediaReceiveCallbackiOS.Initialize(callback, action);
        if (action == 1)
        {
            _NativeGallery_GetSSID();
        }
        else if (action == 2)
        {
            _NativeGallery_GetVersionBuild();
        }
        else if (action == 3)
        {
            _UnityNativeGallery_BindDevice(msg);
        }
        else if (action == 4)
        {
            _NativeGallery_GetBuild();
        }
        else if (action == 5)
        {
            _NativeGallery_GetCacheSize();
        }
        else if (callback != null)          // Selecting audio files is not supported on iOS
        {
            callback(null);
        }
#else
        if (callback != null)
        {
            callback(null);
        }
#endif
    }
Esempio n. 10
0
    private static Permission GetMediaFromGallery(MediaPickCallback callback, MediaType mediaType, string mime, string title)
    {
        Permission result = RequestPermission(PermissionType.Read);

        if (result == Permission.Granted && !IsMediaPickerBusy())
        {
#if UNITY_EDITOR
            System.Collections.Generic.List <string> editorFilters = new System.Collections.Generic.List <string>(4);

            if ((mediaType & MediaType.Image) == MediaType.Image)
            {
                editorFilters.Add("Image files");
                editorFilters.Add("png,jpg,jpeg");
            }

            if ((mediaType & MediaType.Video) == MediaType.Video)
            {
                editorFilters.Add("Video files");
                editorFilters.Add("mp4,mov,wav,avi");
            }

            if ((mediaType & MediaType.Audio) == MediaType.Audio)
            {
                editorFilters.Add("Audio files");
                editorFilters.Add("mp3,aac,flac");
            }

            editorFilters.Add("All files");
            editorFilters.Add("*");

            string pickedFile = UnityEditor.EditorUtility.OpenFilePanelWithFilters("Select file", "", editorFilters.ToArray());

            if (callback != null)
            {
                callback(pickedFile != "" ? pickedFile : null);
            }
#elif UNITY_ANDROID
            AJC.CallStatic("PickMedia", Context, new NGMediaReceiveCallbackAndroid(callback, null), (int)mediaType, false, SelectedMediaPath, mime, title);
#elif UNITY_IOS
            if (mediaType == MediaType.Audio)
            {
                Debug.LogError("Picking audio files is not supported on iOS");

                if (callback != null)                  // Selecting audio files is not supported on iOS
                {
                    callback(null);
                }
            }
            else
            {
                NGMediaReceiveCallbackiOS.Initialize(callback, null);
                _NativeGallery_PickMedia(SelectedMediaPath, (int)(mediaType & ~MediaType.Audio), PermissionFreeMode ? 1 : 0, 1);
            }
#else
            if (callback != null)
            {
                callback(null);
            }
#endif
        }

        return(result);
    }