//called if an object is grabbed
        void Grabbed(object sender, InteractableObjectEventArgs e)
        {
            Debug.Log("VRTK Waypoint Grabber Function called");

            // update the waypoint status
            prevWaypointStatus = waypointStatus;
            waypointStatus     = WaypointStatus.GRABBED;

            // change the color to grabbed
            this.GetComponent <MeshRenderer>().material = touchedWaypoint;

            if (classPointer.prevPathPoint != null)
            {
                prevPoint = classPointer.prevPathPoint.gameObjectPointer;
            }

            // Check to see if there exists a next waypoint, and update the nextPoint variable accordingly.
            // If there exists a next waypoint, then its line will also be updated by the updateLine coroutine.
            if (classPointer.nextPathPoint != null)
            {
                nextPoint = classPointer.nextPathPoint;
            }

            // Start updating the line renderer.
            StartCoroutine(updateLine());
        }
        void Start()
        {
            controller         = GameObject.Find("Controller");
            waypointStatus     = WaypointStatus.STATIC;
            prevWaypointStatus = WaypointStatus.STATIC;

            referenceDrone           = classPointer.referenceDrone;
            referenceDroneGameObject = referenceDrone.gameObjectPointer;

            World             = GameObject.FindGameObjectWithTag("World");
            WorldScaleInitial = World.transform.localScale;
            controller_right  = GameObject.Find("controller_right");

            if (classPointer.prevPathPoint != null)
            {
                lineCollider           = new GameObject("Line Collider").AddComponent <CapsuleCollider>();
                lineCollider.tag       = "Line Collider";
                lineCollider.isTrigger = true;
                lineCollider.radius    = 0.1f;
                lineCollider.gameObject.AddComponent <LineProperties>().originWaypoint = classPointer;
                lineCollider.transform.parent = this.gameObject.transform;

                // Establishing the previous point in the path. (Null if it is the drone)
                prevPoint = classPointer.prevPathPoint.gameObjectPointer;

                // Create the collider around the line renderer
                SetLineCollider();
            }
            else
            {
                prevPoint = null;
            }

            // Sets up interaction events
            GetComponent <VRTK_InteractableObject>().InteractableObjectUngrabbed += new InteractableObjectEventHandler(InteractableObjectUngrabbed);
            GetComponent <VRTK_InteractableObject>().InteractableObjectGrabbed   += new InteractableObjectEventHandler(Grabbed);

            //Trying to fix first initial waypoint
            Debug.Log("Init first line");
            SetPassedState();

            //static coloring
            this.GetComponent <MeshRenderer>().material = unpassedWaypoint;
            if (referenceDrone.selected)
            {
                LineProperties.material = selectedUnpassedLine;
            }
            else
            {
                LineProperties.material = unselectedUnpassedLine;
            }

            //if needed will input again;
            //ChangeColor();

            StartCoroutine(updateLine());
            StopCoroutine(updateLine());
        }
 // Sets this waypoint's passed state
 public void SetPassedState()
 {
     if (waypointStatus != WaypointStatus.PASSED && Vector3.Distance(referenceDroneGameObject.transform.localPosition, this.transform.localPosition) < 0.1f)
     {
         prevWaypointStatus = waypointStatus;
         waypointStatus     = WaypointStatus.PASSED;
         GetComponent <VRTK_InteractableObject>().isGrabbable = false;
     }
 }
示例#4
0
            public void Init(int startPtIndex)
            {
                int len = WaypointData.Length;

                for (int i = 0; i < len; i++)
                {
                    // Initial distance
                    WaypointData[i] = new WaypointStatus(
                        null, double.PositiveInfinity, InRange.Unknown);
                }

                WaypointData[startPtIndex] = new WaypointStatus(null, 0.0, InRange.Unknown);
            }
 /// <summary>
 /// Unlock the waypoint so it can be edited by the user.
 /// Change the state, color and VRTK grabble state accordingly
 /// </summary>
 public void UnlockWaypoint()
 {
     waypointStatus     = prevWaypointStatus;
     prevWaypointStatus = WaypointStatus.STATIC;
     GetComponent <VRTK_InteractableObject>().isGrabbable = true;
     if (referenceDrone.selected)
     {
         LineProperties.material = selectedUnpassedLine;
     }
     else
     {
         LineProperties.material = unselectedUnpassedLine;
     }
 }
        /// <summary>
        /// Change the state and color of the waypoint to passed.
        /// </summary>
        public void WaypointPassed()
        {
            prevWaypointStatus = waypointStatus;
            waypointStatus     = WaypointStatus.PASSED;

            GetComponent <VRTK_InteractableObject>().isGrabbable = false;
            this.GetComponent <MeshRenderer>().material          = passedWaypoint;

            if (referenceDrone.selected)
            {
                LineProperties.material = selectedPassedLine;
            }
            else
            {
                LineProperties.material = unselectedPassedLine;
            }
        }
        //this is called when the object is ungrabbed (was here before somehow)
        void InteractableObjectUngrabbed(object sender, VRTK.InteractableObjectEventArgs e)
        {
            Debug.Log("VRTK Waypoint UnGrabber Function called");


            //stop coroutine
            StopCoroutine(updateLine());

            //inform the reference drone that the flight path has been changed.
            waypointStatus     = prevWaypointStatus;
            prevWaypointStatus = WaypointStatus.GRABBED;

            // change the color to un grabbed
            this.GetComponent <MeshRenderer>().material = unpassedWaypoint;

            // Trigger UpdateWaypoints call for drone.
            referenceDrone.DronePathUpdated();
        }
        /// <summary>
        /// Change the state and color of the waypoint to indicate that it has been successfully uploaded to the drone.
        /// </summary>
        public void WaypointUploaded()
        {
            if (waypointStatus == WaypointStatus.PASSED)
            {
                Debug.Log("Invalid command. Please check logic.");
            }

            prevWaypointStatus = waypointStatus;
            waypointStatus     = WaypointStatus.UPLOADED;

            this.GetComponent <MeshRenderer>().material = uploadedWaypoint;
            if (referenceDrone.selected)
            {
                LineProperties.material = selectedUnpassedLine;
            }
            else
            {
                LineProperties.material = unselectedUnpassedLine;
            }
        }
        /// <summary>
        /// Lock the waypoint so it cannot be edited by the user.
        /// Change the state, color and VRTK grabable state accordingly
        /// </summary>
        public void LockWaypoint()
        {
            if (waypointStatus == WaypointStatus.PASSED)
            {
                Debug.Log("Invalid command. Please check logic.");
            }

            prevWaypointStatus = waypointStatus;
            waypointStatus     = WaypointStatus.LOCKED;

            GetComponent <VRTK_InteractableObject>().isGrabbable = false;
            this.GetComponent <MeshRenderer>().material          = lockedWaypoint;

            if (referenceDrone.selected)
            {
                LineProperties.material = selectedUnpassedLine;
            }
            else
            {
                LineProperties.material = unselectedUnpassedLine;
            }
        }