/**
-
EasyAR2.1使用方法
-
EasyAR_非子萧_201711
-
1,场景中添加EasyAR_Startup预制体(EasyAR摄像机):+KEY:
-
2,场景中添加EasyAR_ImageTarget预制体(空对象+本脚本)(EaayAR识别图)+EasyAR_ImageTarget脚本
-
3,(2预制体+本脚本)
-
4,本脚本参数:(识别图路径)Path:idback.jpg/targets.json;(注意:必须要文件扩展名.jpg/.json)
-
5, 本脚本参数: (识别图名称) Name:idabck(主意:没有后缀;idback.jpg文件必须在StreamingAssets文件夹中)
-
6, 本脚本参数:(识别图大小)Size: X=8.56,Y=5.4(注意:这儿不设置大小,Transform组件中,大小不能设置)
-
7,本脚本参数:(识别图脱卡)IsTuoKa:选择(true)=脱卡,不选择(false)=不脱卡,默认不脱卡;
-
8, 本脚本参数: (识别图存储) Storage:Assets(StreamingAssets文件夹)
-
9,给识别图添加子对象:子对象就是要显示的对象
-
10,本脚本参数:Loader TmageTracker(EasyAR_Startup中的ImageTracker)
*应用名称:XXEasyAR
*Bundle ID:com.XXEasyAR.www
*KEY:yXt3uSTmVF2ohIJ9fSa4dM6hOFIYSUMJxx6NJIUzf9IlVWP0Mm1YM59JCEp9XssSjPwsmsqMySsowhXGRrkCLeoAPpYxsxlpVMbKfmlJbjcLyXrLumRlrkxkTfYue7PIc9qmOzlZSoEH42E5I581o3i8dEAdN0E9nnCaIGZ8EATp9trqWarcMHsT6Ljxr2y7afGEMcRf
*/
using UnityEngine;
using EasyAR;
public class EasyAR_ImageTarget : ImageTargetBehaviour
{
//脱卡
public bool isTuoKa = false;//是否脱卡=否
protected override void Awake()
{
base.Awake();
TargetFound += OnTargetFound;
TargetLost += OnTargetLost;
TargetLoad += OnTargetLoad;
TargetUnload += OnTargetUnload;
}
protected override void Start()
{
base.Start();
HideObjects(transform);
}
//隐藏识别图子对象
void HideObjects(Transform trans)
{
for (int i = 0; i < trans.childCount; ++i)
HideObjects(trans.GetChild(i));
if (transform != trans)
{
gameObject.SetActive(false);
}
}
//显示识别图子对象
void ShowObjects(Transform trans)
{
for (int i = 0; i < trans.childCount; ++i)
ShowObjects(trans.GetChild(i));
if (transform != trans)
{
gameObject.SetActive(true);
}
}
/// <summary>
/// 当识别到目标图片时
/// </summary>
/// <param name="behaviour"></param>
void OnTargetFound(TargetAbstractBehaviour behaviour)
{
Debug.Log("Found: " + Target.Id);
ShowObjects(transform);//显示识别图子对象
}
/// <summary>
/// 当识别不到目标图片时
/// </summary>
/// <param name="behaviour"></param>
void OnTargetLost(TargetAbstractBehaviour behaviour)
{
Debug.Log("Lost: " + Target.Id);
//是否脱卡
if (isTuoKa)
{//当选择脱卡,识别不到目标图片时,子对象显示
ShowObjects(transform);
}
else
{//当选择不脱卡,识别不到目标图片时,子对象隐藏
HideObjects(transform);
}
}void OnTargetLoad(ImageTargetBaseBehaviour behaviour, ImageTrackerBaseBehaviour tracker, bool status)
{
Debug.Log("Load target (" + status + "): " + Target.Id + " (" + Target.Name + ") " + " -> " + tracker);
}void OnTargetUnload(ImageTargetBaseBehaviour behaviour, ImageTrackerBaseBehaviour tracker, bool status)
{
Debug.Log("Unload target (" + status + "): " + Target.Id + " (" + Target.Name + ") " + " -> " + tracker);
}
}
网友评论