Skip to content

用于Unity的安卓与IOS打开相机、相册、保存照片的插件

Notifications You must be signed in to change notification settings

ysms2022/UnityCamera

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
}

About

用于Unity的安卓与IOS打开相机、相册、保存照片的插件

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 92.0%
  • Objective-C++ 8.0%