private void RightMouseClicked() { Ray ray = _camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000)) { WaypointMarker marker = hit.collider.GetComponent <WaypointMarker>(); if (marker != null) { if (RobotMasterController.SelectedRobot != null) { if (RobotMasterController.SelectedRobot.CurrenLocomotionType == ROSController.RobotLocomotionType.DIRECT || RobotMasterController.SelectedRobot.CurrentRobotLocomotionState == ROSController.RobotLocomotionState.STOPPED) { WaypointController.Instance.ClickedWaypointMarker(marker); } } else { WaypointController.Instance.ClickedWaypointMarker(marker); } } } }
/*private void AddWaypointToMoveWrapperAtPosition(OrderWrapper ow, Vector3 pos) * { * WaypointMarker wpmrk = WaypointMarker.CreateInstance(pos); * ow.GetWrappedAs<MoveOrder>().AddWaypoint(wpmrk.GetMyWrapper<WaypointMarker>()); * //ow.GetWrappedAs<MoveOrderFormation>().AddWaypoint(wpmrk.GetMyWrapper<WaypointMarker>()); * }*/ private void AddWaypointToMoveWrapperAtPosition(TaskWrapper ow, Vector3 pos) { WaypointMarker wpmrk = WaypointMarker.CreateInstance(pos); ow.GetCastReference <MoveTask>().AddWaypoint(wpmrk.GetRefWrapper()); //ow.GetWrappedAs<MoveOrderFormation>().AddWaypoint(wpmrk.GetMyWrapper<WaypointMarker>()); }
private void EditWaypointMarkerControl() { if (Input.GetMouseButtonDown(0)) { if (_editedWaypointMarkerWrapper != null) { WaypointMarker.UpdateWaypointMarker(_editedWaypointMarkerWrapper, false, pointerInfo.pointedPositionScreen); _editedWaypointMarkerWrapper = null; } else if (_editedWaypointMarkerWrapper == null) { var ewp = GetUICloseToScreenPosition <WaypointMarker>(GetMyCamera(), pointerInfo.pointedPositionScreen, 7f); if (ewp != null) { _editedWaypointMarkerWrapper = ewp.GetRefWrapper(); } else if (NoUIAtScreenPositionExceptCanvas(pointerInfo.pointedPositionScreen, 0)) { } } } if (_editedWaypointMarkerWrapper != null && _editedWaypointMarkerWrapper.GetWrappedReference() != null) { WaypointMarker.UpdateWaypointMarker(_editedWaypointMarkerWrapper, true, pointerInfo.pointedPositionScreen); } }
void Update() { if (!WaypointMarker.InputFieldFocus()) { InputHandling(); } //if (Input.GetButtonDown(INPUT_LORE) && _book.activeSelf) { CloseBook(); } }
private void LeftMouseClicked() { //Checks if UI was clicked if (EventSystem.current.IsPointerOverGameObject()) { return; } if (_hoveredMouseObject && OnMouseClick == null) { _hoveredMouseObject.Clicked(); return; } Ray ray = _camera.ScreenPointToRay(Input.mousePosition); //If something subscribed to mouse click, redirect if (OnMouseClick != null) { OnMouseClick(ray); return; } RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000)) { WaypointMarker marker = hit.collider.GetComponent <WaypointMarker>(); if (marker != null) { if (RobotMasterController.SelectedRobot != null) { if (RobotMasterController.SelectedRobot.CurrenLocomotionType == ROSController.RobotLocomotionType.DIRECT || RobotMasterController.SelectedRobot.CurrentRobotLocomotionState == ROSController.RobotLocomotionState.STOPPED) { WaypointController.Instance.DeleteMarker(marker); } } else { WaypointController.Instance.DeleteMarker(marker); } return; } if (hit.collider.gameObject.layer != LayerMask.NameToLayer("Floor")) { return; } if (RobotMasterController.SelectedRobot != null) { if (RobotMasterController.SelectedRobot.CurrenLocomotionType == ROSController.RobotLocomotionType.DIRECT || RobotMasterController.SelectedRobot.CurrentRobotLocomotionState == ROSController.RobotLocomotionState.STOPPED) { WaypointController.Instance.CreateWaypoint(hit.point); } } } }
public void CreateRoute(List <Waypoint> route) { ClearAllWaypoints(); foreach (Waypoint waypoint in route) { WaypointMarker marker = CreateWaypoint(waypoint.Point.ToUTM().ToUnity()); marker.SetWaypoint(waypoint); } }
public void ClickedWaypointMarker(WaypointMarker marker) { int currentType = (int)marker.Waypoint.ThresholdZone.ThresholdZoneType; currentType++; if (currentType > 3) { currentType = 0; } ThresholdZone newZone = _thresholdZoneDict[(ThresholdZoneType)currentType]; marker.SetThresholdZone(newZone); UpdateMarker(marker); }
private static void AddWaypoint(Vector3 position, string name, MapMarkers type) { //Scale float scale = 1 / _singleton._pivotSpawnContainer.localScale.x * _singleton._waypointSize; Vector3 waypointScale = new Vector3(scale, scale, scale); GameObject newWaypoint = Instantiate(_singleton._waypointPrefab, Vector3.zero, Quaternion.identity, _singleton._waypointContainer); newWaypoint.transform.localPosition = position; newWaypoint.transform.localScale = waypointScale; WaypointMarker script = newWaypoint.GetComponent <WaypointMarker>(); script.Setup(type, name, _singleton._waypointSize); _worldMarkers.Add(position, new WorldMarker(position, true, WaypointMarker.STANDARD_WAYPOINT_NAME, type)); _spawnedWaypoints.Add(newWaypoint.transform); }
public WaypointMarker CreateWaypoint(Vector3 waypointPosition) { foreach (WaypointMarker marker in _waypointMarkers) { marker.SetLock(true); } _lineRendererRoute.positionCount++; _lineRendererRoute.SetPosition(_lineRendererRoute.positionCount - 1, waypointPosition); WaypointMarker waypoint = Instantiate(_waypointMarkerPrefab, waypointPosition, Quaternion.identity).GetComponent <WaypointMarker>(); ThresholdZone zone = _thresholdZoneDict[_defaultZoneType]; waypoint.SetWaypoint(new Waypoint { Point = waypointPosition.ToUTM().ToWGS84(), ThresholdZone = zone }); _waypointMarkers.Add(waypoint); PlayerUIController.Instance.UpdateUI(RobotMasterController.SelectedRobot); return(waypoint); }
public void DeleteMarker(WaypointMarker toDelete) { if (toDelete.IsLocked) { return; } if (_lineRendererRoute.positionCount > 0) { _lineRendererRoute.positionCount--; } Destroy(_waypointMarkers[_waypointMarkers.Count - 1].gameObject); _waypointMarkers.RemoveAt(_waypointMarkers.Count - 1); if (_waypointMarkers.Count == 0) { PlayerUIController.Instance.UpdateUI(RobotMasterController.SelectedRobot); } else if (_waypointMarkers.Count > 0) { _waypointMarkers[_waypointMarkers.Count - 1].SetLock(false); } }
/// <summary> /// Initialize /// </summary> void Start() { this.health = this.maxHealth; this.navMeshAgent = GetComponent <NavMeshAgent>(); this.waypoint = FindObjectOfType <WaypointMarker>(); }
void Awake() { _waypointMarker = transform.parent.GetComponent <WaypointMarker>(); _dragReferencePoint = transform.parent.position; }
protected override void InstanceSetTaskPlan(TaskPlan2 taskPlan) { base.InstanceSetTaskPlan(taskPlan); if (taskPlan != null) { UpdateFormationFacing(unit, GetTaskMarker().GetWorldPosition()); unit.GetFormation().FormTest(); foreach (var subg in actorGroupAsUG.GetSubGroupsAsUG()) { Vector3 wpos; wpos = subg.GetActorsAsUnits()[0].GetFormation().GetAcceptableMovementTargetPosition(GetTaskMarker().GetWorldPosition()); MoveTaskMarker tm = TaskMarker.CreateInstanceAtWorldPosition <MoveTaskMarker>(wpos); tm.AddWaypointMarker(WaypointMarker.CreateWaypointMarker(wpos)); MoveTask chmvt = tm.GetTask() as MoveTask; chmvt.parentActorMoveTask = this; subActorsMoveTasks.Add(subg, chmvt); chmvt.SubscribeOnDestruction("removeparentssubactorsmovetasks", () => subActorsMoveTasks.Remove(subg)); subg.SubscribeOnParentGroupChange("onchangeparentgroup", () => { chmvt.parentActorMoveTask = null; subActorsMoveTasks.Remove(subg); subg.UnsubscribeOnParentGroupChange("onchangeparentgroup"); }); var prevtask = GetTaskPlan().GetTaskInPlanBefore(this) as MoveTask; TaskMarker chprevtm; if (prevtask != null && prevtask.subActorsMoveTasks.ContainsKey(subg)) { chprevtm = prevtask.subActorsMoveTasks[subg].GetTaskMarker(); } else { chprevtm = null; } TaskPlan2 chtp = tm.InsertAssociatedTaskIntoPlan(subg, chprevtm); } /*SubscribeOnDestruction("parentactormovetaskchange", () => * { * foreach (var chmvt in new List<MoveTask>(subActorsMoveTasks.Values)) * { * chmvt.EndExecution(); * chmvt.parentActorMoveTask = null; * } * subActorsMoveTasks.Clear(); * });*/ SetPhase(TaskPhase.Staging); } else { foreach (var chmvt in new List <MoveTask>(subActorsMoveTasks.Values)) { chmvt.EndExecution(); chmvt.parentActorMoveTask = null; } subActorsMoveTasks.Clear(); } }
/*private bool CompatibilityPerActor(IActor actor, Task task) { bool b = true; if (task is MoveTask2) { var mvtsk = task as MoveTask2; var subut = (actor as UnitGroup); //b = !((task.GetAgent() as UnitTeam).GetUnit() == subut.GetUnit() // || mvtsk.agentAsTeam.GetUnits().Where(_ => (_ as UnitTeam).GetUnit() == subut.GetUnit()).Count() > 0); } return b; }*/ protected override void InstanceSetTaskPlan(TaskPlan2 taskPlan) { base.InstanceSetTaskPlan(taskPlan); if (taskPlan != null) { Debug.Log("setting task plan to task"); SubscribeOnDestruction("clearchildrenmovetaskmarkers", () => subActorsMoveTaskMarkers.Clear()); foreach (var u in units) { /*actorGroupAsUG.SubscribeOnUnitRemovalFromGroup(u, _ => { subActorsMoveTaskMarkers.Remove(u); actorGroupAsUG.UnsubscribeOnUnitRemovalFromGroup(_); });*/ //UpdateFormationFacing(u, GetTaskMarker().GetWorldPosition()); //u.GetFormation().FormTest(); } foreach (var subg in actorGroupAsUG.GetSubGroupsAsUG()) { Vector3 wpos; wpos = subg.GetActorsAsUnits()[0].GetFormation().GetParentFormation().GetAcceptableMovementTargetPosition(GetTaskMarker().GetWorldPosition()); var prevtm = GetTaskMarker().GetPreviousTaskMarker()?.GetTask() as MoveTask2; TaskMarker chprevtm; if (prevtm != null) chprevtm = prevtm.subActorsMoveTaskMarkers.FirstOrDefault(_ => (UnitGroup)_.GetTask().GetActorGroup() == subg); else chprevtm = null; MoveTaskMarker tm = TaskMarker.CreateInstanceAtWorldPosition<MoveTaskMarker>(wpos); tm.AddWaypointMarker(WaypointMarker.CreateWaypointMarker(wpos)); TaskPlan2 chtp = tm.InsertAssociatedTaskIntoPlan(subg, chprevtm); tm.SubscribeOnDestruction("removefromparentmovetaskmarkerslist",() => subActorsMoveTaskMarkers.Remove(tm)); subActorsMoveTaskMarkers.Add(tm); } SetPhase(TaskPhase.Staging); } else { subActorsMoveTaskMarkers.Clear(); } if (taskPlan != null) { //AddSubjectAgent(GetAgent()); /*foreach (var sbt in agentAsTeam.GetAllSubTeamsBFS()) { AddSubjectAgent(sbt); }*/ /*foreach (var subAgent in GetSubjectAgents()) { var sbt = subAgent as UnitTeam; if (!sbt.IsVirtualTeam()) sbt.GetUnit().GetFormation().FormTest(); } foreach (var subAgent in GetSubjectAgents()) { Vector3 wpos; wpos = (subAgent as UnitTeam).GetUnit().GetFormation().GetAcceptableMovementTargetPosition(GetTaskMarker().GetWorldPosition()); }*/ //SetPhase(TaskPhase.Staging); } }
public void UpdateMarker(WaypointMarker marker) { _waypointMarkers[_waypointMarkers.IndexOf(marker)].Waypoint = marker.Waypoint; }