private void MoveSelectedUnits() { if (RaycastHelper.TryGetHitInfoForMousePosition(out var hitInfo, LevelObjectTag.Ground.ToString())) { if (player.SelectedUnits.Count == 0) { return; } var unitsPlace = UnitsPlacementHelpert.PlaceUnits(CalculateApproximateCenterOfSelectedUnits(), hitInfo.point, player.SelectedUnits.Count, gameDefinitions.UnitsDefinitions.MaxUnitsInRow, player.SelectedUnits[0].Get <UnitComponent>().Object.transform.lossyScale.x); for (var i = 0; i < player.SelectedUnits.Count; i++) { MoveHelper.CreateMoveEvent(player.SelectedUnits[i], unitsPlace[i]); } } else { foreach (var unit in player.SelectedUnits) { var unitTarget = RaycastHelper.GetUnitEntityByRaycastHit(hitInfo, units.Entities); if (unitTarget.IsNull()) { break; } FollowHelper.CreateFollowEvent(unit, unitTarget); } foreach (var unit in player.SelectedUnits) { var unitTarget = RaycastHelper.GetBuildingEntityByRaycastHit(hitInfo, builds.Entities); if (unitTarget.IsNull()) { break; } FollowHelper.CreateFollowEvent(unit, unitTarget); } } }
private void HandleSelection() { selectedUnits = selectedUnits.Where(u => u.IsNotNullAndAlive()).ToList(); player.SelectedUnits = player.SelectedUnits.Where(u => u.IsNotNullAndAlive()).ToList(); if (Input.GetMouseButtonDown((int)MouseButton.LeftMouse)) { mouseStartPosition = Input.mousePosition; } if (Input.GetMouseButton((int)MouseButton.LeftMouse)) { selectedUnits.DehighlightObjects(); selectedUnits.Clear(); mouseEndPosition = Input.mousePosition; selectionRectangle.UpdateSelectionRectangle(mouseStartPosition, mouseEndPosition); selectedUnits = selectionRectangle.GetUnitsInFrame( mouseStartPosition, mouseEndPosition, myUnits.Entities.Take(myUnits.GetEntitiesCount())); selectedUnits.HighlightObjects(); } if (Input.GetMouseButtonUp((int)MouseButton.LeftMouse)) { if (RaycastHelper.TryGetHitInfoForMousePosition(out var hitInfoUnit, UnitTag.Warrior.ToString())) { var selectedUnit = RaycastHelper.GetUnitEntityByRaycastHit(hitInfoUnit, myUnits.Entities); selectedUnits.Add(selectedUnit); } else if (RaycastHelper.TryGetHitInfoForMousePosition(out var hitInfoDeliver, UnitTag.Runner.ToString())) { var selectedUnit = RaycastHelper.GetUnitEntityByRaycastHit(hitInfoDeliver, myUnits.Entities); selectedUnits.Add(selectedUnit); } player.SelectedUnits = selectedUnits; selectedUnits.HighlightObjects(); } }