Ejemplo n.º 1
0
        public Dictionary <string, Waypoint> waypointsDict; // Collection of the waypoints in this drone's path

        /// <summary>
        /// Constructor method for Drone class objects
        /// </summary>
        /// <param name="drone_obj"> We pass in a Gameobject for the drone -- this will be phased out and the new drone_obj gameObject will be instantiated in this method </param>
        public Drone(Vector3 position)
        {
            // Create gameObject at position
            GameObject baseObject = (GameObject)WorldProperties.worldObject.GetComponent <WorldProperties>().droneBaseObject;

            gameObjectPointer = Object.Instantiate(baseObject, position, Quaternion.identity);
            gameObjectPointer.GetComponent <DroneProperties>().classPointer = this; // Connect the gameObject back to the classObject
            gameObjectPointer.tag  = "Drone";
            gameObjectPointer.name = baseObject.name;
            gameObjectPointer.transform.localScale = WorldProperties.actualScale / 5;
            gameObjectPointer.transform.parent     = WorldProperties.worldObject.transform;
            WorldProperties.AddClipShader(gameObjectPointer.transform);

            // Initialize path and placement order lists
            waypoints      = new ArrayList(0);
            waypointsOrder = new ArrayList(0);

            // Add waypoints container
            nextWaypointId = 0;
            waypointsDict  = new Dictionary <string, Waypoint>();

            // Updating the world properties to reflect a new drone being added
            id = WorldProperties.nextDroneId;
            WorldProperties.dronesDict.Add(id, this);
            WorldProperties.nextDroneId++;

            // Select this drone
            this.Select();

            Debug.Log("Created new drone with id: " + id);
        }
        public Waypoint nextPathPoint; // Refers to next waypoint

        /// <summary>
        /// Waypoint class object constructor
        /// </summary>
        /// <param name="myDrone"> This is the drone that the new waypoint should belong to (remember that you still need to add the waypoint to the path using this drone's methods) </param>
        /// <param name="position"> This is the 3d location at which the new waypoint gameObject should be placed. </param>
        public Waypoint(Drone myDrone, Vector3 position)
        {
            // Linking this waypoint to its drone
            referenceDrone = myDrone;

            // Setting up all the related gameObject parameters
            GameObject baseObject = (GameObject)WorldProperties.worldObject.GetComponent <WorldProperties>().waypointBaseObject;

            gameObjectPointer = Object.Instantiate(baseObject, position, Quaternion.identity);
            gameObjectPointer.GetComponent <VRTK_InteractableObject>().ignoredColliders[0] = GameObject.Find("controller_right").GetComponent <SphereCollider>(); //Ignoring Collider from Controller so that WayPoint Zone is used
            gameObjectPointer.GetComponent <WaypointProperties>().classPointer             = this;                                                                // Connect the gameObject back to the classObject
            gameObjectPointer.tag  = "waypoint";
            gameObjectPointer.name = baseObject.name;
            gameObjectPointer.transform.localScale = WorldProperties.actualScale / 100;
            gameObjectPointer.transform.parent     = WorldProperties.worldObject.transform;
            WorldProperties.AddClipShader(gameObjectPointer.transform);

            // Initializing the ROSpoints Arraylist
            ROSpoints = new ArrayList(0);

            // Establishing the unique waypoint identifier
            id = "" + referenceDrone.id + referenceDrone.nextWaypointId;
            referenceDrone.nextWaypointId++;

            //Debug.Log("Created new waypoint with id: " + id);
        }
        public WaypointProperties waypointProperties; // Points to attached Waypoint Properties script
        /// <summary>
        /// Waypoint class object constructor
        /// </summary>
        /// <param name="myDrone"> This is the drone that the new waypoint should belong to (remember that you still need to add the waypoint to the path using this drone's methods) </param>
        /// <param name="position"> This is the 3d location at which the new waypoint gameObject should be placed. </param>
        public Waypoint(Drone myDrone, Vector3 position, bool takeoffWaypoint = false)
        {
            // Linking this waypoint to its drone
            referenceDrone = myDrone;

            // Setting up all the related gameObject parameters
            GameObject baseObject = (GameObject)WorldProperties.worldObject.GetComponent <WorldProperties>().waypointBaseObject;

            gameObjectPointer = Object.Instantiate(baseObject, position, Quaternion.identity);
            gameObjectPointer.GetComponent <VRTK_InteractableObject>().ignoredColliders[0] = GameObject.Find("controller_right").GetComponent <SphereCollider>(); //Ignoring Collider from Controller so that WayPoint Zone is used
            waypointProperties = gameObjectPointer.GetComponent <WaypointProperties>();
            waypointProperties.classPointer        = this;                                                                                                        // Connect the gameObject back to the classObject
            gameObjectPointer.tag                  = "waypoint";
            gameObjectPointer.name                 = baseObject.name;
            gameObjectPointer.transform.localScale = WorldProperties.actualScale / 100;
            gameObjectPointer.transform.parent     = WorldProperties.worldObject.transform;
            WorldProperties.AddClipShader(gameObjectPointer.transform);
        }
        /// <summary>
        /// Constructor method for Drone class objects
        /// </summary>
        /// <param name="drone_obj"> We pass in a Gameobject for the drone -- this will be phased out and the new drone_obj gameObject will be instantiated in this method </param>
        public Drone(Vector3 position, int uniqueID)
        {
            // Create gameObject at position
            GameObject baseObject = (GameObject)WorldProperties.worldObject.GetComponent <WorldProperties>().droneBaseObject;

            gameObjectPointer = Object.Instantiate(baseObject, position, Quaternion.identity);

            Debug.Log("Position init: " + position.ToString());
            droneProperties                      = gameObjectPointer.GetComponent <DroneProperties>();
            droneProperties.enabled              = true;
            droneProperties.droneClassPointer    = this; // Connect the gameObject back to the classObject
            droneProperties.selectedMeshRenderer = gameObjectPointer.transform.Find("group3/Outline").GetComponent <MeshRenderer>();

            gameObjectPointer.tag  = "Drone";
            gameObjectPointer.name = baseObject.name;
            gameObjectPointer.transform.localScale = WorldProperties.actualScale / 5;
            gameObjectPointer.transform.parent     = WorldProperties.worldObject.transform;

            WorldProperties.AddClipShader(gameObjectPointer.transform);

            // Initialize path and placement order lists
            waypoints        = new List <Waypoint>(); // All waypoints held by the drone
            deletedWaypoints = new List <Waypoint>(); // All waypoints that were deleted, in case the player wants to redo them.

            // Initialize the actions stack.
            actions = new Stack <string>();

            // Updating the world properties to reflect a new drone being added
            id = uniqueID;
            WorldProperties.AddDrone(this);
            Debug.Log("Created new drone with id: " + id);

            // Initilize the sensor list
            // @Jasmine: this is populated by ROS Manager when initilzing the drone and can be used for the UI
            // @Jasmine: feel free to add/remove functionality as needed, it's a very rough structure right now
            attachedSensors = new List <ROSSensorConnectionInterface>();

            // Init as unselected
            gameObjectPointer.transform.Find("group3/Outline").GetComponent <MeshRenderer>().material = droneProperties.deselectedMaterial;
            selected = false;

            Debug.Log("Created new drone with id: " + id);
        }