GJM :Unity使用EasyAR实现脱卡功能
2024-10-11 22:47:44
首先说下大致思路
当卡片离开摄像头时间,ImageTarget-Image的SetActive (false),所以其子物体(model)也就不显示了,因此解决的办法就是在Target (false)时间将模型放到一个合适的位置,这样就能实现脱卡,当Target (true)时,再回到原来位置。具体放到什么位置合适
在EasyAR下面的Augmenter下建设一个空物体,用来存放脱卡后的模型命名ZhenF(真模型的Father),这个位置的模型不会移动,永远都在屏幕固定位置。然后在ZhenF下面建一个空物体用来保存模型的最佳位置和角度。
然后在ImageTarget-Image的下面建一个空物体用来保存target出现时间的最佳位置和角度。
- using UnityEngine;
- using System.Collections;
- public class ZSetactive : MonoBehaviour
- {
- public Transform GreatTransfrom;//脱卡后最佳位置
- public GameObject zhenf;//模型脱卡时存放位置
- public Transform[] TargetTransfrom;//模型在卡片上的最佳位置
- public GameObject[] Target;//卡片
- public GameObject[] zhen;//模型
- void Start ()
- {
- for (int i = 0; i < zhen.Length; i++) {//所有模型初始化全部不显示
- zhen [i].SetActive (false);
- }
- }
- public void tiaozheng ()//模型倾斜时调整最佳位置
- {
- GreatTransfrom.localPosition = new Vector3 (0f,0f,0f);
- GreatTransfrom.localRotation = Quaternion .identity;
- for (int i = 0; i < zhen.Length; i++) {
- zhen [i].transform.localPosition = GreatTransfrom.localPosition ;
- zhen [i].transform.localRotation = GreatTransfrom.localRotation ;
- }
- }
- void Update ()
- {
- WhoShouldShow();//哪个模型应该显示
- TargetT();//有卡片时
- TargetF();//无卡片时
- }
- int index = -1;
- void WhoShouldShow(){//哪个模型应该显示
- // for (int i = 0; i < Target .Length ; i++) {
- // if (Target [i].activeSelf == true) {
- // zhen [i].SetActive (true);
- // index = i ;
- // if (i != index ) {
- // zhen [i].SetActive (false);
- // }
- // }
- // }
- if (Target [0].activeSelf == true) {
- zhen [0].SetActive (true);
- zhen [1].SetActive (false);
- zhen [2].SetActive (false);
- zhen [3].SetActive (false);
- }
- if (Target [1].activeSelf == true) {
- zhen [0].SetActive (false);
- zhen [1].SetActive (true);
- zhen [2].SetActive (false);
- zhen [3].SetActive (false);
- }
- if (Target [2].activeSelf == true) {
- zhen [0].SetActive (false);
- zhen [1].SetActive (false);
- zhen [2].SetActive (true);
- zhen [3].SetActive (false);
- }
- if (Target [3].activeSelf == true) {
- zhen [0].SetActive (false);
- zhen [1].SetActive (false);
- zhen [2].SetActive (false);
- zhen [3].SetActive (true);
- }
- }
- void TargetT(){
- for (int i = 0; i < Target.Length; i++) {//不脱卡
- if (Target [i].activeSelf == true) {
- zhen [i].transform.parent = Target [i].transform;
- zhen [i].transform.position = TargetTransfrom [i].position;
- }
- }
- }
- void TargetF(){//脱卡
- for (int i = 0; i < Target.Length; i++) {
- if (Target [i].activeSelf == false) {
- zhen [i].transform.parent = zhenf.transform;
- zhen [i].transform.localPosition = GreatTransfrom.localPosition;
- }
- }
- }
- }
把这个脚本可以放在一个空物体上面。。
最新文章
- gdb的可视化工具安装
- EntityFramework系列:MySql的RowVersion
- gdo图形引擎中的旋转角
- 实例对比剖析c#引用参数的用法
- 使用mitmf 来绕过HSTS站点抓取登陆明文
- .NET设计模式(13):享元模式(Flyweight Pattern)(转)
- 第三百二十八天 how can I 坚持
- 庖丁解牛-----Live555源码彻底解密(RTP打包)
- 春&;风
- android 中国通信乱码问题
- android调用js
- CentOS配置上网
- 我的Python学习笔记(四):动态添加属性和方法
- ListView下拉刷新上拉加载更多实现
- 关于openssl的交叉编译
- JavaEE 要懂的小事:二、图解 Cookie(小甜饼)
- Java - 33 Java Applet基础
- 回归JavaScript基础(九)
- git用户名和邮箱配置
- Canvas 高级