protected new void Update() { if (!mouseOverUI) { if (mouseBehav == MOUSE_ACTION_FORMATION.SELECT) { if (Input.GetMouseButton(0)) { if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>(); if (!selectedUnits.Contains(character)) { character.selected = true; characterWithFocus = character; selectedUnits.Add(character); ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } else { character.selected = false; if (character == characterWithFocus) { characterWithFocus = null; ui.showDebugInfo(false); } selectedUnits.Remove(character); } } } else { foreach (PersonajePlayer person in selectedUnits) { person.selected = false; } selectedUnits.Clear(); RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>(); character.selected = true; characterWithFocus = character; selectedUnits.Add(character); ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } else { if (characterWithFocus != null) { characterWithFocus = null; ui.showDebugInfo(false); } } } } } else if (mouseBehav == MOUSE_ACTION_FORMATION.MOVE) { if (selectedUnits.Count > 0) { if (Input.GetMouseButton(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajeBase personajeObjetivo = hit.collider.gameObject.GetComponent <PersonajeBase>(); foreach (PersonajeBase person in selectedUnits) { if (person.currentFormacion != null) { formaciones.Remove(person.currentFormacion); person.currentFormacion.disband(); } PursueSD pursueSD = new PursueSD(); pursueSD.target = personajeObjetivo; /*person.fake.posicion = hit.point; * person.fake.moveTo(hit.point); * person.fake.innerDetector = person.innerDetector;*/ person.newTask(pursueSD); } } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10)) { foreach (PersonajeBase person in selectedUnits) { if (person.currentFormacion != null && person.currentFormacion.lider != person) { formaciones.Add(person.currentFormacion); person.currentFormacion.disband(); } //person.setAction(new AgentActionMove(new Vector2(hit.point.x, hit.point.z), person.innerDetector, person.outterDetector)); PursueSD pursueSD = new PursueSD(); pursueSD.target = person.fakeMovement; person.fakeMovement.posicion = hit.point; person.fakeMovement.moveTo(hit.point); // mover los fakes para debuggeo person.fakeMovement.innerDetector = person.innerDetector; person.newTask(pursueSD); } } } } } else { if (Input.GetMouseButton(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { foreach (PersonajeBase person in selectedUnits) { if (person.currentFormacion != null) { formaciones.Remove(person.currentFormacion); person.currentFormacion.disband(); } } //Asignamos el lider que clicamos PersonajeBase lider = hit.collider.gameObject.GetComponent <PersonajeBase>(); Formacion formacion = null; if (mouseBehav == MOUSE_ACTION_FORMATION.TRIANGLE_FORMATION) { formacion = new FormacionTriangulo(lider); } else if (mouseBehav == MOUSE_ACTION_FORMATION.SQUARE_FORMATION) { formacion = new FormacionCuadrado(lider); } else if (mouseBehav == MOUSE_ACTION_FORMATION.ROLE_FORMATION) { formacion = new FormacionPorRoles(lider); } foreach (PersonajeBase person in selectedUnits) { person.currentFormacion = formacion; if (person != lider) { formacion.addMiembro(person); } } formacion.formacionASusPuestos(); formaciones.Add(formacion); } } } } }
protected void Update() { //INPUT MANAGEMENT //CAMERA INPUT HERE (AROUND THE MAP) if (!mouseOverUI) { if (mouseBehav == MOUSE_ACTION.SELECT) { if (Input.GetMouseButton(0)) { if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>(); if (!selectedUnits.Contains(character)) { character.selected = true; characterWithFocus = character; selectedUnits.Add(character); ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } else { character.selected = false; if (character == characterWithFocus) { characterWithFocus = null; ui.showDebugInfo(false); } selectedUnits.Remove(character); } } ui.actualizeUserButtons(allPossibleActions()); } else { foreach (PersonajePlayer person in selectedUnits) { person.selected = false; } selectedUnits.Clear(); RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>(); character.selected = true; characterWithFocus = character; selectedUnits.Add(character); ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } else { if (characterWithFocus != null) { characterWithFocus = null; ui.showDebugInfo(false); } } ui.actualizeUserButtons(allPossibleActions()); } } } else if (mouseBehav == MOUSE_ACTION.MOVE) { if (selectedUnits.Count > 0) { if (Input.GetMouseButton(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajeBase personajeObjetivo = hit.collider.gameObject.GetComponent <PersonajeBase>(); foreach (PersonajeBase person in selectedUnits) { if (person.currentFormacion != null && person.currentFormacion.lider != person) { formaciones.Remove(person.currentFormacion); person.currentFormacion.disband(); } PursueSD pursueSD = new PursueSD(); pursueSD.target = personajeObjetivo; /*person.fake.posicion = hit.point; * person.fake.moveTo(hit.point); * person.fake.innerDetector = person.innerDetector;*/ person.newTask(pursueSD); } } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10)) { foreach (PersonajeBase person in selectedUnits) { if (person.currentFormacion != null && person.currentFormacion.lider != person) { formaciones.Remove(person.currentFormacion); person.currentFormacion.disband(); } PursueSD pursueSD = new PursueSD(); pursueSD.target = person.fakeMovement; person.fakeMovement.posicion = hit.point; person.fakeMovement.moveTo(hit.point); // mover los fakes para debuggeo person.fakeMovement.innerDetector = person.innerDetector; person.newTask(pursueSD); } } } } } else if (mouseBehav == MOUSE_ACTION.FORM_T || mouseBehav == MOUSE_ACTION.FORM_S || mouseBehav == MOUSE_ACTION.FORM_R) { if (selectedUnits.Count > 0) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { // PARA FORMACIONES foreach (PersonajeBase person in selectedUnits) { if (person.currentFormacion != null) { formaciones.Add(person.currentFormacion); person.currentFormacion.disband(); } } //Asignamos el lider que clicamos PersonajeBase lider = hit.collider.gameObject.GetComponent <PersonajeBase>(); Formacion formacion = null; switch (mouseBehav) { case MOUSE_ACTION.FORM_T: formacion = new FormacionTriangulo(lider); break; case MOUSE_ACTION.FORM_S: formacion = new FormacionCuadrado(lider); break; case MOUSE_ACTION.FORM_R: formacion = new FormacionPorRoles(lider); break; } foreach (PersonajeBase person in selectedUnits) { person.currentFormacion = formacion; if (person != lider) { formacion.addMiembro(person); } } formacion.formacionASusPuestos(); formaciones.Add(formacion); //PARA FLOCKING /*PersonajeBase lider = hit.collider.gameObject.GetComponent<PersonajeBase>(); * foreach (PersonajeBase person in selectedUnits) * { * if (person!= lider) * { * FlockingSD flocking = new FlockingSD(1,1,1); * flocking.target = lider; * person.newTask(flocking); * } * }*/ } } } } else if (mouseBehav == MOUSE_ACTION.ROUTE_SET) { if (selectedUnits.Count > 0) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 11)) { setRouteOnUnits(); pathToSet.Clear(); setMouseBehaviour(0); ui.selectMouseOption(0); /*foreach (PersonajeBase person in selectedUnits) * { * if (person.currentFormacion != null) * { * formationManager.removeFormacion(person.currentFormacion); * person.currentFormacion.disband(); * } * }*/ } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10)) { if (pathToSet.Count == 0) { foreach (PersonajeBase unit in selectedUnits) { foreach (Transform routeElem in unit.routeMarks) { Destroy(routeElem.gameObject); } } } pathToSet.Add(hit.point); foreach (PersonajeBase unit in selectedUnits) { GameObject routeMark = Instantiate(routeMarkPrefab, unit.routeMarks); routeMark.transform.position = new Vector3(hit.point.x, 0.05f, hit.point.z); if (pathToSet.Count > 1) { GameObject routeLine = Instantiate(routeLinePrefab, unit.routeMarks); routeLine.GetComponent <FlechaDeRutaDelegate>().setRouteDirection(pathToSet[pathToSet.Count - 2], pathToSet[pathToSet.Count - 1]); } } } } } } } }