Skip to content

Latest commit

 

History

History
61 lines (47 loc) · 1.7 KB

README.md

File metadata and controls

61 lines (47 loc) · 1.7 KB

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打包无需任何配置即可使用

使用方法:

打开相册选择照片:

NativeCall.OpenPhoto(Action<Texture2D> callBack)  
NativeCall.OpenPhoto(Action<string> callBack)    

打开相机拍照:

NativeCall.OpenCamera(Action<Texture2D> callBack)  
NativeCall.OpenCamera(Action<string> callBack)    

保存照片到相册:

NativeCall.SavePhoto(Texture2D tex, Action<bool> 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);
}