public MovementOrderTuple(AbstractMovementOrder order, WaypointUI ui) { this.order = order; this.ui = ui; if (order is AutomaticMovementOrder) { (order as AutomaticMovementOrder).UI = ui; } }
//Attempts to find waypoint at specified index WaypointUI FindWaypointByIndex(int m_WaypointID) { //Iterate through every waypoint and check id and compare against given id for (int i = 0; i < waypointList.childCount; i++) { WaypointUI waypoint = waypointList.GetChild(i).GetComponent <WaypointUI>(); if (waypoint.WaypointID == m_WaypointID) { //Return it if found return(waypoint); } } //Print error if not found and return null Debug.LogError("FindWaypointByName: Waypoint ID not found."); return(null); }
//Clears data of waypoint at specified index and removes it from game world. public void RemoveWaypoint(int m_index) { waypoints[m_index].index = 0; waypoints[m_index].bIsEnabled = false; waypoints[m_index].name = ""; waypoints[m_index].location = Vector3.zero; waypoints[m_index].color = Color.black; waypoints[m_index].bIsInUse = false; WaypointUI waypoint = FindWaypointByIndex(m_index); //Null pointer exception check if (waypoint != null) { waypoint.RemoveWaypoint(); } }
MovementOrderTuple MovementOrderToTuple(AbstractMovementOrder order) { WaypointUI ui = SimplePool.Spawn(waypointUI).GetComponent <WaypointUI>(); MovementOrderTuple result; if (order is MoveFaceOrder) { FacingUI facing = SimplePool.Spawn(facingUI).GetComponent <FacingUI>(); result = new MoveFaceOrderTuple(order, ui, facing); facing.Position = order.Position; facing.Direction = (order as MoveFaceOrder).FacingDirection; } else { result = new MovementOrderTuple(order, ui); } ui.Start = movementOrders.Count != 0 ? ui.Start = movementOrders.Last <MovementOrderTuple>().order.Position : (Vector2)(this.transform.position); ui.End = order.Position; return(result); }
public void Rearrange(bool m_bIsDown, int m_WaypointID) { //Get index at waypoint id WaypointUI waypoint = FindWaypointByIndex(m_WaypointID); //Null pointer exception check if (waypoint != null) { if (m_bIsDown) { //Move sibling index up one for ui and manager child waypointManagerContent.transform.GetChild(waypoint.transform.GetSiblingIndex()).SetSiblingIndex(waypoint.transform.GetSiblingIndex() + 1); waypoint.transform.SetSiblingIndex(waypoint.transform.GetSiblingIndex() + 1); } else { //Move sibling index down one for ui and manager child waypointManagerContent.transform.GetChild(waypoint.transform.GetSiblingIndex()).SetSiblingIndex(waypoint.transform.GetSiblingIndex() - 1); waypoint.transform.SetSiblingIndex(waypoint.transform.GetSiblingIndex() - 1); } } }
//Adds waypoint with specified parameters public void AddWaypoint(string m_name, Vector3 m_location, Color m_color, bool bIsEnabled) { //Keeps track of current iteration in foreach loop int iteration = 0; bool bHasFilled = false; //Loops through each waypoint space to check for next available one. foreach (Waypoint i in waypoints) { //Checks whether the space is free for a waypoint in menu if (i.bIsEnabled == false) { bHasFilled = true; //Sets variables for waypoint waypoints[iteration].index = iteration; waypoints[iteration].bIsEnabled = bIsEnabled; waypoints[iteration].color = m_color; waypoints[iteration].location = m_location; waypoints[iteration].name = m_name; waypoints[iteration].bIsInUse = true; //Spawns new waypoint in menu and in world GameObject go_waypoint = Instantiate(waypointPrefab, pc.transform.position, transform.rotation, transform.root.GetChild(2)); WaypointUI waypoint = go_waypoint.GetComponent <WaypointUI>(); waypoint.SetWaypointSettings(iteration, bIsEnabled, m_name, m_location, m_color); //Breaks out of loop break; } //Increases which element we are on. iteration++; } //Checks whether a space was actually able to be filled and prints out if not. if (bHasFilled == false) { print("All waypoint slots taken."); } }
public MoveFaceOrderTuple(AbstractMovementOrder order, WaypointUI ui, FacingUI facingUI) : base(order, ui) { this.facingUI = facingUI; }