/// <summary> /// Creats the UAV's and places them at the location of the tower. /// </summary> private void CreateUAVs() { for (int i = 0; i < numberOfUAVs; ++i) { // Create a UAV through the entity manager. UAVEntity uav = EntityManager.inst.CreateUAV(towerPrefab.transform.position); } }
/// <summary> /// Stops the UAV of ID. /// </summary> /// <param name="ID"></param> /// <returns> Whether or not the uav was able to be stopped. </returns> public bool StopUAV(int ID) { // Stop the UAV through it's AI component. UAVEntity uav = EntityManager.inst.uavs[ID]; uav.ai.StopAndRemoveAllCommands(); uav.physics.desiredSpeed = 0; return(true); }
/// <summary> /// Sends the UAV to the tower until it's connected to the network. /// </summary> /// <param name="uav"></param> /// <returns> Whether or not the uav was able to be sent to the tower. </returns> public bool SendUAVToTower(UAVEntity uav) { // If uav is valid. if (uav == null) { return(false); } // Add AI command through the uav ai component. uav.assignedNode = null; MoveToUntilConnected moveToCommand = new MoveToUntilConnected(uav, towerPrefab.transform.position); uav.ai.SetCommand(moveToCommand); return(true); }
private void Start() { connectedRouters = new Dictionary <int, Router>(); connectedDevices = new Dictionary <int, Device>(); if (entity == null) { entity = GetComponent <UAVEntity>(); } if (name == "Tower") { NetworkManager.inst.tower = this; } ID = NetworkManager.inst.routers.Count; NetworkManager.inst.routers.Add(ID, this); connectionRadius = NetworkManager.inst.connectionRadius; }
/// <summary> /// Creates a entity of type uav at a given position /// </summary> /// <param name="position"></param> /// <returns> The newly created entity. </returns> public UAVEntity CreateUAV(Vector3 atPos) { if (uavPrefab == null) { uavPrefab = Resources.Load("UAV") as GameObject; } GameObject gameObj = Instantiate(uavPrefab, atPos, new Quaternion()); gameObj.transform.parent = uavFolder.transform; UAVEntity uav = gameObj.GetComponent <UAVEntity>(); uav.ai = gameObj.GetComponent <UnitAI>(); uav.physics = gameObj.GetComponent <OrientedPhysics>(); uav.router = gameObj.GetComponent <Router>(); uav.transform.name = "UAV" + uavs.Count; uavs.Add(uav); return(uav); }
/// <summary> /// Decomissions the uav from the network. /// </summary> /// <param name="uav"></param> /// <returns> Whether or not the uav was able to be decomissioned. </returns> public bool DecomissionUAV(Entity uav) { // Make sure UAV is valid if (uav == null) { return(false); } // If UAV is valid update information about the previous node it was assigned to. UAVEntity newUAV = uav as UAVEntity; newUAV.assignedNode = null; NetworkManager.inst.routers.Remove(newUAV.router.GetID()); // Add AI command to the UAV ai component. MoveTo moveToCommand = new MoveTo(uav, new Vector3(towerPrefab.transform.position.x, 0, towerPrefab.transform.position.z)); uav.ai.SetCommand(moveToCommand); uav.ai.rejectInstructions = true; return(true); }
// ---------------------------------------------------- UAV MOVEMENT ---------------------------------------------------------------- // /// <summary> /// Sends the UAV to a node on the configuration map using AI. /// </summary> /// <param name="uav"></param> /// <param name="toNode"></param> /// <returns> Whether or not the node was sucessfully placed on the map. </returns> public bool SendUAV(UAVEntity uav, NodeEntity toNode) { // If uav is not valid if (uav == null) { return(false); } // If destination is not valid if (toNode == null) { return(false); } // Add AI command to the AI of the entity uav.assignedNode = toNode; toNode.assignedUAV = uav; MoveTo moveToCommand = new MoveTo(uav, toNode.transform.position); uav.ai.SetCommand(moveToCommand); return(true); }