# UnityCamera **Repository Path**: littlesis/UnityCamera ## Basic Information - **Project Name**: UnityCamera - **Description**: 用于Unity的安卓与IOS打开相机、相册、保存照片的插件 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2020-04-12 - **Last Updated**: 2021-11-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UnityCamera ## 用于Unity的安卓与IOS调用相机、相册的插件

项目使用Unity2017.4.2f2测试:

集成了UnityNativeCamera https://github.com/yasirkula/UnityNativeCamera 与UnityNativeGallery https://github.com/yasirkula/UnityNativeGallery

### 安卓端配置: **如果需要保存照片,则PlayerSetting中 设置Write Permission为External (SDCard)** **其他无需任何配置** ### IOS端配置: **默认情况下IOS打包无需任何配置即可使用** ```Editor/PostProcessBuild.cs```中会自动配置打包XCode工程需要的配置: ```NSCameraUsageDescription```相机权限 ```NSPhotoLibraryUsageDescription```相册权限 ```NSMicrophoneUsageDescription```媒体权限 ```NSPhotoLibraryAddUsageDescription```添加到相册权限等。 并删除了```UIApplicationExitsOnSuspend```以解决在XCode上传时导致警告问题 如果想要手动配置权限:请把```ENABLED = false; ```然后打包XCode工程后手动修改```Info.plist ``` ### 使用方法: #### 打开相册选择照片: NativeCall.OpenPhoto(Action callBack) NativeCall.OpenPhoto(Action callBack) #### 打开相机拍照: NativeCall.OpenCamera(Action callBack) NativeCall.OpenCamera(Action callBack) #### 保存照片到相册: NativeCall.SavePhoto(Texture2D tex, Action callBack = null).. #### 安卓端显示一个Toast,IOS端显示一个带有'好'字的提示框 NativeCall.ShowToast(string msg) ### 参考Sample场景、SampleCamera.cs //打开相机 private void OpenCamera() { NativeCall.OpenCamera((Texture2D tex)=> { rawImage.texture = tex; rawImage.rectTransform.sizeDelta = new Vector2(tex.width, tex.height); }); } //打开相册 private void OpenPhoto() { NativeCall.OpenPhoto((Texture2D tex) => { rawImage.texture = tex; rawImage.rectTransform.sizeDelta = new Vector2(tex.width, tex.height); }); } //保存照片 private void SavePhoto() { NativeCall.SavePhoto(rawImage.texture as Texture2D); }