private void Update() { if (!_spawnQueue.Any()) { return; } _spawnTime -= Time.deltaTime; if (_spawnTime > 0) { return; } PlatoonBehaviour previewPlatoon = _spawnQueue.Dequeue(); previewPlatoon.Spawn(transform.position); if (_spawnQueue.Count > 0) { _spawnTime += MIN_SPAWN_INTERVAL; } else { _spawnTime = QUEUE_DELAY; } }
public void DisplayWeapon(PlatoonBehaviour platoon, int weaponId) { _platoon = platoon; _weaponId = weaponId; Cannon weapon = _platoon.Units[0].AllWeapons[_weaponId]; _weaponIcon.sprite = weapon.HudIcon; int i = 0; for (; i < weapon.Ammo.Length; i++) { if (i > _description.Length) { break; } _description[i].gameObject.transform.parent.gameObject.SetActive(true); _description[i].text = $" {weapon.Ammo[i].Description}"; } for (; i < _description.Length; i++) { _description[i].gameObject.transform.parent.gameObject.SetActive(false); } }
/// <summary> /// After a unit is spawned in a basic state that mirror /// can transmit, augment it with 'art' /// (aka non-networking components) based on the config. /// This can't be done before spawning the unit as prefabs /// have to be avaialble at compile time for /// Mirror to be able to spawn them. /// Assumption: The config is the same for all clients. /// </summary> public void MakeUnit(Unit armoryUnit, GameObject unit, PlatoonBehaviour platoon) { GameObject art = MakeUnitCommon(unit, armoryUnit); GameObject deathEffect = null; if (armoryUnit.LeavesExplodingWreck) { deathEffect = GameObject.Instantiate( Resources.Load <GameObject>("Wreck"), art.transform); } // TODO: Load different voice type depending on Owner country GameObject voicePrefab = Resources.Load <GameObject>("VoiceComponent"); GameObject voiceGo = Object.Instantiate(voicePrefab, unit.transform); voiceGo.name = "VoiceComponent"; VoiceComponent voice = voiceGo.GetComponent <VoiceComponent>(); voice.Initialize(armoryUnit.VoiceLines); UnitDispatcher unitDispatcher = unit.GetComponent <UnitDispatcher>(); unitDispatcher.Initialize(platoon, art, deathEffect, voice); unitDispatcher.enabled = true; }
public void CmdSplitPlatoon(uint platoonNetId) { NetworkIdentity identity; if (NetworkIdentity.spawned.TryGetValue(platoonNetId, out identity)) { PlatoonBehaviour platoon = identity.gameObject.GetComponent <PlatoonBehaviour>(); // We do not do something like 'while (Units.Count > 0)' // because the RPCs finish executing and hence update the unit count // way after the loop has concluded! int newPlatoonsCount = platoon.Units.Count - 1; while (newPlatoonsCount > 0) { UnitDispatcher u = platoon.Units[newPlatoonsCount]; uint unitNetId = u.GetComponent <NetworkIdentity>().netId; platoon.RpcRemoveUnit(unitNetId); PlatoonBehaviour newPlatoon = PlatoonBehaviour.CreateGhostMode( platoon.Unit, platoon.Owner); GhostPlatoonBehaviour ghostPlatoon = newPlatoon.GhostPlatoon; NetworkServer.Spawn(ghostPlatoon.gameObject); NetworkServer.Spawn(newPlatoon.gameObject); newPlatoon.RpcEstablishReferences( ghostPlatoon.netId, new[] { unitNetId }); newPlatoon.RpcActivate(u.Transform.position); newPlatoonsCount--; } } }
public void CmdSpawnPlatoon( byte playerId, byte categoryId, int unitId, int unitCount, Vector3 spawnPos, Vector3 destinationCenter, float destinationHeading) { Logger.LogNetworking( LogLevel.DEBUG, this, $"Spawning platoon at {spawnPos}"); if (MatchSession.Current.Players.Count > playerId && unitCount >= MIN_PLATOON_SIZE && unitCount <= MAX_PLATOON_SIZE) { PlayerData owner = MatchSession.Current.Players[playerId]; if (categoryId < owner.Deck.Categories.Length && unitId < MatchSession.Current.Armory.Categories[categoryId].Count) { Unit unit = MatchSession.Current.Armory.Categories[categoryId][unitId]; PlatoonBehaviour newPlatoon = PlatoonBehaviour.CreateGhostMode(unit, owner); GhostPlatoonBehaviour ghostPlatoon = newPlatoon.GhostPlatoon; NetworkServer.Spawn(ghostPlatoon.gameObject); NetworkServer.Spawn(newPlatoon.gameObject); uint[] unitIds = new uint[unitCount]; for (int i = 0; i < unitCount; i++) { GameObject unitGO = Instantiate(unit.Prefab); // Any added unit initialization must be done in an RPC, // otherwise it won't show up on the clients! NetworkServer.Spawn(unitGO); unitIds[i] = unitGO.GetComponent <NetworkIdentity>().netId; } newPlatoon.RpcEstablishReferences(ghostPlatoon.netId, unitIds); newPlatoon.RpcInitializeUnits(); ghostPlatoon.RpcSetOrientation(destinationCenter, destinationHeading); newPlatoon.RpcActivate(spawnPos); } else { Debug.LogError("Got bad unit id from a client."); } } else { // Got an invalid player id, server is trying to crash us? Debug.LogError( "Client asked to create a platoon with an invalid player id."); } }
private void MaybeTogglePlatoonVisibility(bool unitRevealed) { PlatoonBehaviour platoon = UnitBehaviour.Platoon; ToggleAllRenderers(platoon.gameObject, !platoon.Units.TrueForAll( u => !u.VisibleBehavior._isVisible)); }
/// <summary> /// If all units are invisible, make the platoon invisible. /// </summary> private void MaybeTogglePlatoonVisibility() { PlatoonBehaviour platoon = _unit.Platoon; bool visible = !platoon.Units.TrueForAll( u => !u.VisionComponent.IsVisible); platoon.ToggleLabelVisibility(visible); }
public static OrderData MakeFirePositionOrder( PlatoonBehaviour platoonBehaviour, Vector3 targetGround) { return(new OrderData( OrderType.FIRE_POSITION_ORDER, platoonBehaviour, targetGround)); }
public void BuildRealPlatoon() { _realPlatoon = GameObject.Instantiate(Resources.Load <GameObject>("Platoon")); _platoonBehaviour = _realPlatoon.GetComponent <PlatoonBehaviour>(); _platoonBehaviour.Initialize(_unitType, _owner, _units.Count); _platoonBehaviour.SetGhostPlatoon(this); }
public void buildRealPlatoon() { realPlatoon = GameObject.Instantiate(Resources.Load <GameObject>("Platoon")); //yield return null; platoonBehaviour = realPlatoon.GetComponent <PlatoonBehaviour>(); platoonBehaviour.setMembers(unitType, team, units.Count); platoonBehaviour.setEnabled(false); platoonBehaviour.setGhostPlatoon(this); realPlatoon.transform.position = transform.position + 100 * Vector3.down; }
/// <summary> /// Create the smallest platoon allowed. /// </summary> private void StartNewPlatoon() { _smallestPlatoonSize = MIN_PLATOON_SIZE; _newestPlatoon = PlatoonBehaviour.CreateGhostMode(Unit, Owner); for (int i = 0; i < MIN_PLATOON_SIZE; i++) { _newestPlatoon.AddSingleUnit(); } PreviewPlatoons.Add(_newestPlatoon); }
public void CmdCancelOrders( uint platoonNetId) { NetworkIdentity identity; if (NetworkIdentity.spawned.TryGetValue(platoonNetId, out identity)) { PlatoonBehaviour platoon = identity.gameObject.GetComponent <PlatoonBehaviour>(); platoon.RpcCancelOrders(); } }
public WaypointOverlayBehavior CreateWaypointOverlay(PlatoonBehaviour pb) { var overlayPrefab = Resources.Load <GameObject>("WaypointOverlay"); var waypointOverlayBehavior = Object.Instantiate( overlayPrefab, Vector3.zero, Quaternion.identity) .GetComponent <WaypointOverlayBehavior>(); waypointOverlayBehavior.Initialize(pb); return(waypointOverlayBehavior); }
private bool isInside(PlatoonBehaviour obj) { bool inside = false; if (!obj.GetComponent <PlatoonBehaviour>().initialized) { return(false); } inside |= obj.GetComponent <PlatoonBehaviour>().units.Any(x => isInside(x.transform.position)); inside |= isInside(obj.GetComponent <PlatoonBehaviour>().icon.transform.GetChild(0).position); return(inside); }
public static OrderData MakeMoveOrder( PlatoonBehaviour platoon, Vector3 destination, float heading = MovementComponent.NO_HEADING, MoveCommandType moveCommandType = MoveCommandType.NORMAL) { return(new OrderData( OrderType.MOVE_ORDER, platoon, destination, heading, moveCommandType)); }
/// <summary> /// When a platoon's label is left clicked we need to /// add it to the selection. These clicks are detected /// by a button callback handler, so the notification /// unfortunately has to come from the outside.. /// </summary> public void PlatoonLabelClicked(PlatoonBehaviour selectedPlatoon) { if (selectedPlatoon.Owner != _localPlayer) { return; } UnselectAll(_selection, false); selectedPlatoon.PlaySelectionVoiceline(); _selection.Add(selectedPlatoon); SetSelected(_selection, false); _justSelected = true; }
/// <summary> /// Platoon labels for real units are initialized /// before the platoon is fully spawned and activated, /// so they have to be made visible in a separate, later call. /// </summary> public void InitializeAsReal( Unit unit, TeamColorScheme colorScheme, PlatoonBehaviour platoon) { _unitName.text = unit.Name; _color = colorScheme; SetColor(colorScheme.BaseColor); // When the label is clicked, notify the selection manager: _button.onClick.AddListener( () => MatchSession.Current.PlatoonLabelClicked(platoon)); }
private OrderData( OrderType orderType, PlatoonBehaviour platoon, Vector3 targetPosition, float heading = MovementComponent.NO_HEADING, MoveCommandType moveCommandType = MoveCommandType.NORMAL) { OrderType = orderType; Platoon = platoon; TargetPosition = targetPosition; Heading = heading; MoveCommandType = moveCommandType; }
public void Initialize(PlatoonBehaviour platoon) { _platoon = platoon; _lineR = transform.Find("Line").GetComponent <LineRenderer>(); _lineR.startColor = Color.yellow; _lineR.endColor = Color.yellow; _lineR.useWorldSpace = true; _lineR.sortingLayerName = "OnTop"; _lineR.sortingOrder = 20; _lineR.startWidth = 0.10f; _lineR.endWidth = 0.10f; }
public void CmdOrderMovement( uint platoonNetId, Vector3 destination, float heading, MoveCommandType mode, bool enqueue) { NetworkIdentity identity; if (NetworkIdentity.spawned.TryGetValue(platoonNetId, out identity)) { PlatoonBehaviour platoon = identity.gameObject.GetComponent <PlatoonBehaviour>(); platoon.RpcOrderMovement(destination, heading, mode, enqueue); } }
private bool IsInside(PlatoonBehaviour obj) { var platoon = obj.GetComponent <PlatoonBehaviour>(); if (!platoon.IsInitialized) { return(false); } bool inside = false; inside |= platoon.Units.Any(x => IsInside(x.transform.position)); // TODO: This checks if the center of the icon is within the selection box. It should instead check if any of the four corners of the icon are within the box: inside |= IsInside(platoon.Icon.transform.GetChild(0).position); return(inside); }
public void SetTransported(PlatoonBehaviour p) { transported = p; for (int i = 0; i < Platoon.Units.Count; i++) { if (p != null) { if (i == p.Units.Count) { break; } Platoon.Units[i].GetComponent <TransporterBehaviour>().transported = p.Units[i] as InfantryBehaviour; } else { Platoon.Units[i].GetComponent <TransporterBehaviour>().transported = null; } } }
/// <summary> /// After a unit is spawned in a basic state that mirror /// can transmit, augment it with 'art' /// (aka non-networking components) based on the config. /// This can't be done before spawning the unit as prefabs /// have to be avaialble at compile time for /// Mirror to be able to spawn them. /// Assumption: The config is the same for all clients. /// </summary> public void MakeUnit(Unit armoryUnit, GameObject unit, PlatoonBehaviour platoon) { MakeUnitCommon(unit, armoryUnit); // TODO: Load different voice type depending on Owner country GameObject voicePrefab = Resources.Load <GameObject>("VoiceComponent_US"); GameObject voiceGo = Object.Instantiate(voicePrefab, unit.transform); voiceGo.name = "VoiceComponent"; Color minimapColor = platoon.Owner.Team.ColorScheme.BaseColor; AddMinimapIcon(unit, minimapColor); UnitDispatcher unitDispatcher = unit.GetComponent <UnitDispatcher>(); unitDispatcher.Initialize(platoon); unitDispatcher.enabled = true; }
private bool IsInsideSelectionBox(PlatoonBehaviour obj) { PlatoonBehaviour platoon = obj.GetComponent <PlatoonBehaviour>(); if (!platoon.IsInitialized) { return(false); } Rect selectionBox; // Guarantee that the rect has positive width and height: float rectX = _mouseStart.x > _mouseEnd.x ? _mouseEnd.x : _mouseStart.x; float rectY = _mouseStart.y > _mouseEnd.y ? _mouseEnd.y : _mouseStart.y; selectionBox = new Rect( rectX, rectY, Mathf.Abs(_mouseEnd.x - _mouseStart.x), Mathf.Abs(_mouseEnd.y - _mouseStart.y)); bool inside = false; inside |= platoon.Units.Any( x => selectionBox.Contains( Camera.main.WorldToScreenPoint( x.Transform.position))); // This checks if the icon overlaps with the selection box: Rect platoonLabel = platoon.SelectableRect.rect; // To screen coordinates: platoonLabel.center = platoon.SelectableRect.TransformPoint( platoonLabel.center); platoonLabel.size = platoon.SelectableRect.TransformVector( platoonLabel.size); inside |= selectionBox.Overlaps(platoonLabel); return(inside); }
public void PlatoonLabelClicked(PlatoonBehaviour platoon) => _selectionManager.PlatoonLabelClicked(platoon);
public void RegisterPlatoonDeath(PlatoonBehaviour platoon) { _selectionManager.RegisterPlatoonDeath(platoon); }
public TransportableModule(PlatoonBehaviour p) : base(p) { }
public void RegisterPlatoonDeath(PlatoonBehaviour platoon) { _selection.Remove(platoon); AllPlatoons.Remove(platoon); }
public void RegisterPlatoonBirth(PlatoonBehaviour platoon) { AllPlatoons.Add(platoon); }
/// <summary> /// Inform the selection manager that a platoon label was /// clicked so that the selection can be updated. /// </summary> /// Passing this info this way is kind of ugly, but /// arguably better than exposing the selection manager just /// for this call? public void PlatoonLabelClicked(PlatoonBehaviour platoon) => _inputManager.PlatoonLabelClicked(platoon);