public void Update()
        {
            // if mouse button 0 was clicked
            if (Input.touchCount > 0 && isSetupPhase)
            {
                // figure out where we touched
                Touch touch = Input.GetTouch(0);
                if (touch.phase == TouchPhase.Ended)
                {
                    Vector2 screenPoint = Camera.main.ScreenToViewportPoint(touch.position);
                    ARPoint point       = new ARPoint()
                    {
                        x = screenPoint.x, y = screenPoint.y
                    };

                    // notify the WAREngine that a touch start event occured
                    TriggerPointEvent("TouchStart", touch.position);

                    // find all hitResults of type ExistingPlane
                    List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(
                        point, ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent
                        );
                    // if we hit something
                    if (hitResults.Count > 0)
                    {
                        Ray        ray = Camera.main.ScreenPointToRay(touch.position);
                        RaycastHit hit;
                        if (Physics.Raycast(ray, out hit, 10.0f))
                        {
                            // find the object we hit
                            GameObject go = hit.collider.gameObject;

                            // pack the values pertaining to a plane into a container and trigger InitBoard
                            UIInput.InitBoard(new UIPlane {
                                center   = go.transform.position,
                                extent   = go.transform.localScale * 10,
                                rotation = go.transform.rotation
                            });

                            // and stop trying to place a table
                            isSetupPhase = false;

                            // we are done looking for anchors so we will not attach a collideable game obect to our anchors
                            UnityARUtility.InitializePlanePrefab(new GameObject());
                            // clear the current set of planes and their anchor data
                            unityARAnchorManager.Destroy();
                        }
                    }
                }
            }
        }
示例#2
0
        void TriggerInitializeBoard(UIPlane plane)
        {
            // don't do anything on a single click
            if (plane.extent.magnitude < 0.1f)
            {
                return;
            }
            // get the rotation of our plane
            Quaternion rotation = new Quaternion(0f, Camera.main.transform.rotation.y, 0f, 1f);

            // trigger an initializeBoard event with our center and extent
            // pack the values pertaining to a plane into a container to publish with our InitializeBoard msg
            UpdatePlane(plane.start, plane.end, 300f);
            UIInput.InitBoard(new UIPlane(start: plane.start, end: plane.end, rotation: rotation));
        }
示例#3
0
        void TriggerInitializeBoard(Vector2 mouseClickEnd)
        {
            Ray   startRay    = Camera.main.ScreenPointToRay(mouseClickStart);
            Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
            float toPlane;

            if (groundPlane.Raycast(startRay, out toPlane))
            {
                Ray   stopRay = Camera.main.ScreenPointToRay(mouseClickEnd);
                float toPlaneEnd;
                if (groundPlane.Raycast(stopRay, out toPlaneEnd))
                {
                    // find the bounds of the plane
                    Vector3 planeStart = startRay.direction * toPlane + startRay.origin;
                    Vector3 planeEnd   = stopRay.direction * toPlaneEnd + stopRay.origin;
                    // find center point between planeStart and planeEnd
                    Vector3 center = (planeStart + planeEnd) / 2;
                    // extent of our plane is distance from center point to planeStart/End
                    Vector3 extent = 2 * (planeEnd - center);
                    // if we didn't drag a plane
                    if (extent.magnitude < 0.01f)
                    {
                        // don't do anything
                        return;
                    }
                    Vector3 extentAbs = new Vector3(Mathf.Abs(extent.z), Mathf.Abs(extent.y), Mathf.Abs(extent.x));
                    // get the rotation of our plane
                    Quaternion rotation = new Quaternion(Vector3.up.x, Vector3.up.y, Vector3.up.z, -1.0f);
                    // trigger an initializeBoard event with our center and extent
                    // pack the values pertaining to a plane into a container to publish with our InitializeBoard msg
                    UIInput.InitBoard(new UIPlane {
                        center = center, extent = extentAbs, rotation = rotation
                    });
                }
            }
        }