项目使用Unity2017.4.2f2测试:
集成了UnityNativeCamera https://github.com/yasirkula/UnityNativeCamera 与UnityNativeGallery https://github.com/yasirkula/UnityNativeGallery
如果需要保存照片,则PlayerSetting中 设置Write Permission为External (SDCard)
其他无需任何配置
默认情况下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)..
NativeCall.ShowToast(string msg)
//打开相机
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);
}