影创AR眼镜

作者:追风剑情 发布于:2020-10-15 17:45 分类:Unity3d

影创科技-官方网站
影创科技-开放平台
影创科技-ActionOne文档

1111.png

导入SDK

1111.png

遇到的坑

1、需要处理交互事件的UI组件需要添加BoxCollider

2、动态创建GameObject时,一定要重置新对象的scale和z坐标,否则新对象的这两个值会变得很大,导致无法在眼镜里看到创建出来的新对象

示例代码

GameObject go = Instantiate<GameObject>(templet);
go.transform.SetParent(xxx);
//注意: 一定要对缩放和z坐标进行重置,否则这两个值会变得很大,无法在影创眼镜里看到创建出来的对象。
go.transform.localScale = scale;//重置此值与templet的scale保持一致
go.transform.localRotation = Quaternion.identity;
RectTransform rt = go.GetComponent<RectTransform>();
Vector3 pos = rt.anchoredPosition3D;
pos.z = posZ;//重置此值与templet的z坐标保持一致
rt.anchoredPosition3D = pos;
go.SetActive(true);

3、影创SDK在Unity2017、Unity2019中才支持高通(Vuforia)插件

4、SDK3.0.1需要在Unity2019.2.3中运行才最稳定(影创官方推荐版本)

5、使用手柄时,需要在设置里开启蓝牙,长按手柄侧键复位

6、SDK3.0.1的UIButton脚本运行时会重置BoxCollider尺寸,建议修改他们的代码

void AddBoxCollider() {
	RectTransform rt = GetComponent<RectTransform>();
	BoxCollider boxCollider = GetComponent<BoxCollider>();
	if(rt) {
		//Fix: 仅对自动创建的BoxCollider设值
		if(boxCollider == null) {
			boxCollider = gameObject.AddComponent<BoxCollider>();
			boxCollider.size = new Vector3(rt.sizeDelta.x, rt.sizeDelta.y, 0);
		}
	}
}

7、UGUI的z坐标会影响深度,值越小越靠前(接近眼睛)

8、影创的交互系统,需要导入using SC.InputSystem;


/// <summary>
/// 影创眼镜辅助类
/// </summary>
public sealed class ShadowCreatorHelper
{
    //[适配] 初始化
    public static void Initialize()
    {
        GameObject ShadowSystem = Resources.Load("Prefabs/ShadowSystem");
        //影创SDK_3.0.1已经移除了ActionSystem
        GameObject ActionSystem = Resources.Load("Prefabs/ActionSystem");
        if (ShadowSystem)
        {
            GameObject go = GameObject.Instantiate(ShadowSystem);
            go.name = "ShadowSystem";
            go.transform.localScale = Vector3.one;
            go.transform.position = Vector3.zero;
            go.transform.rotation = Quaternion.identity;
        }
        if (ActionSystem)
        {
            GameObject go = GameObject.Instantiate(ActionSystem);
            go.name = "ActionSystem";
            go.transform.localScale = Vector3.one;
            go.transform.position = Vector3.zero;
            go.transform.rotation = Quaternion.identity;
        }
    }

    //[适配] Root Canvas
    public static void ModifyRootCanvas(Canvas rootCanvas)
    {
        //适配Canvas
        rootCanvas.renderMode = RenderMode.WorldSpace;
        RectTransform rt = rootCanvas.GetComponent<RectTransform>();
        //z值调整界面远近
        rt.anchoredPosition3D = new Vector3(0, 0, 1.7f);
        //设置成开发分辨率
        rt.sizeDelta = new Vector2(1920, 1080);
        rt.pivot = new Vector2(0.5f, 0.5f);
        //rt.localScale = new Vector3(0.001f, 0.001f, 0.001f);
        rt.localScale = new Vector3(0.0005f, 0.0005f, 0.0005f);
    }

    //[适配] 移除主摄像机
    public static void RemoveMainCamera()
    {
        GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
        if (mainCamera)
            mainCamera.SetActive(false);
        GameObject.Destroy(mainCamera);
    }
}


标签: Unity3d

Powered by emlog  蜀ICP备18021003号   sitemap

川公网安备 51019002001593号