</div>
<!-- /Block user information module HEADER -->
<ul class="p_pop nav_pop" id="umnav_menu" style="display: none;">
<li><a href="http://www.manew.com/forum.php?mod=guide&view=my" _style="background-image:url(http://www.manew.com/static/image/feed/thread_b.png) !important">帖子</a></li>
<li><a href="http://www.manew.com/home.php?mod=space&do=favorite&view=me" _style="background-image:url(http://www.manew.com/static/image/feed/favorite_b.png) !important">收藏</a></li>
<li><a href="http://www.manew.com/home.php?mod=magic" _style="background-image:url(http://www.manew.com/static/image/feed/magic_b.png) !important">道具</a></li>
<li><a href="http://www.manew.com/home.php?mod=medal" _style="background-image:url(http://www.manew.com/static/image/feed/medal_b.png) !important">勋章</a></li>
<li><a href="http://www.manew.com/home.php?mod=task" _style="background-image:url(http://www.manew.com/static/image/feed/task_b.png) !important">任务</a></li>
<li><a href="http://www.manew.com/forum.php?mod=collection&op=my" _style="background-image:url(http://www.manew.com/static/image/feed/collection_b.png) !important">淘帖</a></li>
<li><a href="misc.php?mod=ranklist" _style="background-image:url(http://www.manew.com/static/image/feed/ranklist_b.png) !important">排行榜</a></li>
<li><a href="http://www.manew.com/home.php?mod=spacecp" rel="nofollow">设置</a></li>
<li><a href="member.php?mod=logging&action=logout&formhash=a237ee7e" rel="nofollow">退出</a></li>
</ul>
<div class="header_user" style="float: right;"><ul id="header_nav">
<li class="login_list"><a class="login_block_q" href="http://www.manew.com/tao">淘帖</a></li>
<li class="login_list"><a class="login_block_q" href="http://www.manew.com/thread-32240-1-1.html" rel="nofollow">微信签到</a></li>
</ul></div>
<div class="bus_search"> <div class="scbar_narrow cl" id="scbar">
帖子 | 搜索 |
<ul class="bus_box animated fadeInUp manew_dhxt">
-
__________________________________________________________________________________
开发者干货区版块规则:
1、文章必须是图文形式。(至少2幅图)
2、文章字数必须保持在1500字节以上。(编辑器右下角有字数检查)
3、本版块只支持在游戏蛮牛原创首发,不支持转载。
4、本版块回复不得无意义,如:顶、呵呵、不错……【真的会扣分的哦】
5、……
__________________________________________________________________________________
抢楼 | 本帖为抢楼帖,欢迎抢楼! |
最近做项目需要用到这个功能,就是在Unity中调用本地相册或直接打开摄像机拍照并且裁剪一部分用于用户头像,今天研究了一下,那么研究出成果了MOMO一定要分享给大家。Unity与Android的交互还有谁不会?? 如果有不会的朋友请看MOMO之前的文章喔,Unity3D研究院之打开Activity与调用JAVA代码传递参数(十八)这里有关交互的方式就不详细说明,主要将如何在Unity中打开摄像机、在Unity中打开本地相册,选一个照片后如何进行裁剪,最后将图片转换成Texture显示在U3D的世界当中。 首先看看Eclipse中的Android插件部分,我的包名是com.xys请大家与MOMO保持一致,Unity工程中也需要是这个包名噢。 UnityTestActivity.java 这个类是Unity的插件主类,在这里调用是打开摄像机 还是本地相册的方法。
[AppleScript] 纯文本查看 复制代码
然后是WebViewActivity.java 这里主要处理用户打开摄像机或本地相册后如何进行裁剪图片,并且把裁剪的图片储存在本地文件中。
[AppleScript] 纯文本查看 复制代码
注解1:主要是路径”/mnt/sdcard/Android/data/com.xys/files”,如下图所示,我们在这里把文件保存在这个路径下。为什么要把图片2进制文件写在这里呢? 还记得以前MOMO给大家说过在Unity中访问Android或IOS本地2进制文件时用到的这个路径,Application.persistentDataPath 该路径等价于 /mnt/sdcard/Android/data/com.xys/files ,当然后者的包名是对应的工程包名,这样在Unity中可以找到对应裁剪后的图片文件,并且显示在Unity中。 AndroidManifest.xml 这个文件也没什么好说的,大家看看吧。
[AppleScript]
纯文本查看
复制代码
然后把上面的Android工程打包做成插件放在Unity中。如下图所示,这个我的Unity工程中对应的路径。如果看不懂的朋友请看我之前的文章哈。 然后看Test.cs脚本,它直接挂在摄像机身上。
[AppleScript]
纯文本查看
复制代码
注解1:请大家一定要注意这个路径的写法, 前面一定要加 “File://” 不然无法读取。OK说了这么多我们看看这个项目运行的效果,激动人心的时刻来临啦 嚯嚯嚯嚯!!! 1.首次进入的画面, 这里的图片是我刚刚从相册选择的 2.打开相册我们选择一张图片 3. 选择一张图片,我们进行裁剪 最后我们返回到Unity中界面。新的图片Unity已经完成读取,界面上已经修改成刚刚我裁剪的啦,哇咔咔。 怎么样,还不错啦? 哈哈后。这个做用户头像肯定给力 蛤蛤。 如果点击打开摄像机按钮,拍照完毕后会提示裁剪,裁减完毕返回到Unity界面中同样能看到效果。 最后MOMO将本篇博文的源码放出来, 源码包括Android的工程 与Unity的工程,雨松MOMO祝大家学习愉快,大家互相学习互相进步,加油哇咔咔,啦啦啦。 下载地址:http://vdisk.weibo.com/s/ac5ZB unity3d 打开相册;unity3d 图片 裁剪;unity 裁剪图片;unity bitmap;unity 调用相册;unity bitmap 转texture;unity3d 相册;unity3d的图片裁剪;unity 图片裁剪;bitmap unity;unity 调用本地相册;unity texture bitmap;unity bitmap texture |
相关帖子
AR/VR
—untiy博客
|
支持 雨松MOMO |