public void Move(PathNodeMain n) { Move(n.transform.position); MovingToVector = false; AIPathFinder.endReachedDistance = TARGET_REACHED_DISTANCE; SelectMoveNode(n); }
public void SetNodes(PathNodeMain node1, PathNodeMain node2) { n1 = node1; n2 = node2; start = n1.transform; end = n2.transform; Update(); }
void SelectMoveNode(PathNodeMain node) { DeselectMoveNode(); move_node = node; move_node.PathNodeMovedEvent += OnPathMoved; move_node.PathNodeNewForwardNodesEvent += OnPathNewNode; move_node.OnPathNodeDestroyedEvent += OnPathDestroyed; }
void DeselectNode() { if (!selected_node) { return; } selected_node.setSelected(false); selected_node = null; }
void DeselectMoveNode() { if (move_node != null) { move_node.PathNodeMovedEvent -= OnPathMoved; move_node.PathNodeNewForwardNodesEvent -= OnPathNewNode; move_node.OnPathNodeDestroyedEvent -= OnPathDestroyed; move_node = null; } }
public void RemoveForwardNode(PathNodeMain node) { /*if (path_lines.ContainsKey(node)){ * Destroy(path_lines[node]); * path_lines.Remove(node); * * }*/ for (int i = 0; i < path_lines.Count; i++) { if (path_lines[i].ForwardNode == node) { Destroy(path_lines[i].gameObject); path_lines.RemoveAt(i); } } forward_nodes.Remove(node); }
public void AddForwardNode(PathNodeMain node) { if (forward_nodes.Contains(node) || backward_nodes.Contains(node)) { return; } forward_nodes.Add(node); node.backward_nodes.Add(this); var o = Instantiate(PathLine_prefab, transform.position, Quaternion.identity) as GameObject; var line = o.GetComponent <PathLineMain>(); line.SetNodes(this, node); path_lines.Add(line); if (PathNodeNewForwardNodesEvent != null) { PathNodeNewForwardNodesEvent(); } }
public void RemoveBackwardNode(PathNodeMain node) { backward_nodes.Remove(node); }
public bool CheckNode(PathNodeMain node) { return(n1 == node || n2 == node); }
// Update is called once per frame void Update() { if (_controlMode == ControlMode.CreatePaths) { if (GroundPosition(out temp_ground_pos)) { selection_circle.transform.position = temp_ground_pos + Vector3.up * 0.1f; } } if (Input.GetKeyDown(KeyCode.Escape)) { Application.LoadLevel("MenuScene"); } if (GAMEOVER) { if (Input.GetKeyDown(KeyCode.R)) { Application.LoadLevel("GameScene"); } return; } //select if (Input.GetButtonUp("Select")) { if (moving_node) { moving_node = false; if (_controlMode == ControlMode.CreatePaths) { selection_circle.gameObject.SetActive(true); } } if (node_pressed) { DeselectNode(); } node_pressed = false; selection_rect_on = false; if (selection_rect_on_legit) { SelectUnits(selection_rect_start_pos, Input.mousePosition); selection_rect_on_legit = false; if (_controlMode == ControlMode.CreatePaths) { selection_circle.gameObject.SetActive(true); } } else if (_controlMode == ControlMode.CreatePaths) { if (can_create_path) { //CreateNodeInMousePos(); } } can_create_path = false; } if (Input.GetButton("Select")) { if (moving_node) //moving node { if (GroundPosition(out temp_ground_pos)) { if (node_pressed) { if (Vector3.Distance( temp_ground_pos, selected_node.transform.position - new Vector3(temp_selection_offset.x, 0, temp_selection_offset.z) ) > 1) { selected_node.Reposition(temp_ground_pos + temp_selection_offset); node_pressed = false; } } else { selected_node.Reposition(temp_ground_pos + temp_selection_offset); } } } else { //start selection rectangle if (!selection_rect_on_legit && selection_rect_on) { if (Vector3.Distance(Input.mousePosition, selection_rect_start_pos) > 10) { selection_rect_on_legit = true; selection_circle.gameObject.SetActive(false); } } } } if (Input.GetButtonDown("Select")) { //check for units var unit = RaycastUnit(); if (unit != null) { SelectUnit(unit); #if UNITY_EDITOR unit.HP -= 10; #endif return; } selection_rect_on = true; selection_rect_start_pos = Input.mousePosition; if (_controlMode == ControlMode.None) { var node = RaycastPathNode(); if (node != null) { SetPathMode(true); SetSelectedNode(node); return; } } if (_controlMode == ControlMode.CreatePaths) { var node = RaycastPathNode(); if (node != null) { moving_node = true; selection_circle.gameObject.SetActive(false); if (selected_node == node) { node_pressed = true; } else { SetSelectedNode(node); DeselectLine(); } if (GroundPosition(out temp_ground_pos)) { temp_selection_offset = node.transform.position - temp_ground_pos; } return; } var line = RaycastPathLine(); if (line != null) { SetSelectedLine(line); DeselectNode(); return; } can_create_path = true; } DeselectUnits(); DeselectLine(); } //control actions if (Input.GetButtonDown("Command")) { if (_controlMode == ControlMode.None) { if (HasSelectedUnits()) { var node = RaycastPathNode(); if (node != null) { foreach (var s in selected_units) { s.Move(node); } } else { if (GroundPosition(out temp_ground_pos)) { foreach (var s in selected_units) { s.Move(temp_ground_pos); } } } } } else if (_controlMode == ControlMode.CreatePaths) { CreateNodeInMousePos(); } } //other #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Alpha1)) { SetMode(ControlMode.None); } if (Input.GetKeyDown(KeyCode.Alpha3)) { if (GroundPosition(out temp_ground_pos)) { var go = Instantiate(Unit_prefab, temp_ground_pos + Vector3.up * 2, Quaternion.identity) as GameObject; AddCar(go.GetComponent <UnitMain>()); } } if (Input.GetKeyDown(KeyCode.Alpha4)) { SetGameover(); } #endif if (Input.GetButtonDown("PathMode")) { TogglePathMode(); } if (Input.GetButtonDown("Remove")) { if (selected_node != null) { PathNodeMain node = null; if (selected_node.HasForwardNodes()) { node = Subs.GetRandom(selected_node.ForwardNodes); } else { if (selected_node.HasBackwardNodes()) { node = Subs.GetRandom(selected_node.BackwardNodes); } } selected_node.Delete(); if (node != null) { SetSelectedNode(node); } } if (selected_line != null) { selected_line.Delete(); } } if (Input.GetKeyDown(KeyCode.Space)) { ToggleTimeState(); } }
void SetSelectedNode(PathNodeMain node) { DeselectNode(); selected_node = node; selected_node.setSelected(true); }