コード例 #1
0
    /// <summary>
    /// This method manages user interaction
    /// </summary>
    protected override void ProcessTouch(Touch touch)
    {
        TrackableHit      hit;
        TrackableHitFlags raycastFilter =
            TrackableHitFlags.PlaneWithinPolygon;

        if (ARCoreWorldOriginHelper.Raycast(touch.position.x, touch.position.y,
                                            raycastFilter, out hit))
        {
            m_LastPlacedAnchor = hit.Trackable.CreateAnchor(hit.Pose);
        }

        if (m_LastPlacedAnchor != null)
        {
            if (_CanPlaceFlags())
            {
                mapBuilder.ProcessTouches();
            }
            else if (!m_IsOriginPlaced)
            {
                SetWorldOrigin(m_LastPlacedAnchor.transform);
                _InstantiateAnchor();
                OnAnchorInstantiated();
            }
        }
    }
コード例 #2
0
    protected override void ProcessTouch(Touch touch)
    {
        TrackableHit      hit;
        TrackableHitFlags raycastFilter =
            TrackableHitFlags.PlaneWithinPolygon;

        if (ARCoreWorldOriginHelper.Raycast(touch.position.x, touch.position.y,
                                            raycastFilter, out hit))
        {
            m_LastPlacedAnchor = hit.Trackable.CreateAnchor(hit.Pose);
        }

        if (_CanPlaceFlags())
        {
            ((ClientMapBuilder)mapBuilder).ProcessTouches();
        }
    }
コード例 #3
0
    protected override void OnEndManipulation(TapGesture gesture)
    {
        //_ShowAndroidToastMessage("END");
        _UpdateApplicationLifecycle();
        if (gesture.WasCancelled)
        {
            return;
        }

        // If gesture is targeting an existing object we are done.
        if (gesture.TargetObject != null)
        {
            _ShowAndroidToastMessage("target Not Null onEnd");
            return;
        }

        // If selection panel is on we are done
        if (selectionCanvas.GetComponent <selectScreenToggle>().toggs)
        {
            return;
        }
        // If we are neither in hosting nor resolving mode then the update is complete.
        if (m_CurrentMode == ApplicationMode.Ready)
        {
            if (PhotonNetwork.IsMasterClient)
            {
                m_CurrentMode = ApplicationMode.Hosting;
                _ShowAndroidToastMessage("Hello Master");
                //  hostSet = true;
            }
            else
            {
                m_CurrentMode = ApplicationMode.Resolving;
                _ShowAndroidToastMessage("Hello Slave");
            }
            //  return;
        }

        // If the origin anchor has not been placed yet, then update in resolving mode is
        // complete.
        if (m_CurrentMode == ApplicationMode.Resolving && !m_IsOriginPlaced)
        {
            return;
        }

        //We don't need it because we already have touch data under gesture class
        //// If the player has not touched the screen then the update is complete.
        //Touch touch;
        //if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
        //{
        //    return;
        //}

        TrackableHit arcoreHitResult = new TrackableHit();

        m_LastHitPose = null;

        // Raycast against the location the player touched to search for planes.
        if (ARCoreWorldOriginHelper.Raycast(gesture.StartPosition.x, gesture.StartPosition.y,
                                            TrackableHitFlags.PlaneWithinPolygon, out arcoreHitResult))
        {
            m_LastHitPose = arcoreHitResult.Pose;
        }
        //    if (hostSet)



        // If there was an anchor placed, then instantiate the corresponding object.
        if (m_LastHitPose != null)
        {
            // The first touch on the Hosting mode will instantiate the origin anchor. Any
            // subsequent touch will instantiate a star, both in Hosting and Resolving modes.
            if ((arcoreHitResult.Trackable is DetectedPlane) &&
                Vector3.Dot(FirstPersonCamera.transform.position - arcoreHitResult.Pose.position,
                            arcoreHitResult.Pose.rotation * Vector3.up) < 0)
            {
                _ShowAndroidToastMessage("Hit at back of the current DetectedPlane");
            }

            else
            {
                if (_CanPlaceStars())
                {
                    string s;
                    int    sel = selectionCanvas.GetComponent <selectScreenToggle>().selec;
                    if (sel == 1)
                    {
                        s = "armChairM1";
                    }
                    else if (sel == 2)
                    {
                        s = "armChairM2";
                    }
                    else if (sel == 3)
                    {
                        s = "coffeeTableM";
                    }
                    else if (sel == 4)
                    {
                        s = "couchM";
                    }
                    else
                    {
                        s = "AllForOne";
                        _ShowAndroidToastMessage("Selection Error");
                    }
                    if (selectionCanvas.GetComponent <selectScreenToggle>().justSelec)
                    {
                        var allForOneObj = PhotonNetwork.Instantiate(s, m_LastHitPose.Value.position, m_LastHitPose.Value.rotation);
                        //  _ShowAndroidToastMessage("instantiation succesful of"+s);
                        var localAnchor = arcoreHitResult.Trackable.CreateAnchor(arcoreHitResult.Pose);
                        //ctr++;
                        //allForOneObj.name = (string)("spawnable "+(char)ctr);
                        allForOneObj.transform.parent = localAnchor.transform;
                        //manipulator.transform.parent = localAnchor.transform;
                        allForOneObj.GetComponent <Manipulator>().Select();
                        //manipulator.GetComponent<Manipulator>().Select();
                        //_ShowAndroidToastMessage(s);
                        selectionCanvas.GetComponent <selectScreenToggle>().justSelec = false;
                    }
                }
                else if (!m_IsOriginPlaced && m_CurrentMode == ApplicationMode.Hosting)
                {
                    m_WorldOriginAnchor = arcoreHitResult.Trackable.CreateAnchor(arcoreHitResult.Pose);
                    SetWorldOrigin(m_WorldOriginAnchor.transform);
                    _InstantiateAnchor();
                }
            }
        }
    }
