• 大小: 3.47MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-10
  • 语言: 其他
  • 标签: unity  

资源简介

unity for ios 上传IOS机本地的头像 相机的获取 相册的获取 截图拍照

资源截图

代码片段和文件信息

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class IOSAlbumCamera : MonoBehaviour
{
[DllImport (“__Internal“)]
private static extern void _iosOpenPhotoLibrary();
[DllImport (“__Internal“)]
private static extern void _iosOpenPhotoAlbums();
[DllImport (“__Internal“)]
private static extern void _iosOpenCamera();
[DllImport (“__Internal“)]
private static extern void _iosOpenPhotoLibrary_allowsEditing();
[DllImport (“__Internal“)]
private static extern void _iosOpenPhotoAlbums_allowsEditing();
[DllImport (“__Internal“)]
private static extern void _iosOpenCamera_allowsEditing();
[DllImport (“__Internal“)]
private static extern void _iosSaveImageToPhotosAlbum(string readAddr);

    /// 
    /// 打开照片
    /// 

    /// 
public static void iosOpenPhotoLibrary(bool allowsEditing=false)
{
if (allowsEditing)
_iosOpenPhotoLibrary_allowsEditing ();
else
_iosOpenPhotoLibrary ();
}

    /// 
    /// 打开相册
    /// 

    /// 
public static void iosOpenPhotoAlbums(bool allowsEditing=false)
{
if (allowsEditing)
_iosOpenPhotoAlbums_allowsEditing ();
else
_iosOpenPhotoAlbums ();
}

    /// 
    /// 打开相机
    /// 

    /// 
public static void iosOpenCamera(bool allowsEditing=false)
{
if (allowsEditing)
_iosOpenCamera_allowsEditing ();
else
_iosOpenCamera ();
}

    /// 
    /// 保存图片到相册
    /// 

    /// 
public static void iosSaveImageToPhotosAlbum(string readAddr)
{
_iosSaveImageToPhotosAlbum (readAddr);
}

    /// 
    /// 将ios传过的string转成u3d中的texture
    /// 

    /// se64“>
    /// 
public static Texture2D base64StringToTexture2D(string base64)
{
Texture2D tex = new Texture2D (4 4 TextureFormat.ARGB32 false);
try
{
byte[] bytes = System.Convert.Frombase64String(base64);
tex.LoadImage(bytes);
}
catch(System.Exception ex)
{
            Debug.LogError(ex.Message);
}
return tex;
}    

private static IOSAlbumCamera _instance;
public static IOSAlbumCamera Instance{get{ return _instance; }}

public System.Action CallBack_PickImage_With_base64;
public System.Action CallBack_ImageSavedToAlbum;

void Awake()
{
if (_instance != null)
{
DestroyImmediate(this);
return;
}
_instance = this;
// Gameobject go = new Gameobject (“IOSAlbumCamera“);
// _instance = go.AddComponent ();
}

/// 
/// 打开相册相机后的从ios回调到unity的方法
/// 

/// se64“>base64.
void PickImageCallBack_base64(string base64)
{
if(CallBack_PickImage_With_base64!=null)
{
CallBack_PickImage_With_base64(base64);
}
}

    /// 
    /// 保存图片到相册后,从ios回调到unity的方法
    /// 

    /// 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-02-26 13:14  IOSXiangce\
     目录           0  2016-02-26 13:00  IOSXiangce\.vs\
     目录           0  2016-02-26 13:00  IOSXiangce\.vs\IOSAlubmCamera\
     目录           0  2016-02-26 13:14  IOSXiangce\.vs\IOSAlubmCamera\v14\
     文件       98304  2016-02-26 13:14  IOSXiangce\.vs\IOSAlubmCamera\v14\.suo
     文件        4349  2016-02-26 10:35  IOSXiangce\Assembly-CSharp.csproj
     目录           0  2016-02-26 13:14  IOSXiangce\Assets\
     目录           0  2016-02-26 13:14  IOSXiangce\Assets\IOSAlubmCamera\
     文件         191  2016-02-25 18:26  IOSXiangce\Assets\IOSAlubmCamera.meta
     目录           0  2016-02-26 12:02  IOSXiangce\Assets\IOSAlubmCamera\demo\
     文件         191  2016-02-25 18:29  IOSXiangce\Assets\IOSAlubmCamera\demo.meta
     文件       25338  2016-02-24 20:45  IOSXiangce\Assets\IOSAlubmCamera\demo\49DB73250F3DA51A67A5FCF14D6239CF.png
     文件        1308  2016-02-26 12:00  IOSXiangce\Assets\IOSAlubmCamera\demo\49DB73250F3DA51A67A5FCF14D6239CF.png.meta
     文件        1752  2016-02-26 12:01  IOSXiangce\Assets\IOSAlubmCamera\demo\iosalubmcamer_demo.cs
     文件         262  2016-02-25 18:29  IOSXiangce\Assets\IOSAlubmCamera\demo\iosalubmcamer_demo.cs.meta
     文件       44628  2016-02-26 12:02  IOSXiangce\Assets\IOSAlubmCamera\demo\isoalubmcamer_demo.unity
     文件         174  2016-02-25 18:27  IOSXiangce\Assets\IOSAlubmCamera\demo\isoalubmcamer_demo.unity.meta
     文件        3319  2016-02-26 13:14  IOSXiangce\Assets\IOSAlubmCamera\IOSAlbumCamera.cs
     文件         262  2016-02-25 18:30  IOSXiangce\Assets\IOSAlubmCamera\IOSAlbumCamera.cs.meta
     目录           0  2016-02-26 13:14  IOSXiangce\Assets\Plugins\
     文件         191  2016-02-25 18:27  IOSXiangce\Assets\Plugins.meta
     目录           0  2016-02-26 11:44  IOSXiangce\Assets\Plugins\IOS\
     文件         191  2016-02-25 18:27  IOSXiangce\Assets\Plugins\IOS.meta
     文件         210  2016-02-26 10:37  IOSXiangce\Assets\Plugins\IOS\IOSAlbumCameraController.h
     文件         309  2016-02-25 18:28  IOSXiangce\Assets\Plugins\IOS\IOSAlbumCameraController.h.meta
     文件       10369  2016-02-26 11:44  IOSXiangce\Assets\Plugins\IOS\IOSAlbumCameraController.mm
     文件         309  2016-02-25 18:28  IOSXiangce\Assets\Plugins\IOS\IOSAlbumCameraController.mm.meta
     文件        6494  2016-02-26 13:00  IOSXiangce\IOSAlubmCamera.CSharp.csproj
     文件         931  2016-02-26 12:54  IOSXiangce\IOSAlubmCamera.sln
     文件         639  2016-02-26 12:51  IOSXiangce\IOSAlubmCamera.userprefs
     目录           0  2016-02-26 13:14  IOSXiangce\Library\
............此处省略803个文件信息

评论

共有 条评论