关于Unity使用vuforia制作AR

环境:自带vuforia的unity

如果你的unity没有vuforia,可以在vuforia官网下载

使用前配置

进入vuforia官网,https://developer.vuforia.com/license-manager注册一个帐号

1.Get Development Key,获取License,这个License可以一直使用,以后不需要再Get了

2.添加Database

参考文章:https://blog.csdn.net/slj2017/article/details/79730378

3.制作AR及其动画

使用vufoira前,需要在Edit->Build Settings->Player Settings->XR Settings下勾选Vuforia Augmented Reality

1)unity中,从GameObject->Vuforia->ARCamera,添加ARCamera删除Main camera,

获取License,在vofuria官网点击ARCamera->Open Vuforia configuration->add License

2)从GameObject->Vuforia->Image,添加ImageTarget,点击ImageTarget,添加Database和Image Target,其中Database需要在vuforia官网下载后导入unity

3)将下载的模型拖入到unity中,即导入模型,并将对应的模型拖到ImageTarget下,作为其子对象,此时完成AR最基础的部分

4)添加动画声音绑定:

i)右键Create->New Animator Controller,双击打开该controller,create State->empty,再次create State->empty,选中第一次create的new State,右键make transition到第二次create的new State,点击第二次创建的new State,将模型动作拖到它的Motion里,选择controller里的'+'->Bool,命名,例如:isAnimation(与代码相对应,可自定义),最后将这个controller拖给模型

ii)点击模型,创建碰撞体:Add Component->capsule Collider,自行修改碰撞体大小范围

iii)点击模型,添加声音:Add Component->Audio Source,把声音拖到AudioClip下,可看情况选择是否勾选'Play On Awake‘

iiii)添加脚本:public class hyenaPlay : MonoBehaviour

{ // Start is called before the first frame update Animator ani; AudioSource audio; void Start() { ani = this.GetComponent<Animator>(); audio = this.GetComponent<AudioSource>(); } void OnMouseDown() { ani.SetBool("isAnimation", true); audio.Play(); } }

其中,”hyenaPlay“为脚本名字,"isAnimation"与上面的Bool值命名对应,最后将脚本拖给模型

5)可在同个场景内,添加多个AR模型,最后保存为一个场景,即File->Save as

6)导出apk:

i)File->Build settings->Player Settings,在Play Settings下选择other Settings,对Package Name进行设置,满足aa.bb.cc命名即可,将Minimum API Level选择为自己手机对应的android版本

ii)进入Edit->preferences,设置android SDK和JAVA SDK路径,最后bulid即可导出apk

关于unity打包安卓apk详细步骤:https://blog.csdn.net/weixin_41881186/article/details/80199302

猜你喜欢

转载自blog.csdn.net/Jonder_wu/article/details/86689826