コード例 #4
0
    /// <summary>
    /// The Unity Update() method.
    /// </summary>
    public void Update()
    {
        _UpdateApplicationLifecycle();

        // If we are neither in hosting nor resolving mode then the update is complete.
        if (m_CurrentMode != ApplicationMode.Hosting &&
            m_CurrentMode != ApplicationMode.Resolving)
        {
            return;
        }

        // If the origin anchor has not been placed yet, then update in resolving mode is
        // complete.
        if (m_CurrentMode == ApplicationMode.Resolving && !m_IsOriginPlaced)
        {
            return;
        }

        // If the player has not touched the screen then the update is complete.
        Touch touch;

        if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
        {
            return;
        }

        TrackableHit arcoreHitResult = new TrackableHit();

        m_LastHitPose = null;

        // Raycast against the location the player touched to search for planes.
        if (Application.platform != RuntimePlatform.IPhonePlayer)
        {
            if (arCoreWorldOriginHelper.Raycast(touch.position.x, touch.position.y,
                                                TrackableHitFlags.PlaneWithinPolygon, out arcoreHitResult))
            {
                m_LastHitPose = arcoreHitResult.Pose;
            }
        }
        else
        {
            Pose hitPose;
            if (m_ARKitHelper.RaycastPlane(
                    arKitFirstPersonCamera, touch.position.x, touch.position.y, out hitPose))
            {
                m_LastHitPose = hitPose;
            }
        }

        // If there was an anchor placed, then instantiate the corresponding object.
        if (m_LastHitPose != null)
        {
            // The first touch on the Hosting mode will instantiate the origin anchor. Any
            // subsequent touch will instantiate a star, both in Hosting and Resolving modes.
            // if (_CanPlaceStars())
            // {
            //  _InstantiateStar();
            // }
            // else
            if (!m_IsOriginPlaced && m_CurrentMode == ApplicationMode.Hosting)
            {
                if (Application.platform != RuntimePlatform.IPhonePlayer)
                {
                    m_WorldOriginAnchor =
                        arcoreHitResult.Trackable.CreateAnchor(arcoreHitResult.Pose);
                }
                else
                {
                    m_WorldOriginAnchor = m_ARKitHelper.CreateAnchor(m_LastHitPose.Value);
                }

                SetWorldOrigin(m_WorldOriginAnchor.transform);
                _InstantiateAnchor();
                OnAnchorInstantiated(true);
            }
        }
    }