コード例 #1
0
    // invoked by the model-toggle
    public void ModelToggleSelected(bool bOn)
    {
        if (bIntAction || !modelTransform || !arManager)
        {
            return;
        }

        if (bOn)
        {
            if (anchorTransform && anchorTransform.gameObject.activeSelf)
            {
                // set model at anchor's position
                SetModelWorldPos(anchorTransform.position, !verticalModel ? anchorTransform.rotation : Quaternion.identity);
            }
            else
            {
                // raycast from center of the screen
                //Vector2 screenPos = new Vector2(Screen.width / 2f, Screen.height / 2f);
                MultiARInterop.TrackableHit hit;
                if (arManager.RaycastToWorld(false, out hit))
                {
                    // set model position
                    SetModelWorldPos(hit.point, !verticalModel ? hit.rotation : Quaternion.identity);
                }
            }

            // attach to existing anchor, if needed
            if (arManager.IsValidAnchorId(anchorId))
            {
                arManager.AttachObjectToAnchor(modelTransform.gameObject, anchorId, false, false);
            }
        }
        else
        {
            // detach from the anchor, if needed
            if (arManager.IsValidAnchorId(anchorId))
            {
                anchorId = arManager.DetachObjectFromAnchor(modelTransform.gameObject, anchorId, false, false);
            }

            // deactivate the model if needed
            if (modelTransform.gameObject.activeSelf)
            {
                modelTransform.gameObject.SetActive(false);
            }
        }
    }