public void RegisterSpawnPoint(SpawnPointBehaviour s) { if (!_spawnPointList.Contains(s)) { _spawnPointList.Add(s); } }
/// <summary> /// Purchase units if there is a buy selection. /// </summary> /// <param name="closestSpawn"></param> private void MaybePurchaseGhostUnits(SpawnPointBehaviour closestSpawn) { if (Input.GetMouseButtonUp(0)) { bool noUIcontrolsInUse = EventSystem.current.currentSelectedGameObject == null; if (!noUIcontrolsInUse) { return; } if (_currentBuyTransaction == null) { return; } closestSpawn.BuyPlatoons(_currentBuyTransaction.PreviewPlatoons); if (Input.GetKey(KeyCode.LeftShift)) { // We turned the current ghosts into real units, so: _currentBuyTransaction = _currentBuyTransaction.Clone(); } else { ExitPurchasingMode(); } } }
private void ShowGhostUnitsAndMaybePurchase(RaycastHit terrainHover) { // Show ghost units under mouse: SpawnPointBehaviour closestSpawn = GetClosestSpawn(terrainHover.point); _currentBuyTransaction.PreviewPurchase( terrainHover.point, 2 * terrainHover.point - closestSpawn.transform.position); MaybePurchaseGhostUnits(closestSpawn); }
private SpawnPointBehaviour GetClosestSpawn(Vector3 p) { var pointList = _spawnPointList.Where( x => x.Team == _localPlayer.Team).ToList(); SpawnPointBehaviour go = pointList.First(); float distance = Single.PositiveInfinity; foreach (var s in pointList) { if (Vector3.Distance(p, s.transform.position) < distance) { distance = Vector3.Distance(p, s.transform.position); go = s; } } return(go); }
/// <summary> /// Purchase units if there is a buy selection. /// </summary> /// <param name="closestSpawn"></param> private void MaybePurchaseGhostUnits(SpawnPointBehaviour closestSpawn) { if (Input.GetMouseButtonUp(0)) { bool noUIcontrolsInUse = EventSystem.current.currentSelectedGameObject == null; if (!noUIcontrolsInUse) { return; } if (_currentBuyTransaction == null) { return; } foreach (GhostPlatoonBehaviour ghost in _currentBuyTransaction.PreviewPlatoons) { CommandConnection.Connection.CmdEnqueuePlatoonPurchase( _currentBuyTransaction.Owner.Id, _currentBuyTransaction.Unit.CategoryId, _currentBuyTransaction.Unit.Id, ghost.UnitCount, closestSpawn.Id, ghost.transform.position, ghost.FinalHeading); ghost.Destroy(); } if (Input.GetKey(KeyCode.LeftShift)) { // We turned the current ghosts into real units, so: _currentBuyTransaction = _currentBuyTransaction.Clone(); } else { ExitPurchasingMode(); } } }