コード例 #1
0
 /// <summary>
 /// Function called when the manipulation is continued.
 /// </summary>
 /// <param name="gesture">The current gesture.</param>
 protected virtual void OnContinueManipulation(TapGesture gesture)
 {
     // Optional override.
 }
コード例 #2
0
 /// <summary>
 /// Function called when the manipulation is started.
 /// </summary>
 /// <param name="gesture">The current gesture.</param>
 protected virtual void OnStartManipulation(TapGesture gesture)
 {
     // Optional override.
 }
コード例 #3
0
 /// <summary>
 /// Returns true if the manipulation can be started for the given gesture.
 /// </summary>
 /// <param name="gesture">The current gesture.</param>
 /// <returns>True if the manipulation can be started.</returns>
 protected override bool CanStartManipulationForGesture(TapGesture gesture)
 {
     return(true);
 }
コード例 #4
0
        /// <summary>
        /// Function called when the manipulation is ended.
        /// </summary>
        /// <param name="gesture">The current gesture.</param>
        protected override void OnEndManipulation(TapGesture gesture)
        {
            if (gesture.WasCancelled)
            {
                return;
            }

            // If gesture is targeting an existing object we are done.
            if (gesture.TargetObject != null)
            {
                return;
            }

            // Raycast against the location the player touched to search for planes.
            TrackableHit      hit;
            TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon;

            if (Frame.Raycast(
                    gesture.StartPosition.x, gesture.StartPosition.y, raycastFilter, out hit))
            {
                // Use hit pose and camera pose to check if hittest is from the
                // back of the plane, if it is, no need to create the anchor.
                if ((hit.Trackable is DetectedPlane) &&
                    Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
                                hit.Pose.rotation * Vector3.up) < 0)
                {
                    Debug.Log("Hit at back of the current DetectedPlane");
                }
                else
                {
                    ObjectToPlace = itemManager.ObjectToPlace;

                    // Instantiate model at the hit pose.
                    var modelObject = Instantiate(ObjectToPlace, hit.Pose.position, hit.Pose.rotation);

                    // Instantiate manipulator.
                    var manipulator =
                        Instantiate(ManipulatorPrefab, hit.Pose.position, hit.Pose.rotation);

                    // Make model a child of the manipulator.
                    modelObject.transform.parent = manipulator.transform;

                    // Create an anchor to allow ARCore to track the hitpoint as understanding of
                    // the physical world evolves.
                    var anchor = hit.Trackable.CreateAnchor(hit.Pose);

                    // Make manipulator a child of the anchor.
                    manipulator.transform.parent = anchor.transform;

                    // Select the placed object.
                    manipulator.GetComponent <Manipulator>().Select();

                    //Disable object placement after item placed.
                    GameObject manipulationPanel = GameObject.Find("Controls");
                    manipulationPanel.GetComponent <ManipulationButtons>().togglePlace = false;

                    PlacedObjects.Add(modelObject);
                    GameObject.Find("Controls").GetComponent <ManipulationButtons>().TogglePressedColour();
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Returns true if the manipulation can be started for the given gesture.
 /// </summary>
 /// <param name="gesture">The current gesture.</param>
 /// <returns>True if the manipulation can be started.</returns>
 protected virtual bool CanStartManipulationForGesture(TapGesture gesture)
 {
     return(false);
 }
コード例 #6
0
 private void OnFinished(TapGesture gesture)
 {
     m_IsManipulating = false;
     OnEndManipulation(gesture);
 }