/// <summary> /// Must notify the registry every time a /// (real, active) unit is removed. /// <para></para> /// Do not call outside of MatchSession. /// </summary> /// <param name="unit"></param> public void RegisterUnitDeath(UnitDispatcher unit) { Units.Remove(unit); Team unitTeam = unit.Platoon.Team; UnitsByTeam[unitTeam].Remove(unit); foreach (var pair in EnemiesByTeam) { if (pair.Key != unitTeam) { pair.Value.Remove(unit); } } VisionComponent visionComponent = unit.VisionComponent; if (unitTeam == _localTeam) { AllyVisionComponents.Remove(visionComponent); } else { EnemyVisionComponents.Remove(visionComponent); } }
/// <summary> /// Must notify the registry every time a /// (real, active) unit is created. /// <para></para> /// Do not call outside of MatchSession. /// </summary> /// <param name="unit"></param> public void RegisterUnitBirth(UnitDispatcher unit) { Units.Add(unit); Team unitTeam = unit.Platoon.Team; UnitsByTeam[unitTeam].Add(unit); // Add unit as enemy to all other teams: foreach (var pair in EnemiesByTeam) { if (pair.Key != unitTeam) { pair.Value.Add(unit); } } VisionComponent visibleBehavior = unit.VisionComponent; if (unitTeam == _localTeam) { AllyVisionComponents.Add(visibleBehavior); } else { EnemyVisionComponents.Add(visibleBehavior); } }
public void Initialize( UnitDispatcher dispatcher, DataComponent data) { _dispatcher = dispatcher; Health = data.MaxHealth; }
/// <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 Initialize(UnitDispatcher unit) { _unit = unit; _successLine.startColor = Color.cyan; _successLine.endColor = Color.cyan; _successLine.useWorldSpace = true; _successLine.sortingLayerName = "OnTop"; _successLine.sortingOrder = 21; _successLine.startWidth = 0.005f; _successLine.endWidth = 0.10f; _successLine.positionCount = 2; // The line shown after a los block _errorLine.startColor = Color.red; _errorLine.endColor = Color.red; _errorLine.useWorldSpace = true; _errorLine.sortingLayerName = "OnTop"; _errorLine.sortingOrder = 21; _errorLine.startWidth = 0.10f; _errorLine.endWidth = 0.10f; _errorLine.positionCount = 2; }
/// <summary> /// Notify all nearby enemy units that they may have to show themselves. /// Only works if they have colliders! /// </summary> public void ScanForEnemies() { Collider[] hits = Physics.OverlapSphere( gameObject.transform.position, _maxSpottingRange, LayerMask.NameToLayer("Selectable"), QueryTriggerInteraction.Ignore); foreach (Collider c in hits) { GameObject go = c.gameObject; // this finds colliders, health bars and all other crap except units UnitDispatcher unit = go.GetComponentInParent <UnitDispatcher>(); if (unit == null || !unit.enabled) { continue; } // This assumes that all selectables with colliders have // a visibility manager, which may be a bad assumption: if (unit.Platoon.Owner.Team != _team) { unit.VisionComponent.MaybeReveal(this); } } }
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 Initialize(UnitDispatcher dispatcher, DataComponent unitData) { _unit = dispatcher; _terrainMap = MatchSession.Current.TerrainMap; _maxSpottingRange = unitData.MaxSpottingRange; _stealthFactor = unitData.Stealth; _stealthPenFactor = unitData.StealthPenetration; }
// TODO: If the unit is killed, it will never be removed from the zone: private void OnTriggerExit(Collider other) { UnitDispatcher component = other.transform.parent.GetComponent <UnitDispatcher>(); if (component != null) { _units.Remove(component); } }
public TargetingOverlay CreateTargetingOverlay(UnitDispatcher unit) { var overlayPrefab = Resources.Load <GameObject>("TargetingOverlay"); var targetingOverlay = Object.Instantiate( overlayPrefab, Vector3.zero, Quaternion.identity) .GetComponent <TargetingOverlay>(); targetingOverlay.Initialize(unit); return(targetingOverlay); }
private void OnTriggerExit(Collider other) { UnitDispatcher unit = other.transform.root.GetComponent <UnitDispatcher>(); if (unit != null && unit.isActiveAndEnabled && unit.CanCaptureZones) { Logger.LogWithoutSubsystem( LogLevel.DEBUG, $"Command unit {unit} has left capture zone {this}."); _units.Remove(unit); } }
// Update is called once per frame private void Update() { // Pop any units that have been killed since the last update: _units.RemoveAll(x => x == null); // Check if Blue Red None or Both occupy the zone bool redIncluded = false; bool blueIncluded = false; PlayerData newOwner = null; for (int i = 0; i < _units.Count; i++) { UnitDispatcher unit = _units.ToArray()[i]; if (!unit.IsMoving()) { newOwner = unit.Platoon.Owner; // Names are USSR and NATO if (newOwner.Team.Name == "USSR") { redIncluded = true; } else { blueIncluded = true; } } } if (redIncluded && blueIncluded || (!redIncluded && !blueIncluded)) { if (_owner != null) { ChangeOwner(null); } } else if (redIncluded) { if (_owner != newOwner) { ChangeOwner(newOwner); } } else { if (_owner != newOwner) { ChangeOwner(newOwner); } } }
private void OnTriggerEnter(Collider other) { if (other.transform.parent == null) { return; } UnitDispatcher component = other.transform.parent.GetComponent <UnitDispatcher>(); if (component != null && component.isActiveAndEnabled) { _units.Add(component); } }
// Update is called once per frame private void Update() { // Pop any units that have been killed since the last update: _units.RemoveAll(x => x == null); // Check if Blue Red None or Both occupy the zone bool redIncluded = false; bool blueIncluded = false; for (int i = 0; i < _units.Count; i++) { UnitDispatcher unit = _units.ToArray()[i]; if (!unit.IsMoving()) { if (unit.Platoon.Team.Name == Team.TeamName.USSR) { redIncluded = true; } else { blueIncluded = true; } } } if (redIncluded && blueIncluded || (!redIncluded && !blueIncluded)) { if (OwningTeam != Team.TeamName.UNDEFINED) { ChangeTeam(Team.TeamName.UNDEFINED); } } else if (redIncluded) { if (OwningTeam != Team.TeamName.USSR) { ChangeTeam(Team.TeamName.USSR); } } else { if (OwningTeam != Team.TeamName.NATO) { ChangeTeam(Team.TeamName.NATO); } } }
// Update is called once per frame private void Update() { // Check if Blue Red None or Both occupy the zone bool redIncluded = false; bool blueIncluded = false; PlayerData newOwner = null; for (int i = 0; i < _units.Count; i++) { UnitDispatcher unit = _units.ToArray()[i]; if (unit.AreOrdersComplete()) { newOwner = unit.Platoon.Owner; // Names are USSR and NATO if (newOwner.Team.Name == "USSR") { redIncluded = true; } else { blueIncluded = true; } } } if (redIncluded && blueIncluded || (!redIncluded && !blueIncluded)) { if (_owner != null) { ChangeOwner(null); } } else if (redIncluded) { if (_owner != newOwner) { ChangeOwner(newOwner); } } else { if (_owner != newOwner) { ChangeOwner(newOwner); } } }
private void OnTriggerEnter(Collider other) { if (other.transform.parent == null) { return; } UnitDispatcher unit = other.transform.root.GetComponent <UnitDispatcher>(); if (unit != null && unit.isActiveAndEnabled && unit.CanCaptureZones) { Logger.LogWithoutSubsystem( LogLevel.DEBUG, $"Command unit {unit} has entered capture zone {this}."); _units.Add(unit); } }
/// <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; }
public void SetUnit(UnitDispatcher o) { _unit = o; SetHealth(_unit.MaxHealth); }
/// <summary> /// Do not call this constructor outside of the UnitDispatcher class! /// </summary> /// <param name="enemy"></param> public TargetTuple(UnitDispatcher enemy, TargetType type) { _position = Vector3.zero; Enemy = enemy; Type = type; }
public void RegisterUnitDeath(UnitDispatcher unit) => _unitRegistry.RegisterUnitDeath(unit);