download dabatase -unity editor
数据包导入
右键-vuforia-image -cube
download dabatase -unity editor
数据包导入
右键-vuforia-image -cube
touchcount——有几根手指触碰到屏幕
AR学习:
使用vuforia
unity 2017.3
RFX1-RFX1 resources -prefabs-V1
GameObject Aixi = GameObject.Instantiate (AixiPrefab );
Aixi.transform.position = this.transform.position;
Aixi.transform.parent = this.transform;
在图片表面生成物体
Destroy (GameObject.Find ("Aixi(Clone)"));
销毁生成的
ARCamera:负责真实世界的显示 = 调用设备的摄像机
将特效加入的方法和生成寒冰特效一摸一样。
生成代码可以参考如下:
//生成血池
GameObject e1 = GameObject.Instantiate (bloodprefab ,transform .position ,Quaternion .identity );
// bloodprefab .transform.position = this.transform.position;
e1 .transform.parent = this.transform;
定时销毁代码:Destroy(e1,10.0f);
放于生成
transform.Translate (new Vector3 (0f, 0.7f, 0f) * Time.deltaTime);
//用来进行缓慢移动的操作
//生成初始位置时往y下移1.6
GameObject Aixi = GameObject.Instantiate (AixiPrefab,transform .position -new Vector3 (0f,1.6f,0f), transform.rotation );
// Aixi.transform.position = this.transform.position;
Aixi.transform.parent = this.transform;
//判断艾希是否已经到达纸面上
if (transform.localPosition.y > 0) {
return;
}
shabi
Create \ RenderTexture
放入MainCamera的TargetTexture
将MainCamera对着物体;
新建Plane,将RenderTexture赋给Plane;
Camera的ClearFlags改为:SolidColor
Plane的Shadow改为LegacyShaders\Transparent\Diffuse
给要显示的物体指定层级,修改Camera渲染的层级:CullingMask:改为指定层级
改变摄像机的位置,获得不同位置照射的物体,作为阴影;
将Plane和Camera 都放在物体下,物体放在ImageTarget下;
AR camera有两个作用,一个调用相机,了另一个使用vuforia behaviour脚本
world center mode
vuforia configuration -camera direction
前置摄像头/后置摄像头
图片需要先上传到vuforia数据库才能被识别
1.AudioSource和AudioClip的区别
2.Invoke()函数的用法
1.触屏检测
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray,out hitInfo))
{
if (Input.touchCount==1&&Input.GetTouch(0).phase==TouchPhase.Began)
{
if(Input.GetTouch(0).tapCount==2) Destroy(hitInfo.collider.gameObject);
}
}
}
阴影制作
1.将摄像头放置于图片上面,能捕捉到图片。
2.建立texture文件夹,在文件夹里面新建Render texture。并将此添加到主相机的target Texture。(这时的render texture的纹路即为主摄像机所见内容)。将main camera 里面的Clear Flags设置为solid color。
3.新建plane,将render texture作为贴图拖放置于上。
选中plane-ARshadow-legacy shadow-transparent-diffuse。(只留下了想要的纹理)
4.将aixi放到摄像机下面,做艾希的阴影。
先设置aixi 的渲染优先级。(第一步在aixi的layer组件中设置8-aixi、第二部在main camera里面的culling mask里面先选nothing,再选aixi)
然后调整
1.先给imagetarget添加一个audiosourse组件,将BGM放到这个组件之中。
2.在脚本中先定义两个音频private AudioSource audio;
private Audio welcomeCilp;
3.在start里面获得audiosourse组件,然后在动画播放六秒后播放欢迎语句。
audio = this.GetComponent <AudioSource > ();
Invoke ("PlaywelcomeCilp", 6.0f);
4.在found中添加播放BGM的代码。
if (!audio.isPlaying) {
audio.Play ();
}
5.添加一个播放欢迎语句的方法PlaywelcomeClip()然后在start里面调用这个方法。
private void PlaywelcomeClip(){
AudioSource.PlayClipAtPoint (welcomeCilp, transform.position);
}
开始代码改变
打开unity,点击工具栏的GameObject->Vuforia->AR Camera,会导入一些资源(外置包不会导入)
然后AR camera的Vuforia Behavior会报警告,点击Build Setting->Player Setting ,找到XR Setting栏,勾选上下面的Vuforia Augmented Reality Supper,就不会报错了
在官网里,点击Develop,点击Get Development Key,填写项目名,通过。然后在项目栏里,点击刚刚创建的项目,复制Key文本
回到unity,点击刚刚创建的AR Camera,点击Open Vuforia configuration,Resources文件夹下会新建一个VuforiaConfiguration,把刚刚复制官网的Key文本黏贴到App License Key中(外置包不用)
scene 场景只显示cube
因为 imagetarget有三个脚本
1、image target Behaviour数据库图片进行设置 Datable是使用那个数据库 image targe图片
Advanced 宽 高
2、turn off
是否获取设备摄像头的链接
3丢失不在被手机识别
void Update () {
if (Input.GetMouseButtonDown (0)) {
//发射一条射线,位置是点击到的位置
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//用来接收返回回来的信息
RaycastHit hitInfo;
//如果接收到了返回来的信息
if (Physics.Raycast (ray, out hitInfo)) {
//touchCount是指有几个手指碰到屏幕,后面的是指第一次触摸
if (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Began) {
if (Input.GetTouch (0).tapCount == 2)
Destroy (hitInfo.collider.gameObject);
}
}
}
}
}
1.要判断长按,需要定义一个变量来记录按的时间
private float touchTime;
2.定义一个变量,判断是不是新按上去的
private bool newTouch=false;
3.在update里面编写功能。