public static Units <T> UnitsFromConfig <T>(ref KSP.IO.PluginConfiguration config, Units <T> defaultUnits = null) { UnitTypeContainer <T> unitType = UnitType <T>(); if (unitType == null) { throw new ArgumentException("Unit type " + typeof(T).ToString() + " has not been registered. Cannot load from config."); } return(unitType.UnitsFromConfig(ref config, defaultUnits)); }
public static void RegisterUnits <T>(Units <T> units) { UnitTypeContainer <T> unitType = UnitType <T>(); if (unitType == null) { Debug.LogWarning("Unit type " + typeof(T).ToString() + " has not been registered. Units " + units.ToString() + " will not be added."); } unitType.AddUnits(units); }
public static void RegisterUnits <T>(Units <T> units) { UnitTypeContainer <T> unitType = UnitType <T>(); if (unitType == null) { Log.warn("Unit type {0} has not been registered. Units {1} will not be added.", typeof(T), units); } unitType.AddUnits(units); }
private void Awake() { //Initialize the correct UnitType, and place it in variable thisUnit unitContainer = FindObjectOfType <UnitTypeContainer>(); unitTypes = unitContainer.unitTypes; for (int i = 0; i < unitTypes.Count; i++) { if (unitTypes[i].unitTypeName.Equals(unitTypeName)) { thisUnit = unitTypes[i]; break; } } //Basic For-loop to find the correct UnitType from container //Initialize the UnitType stats to this instance health = thisUnit.health; attackPower = thisUnit.attackPower; attackPerSecond = thisUnit.attackPerSecond; baseSpeed = thisUnit.baseSpeed; sizeRadius = thisUnit.sizeRadius; attackRadius = thisUnit.attackRadius; aggroRadius = thisUnit.aggroRadius; targets = thisUnit.targets; characteristcs = thisUnit.characteristcs; //Initialize some private stats as well: attackRad = attackRadius; //The tolrance distance for when the enemy starts "Attacking" the target instead of "Navigating" towards it. reachRad = attackRad * 1.2f; //Once the "Attacking" has started, we need to enlargen the attackDiameter, so that there won't occur any "following jitter", where the unit stops, but has to start navigating agian, because the enemy is out-of-reach on the next update. attackTimer = attackPerSecond; //Initialize the NavMeshAgent and assign stats to the agent's parameters agent = GetComponent <NavMeshAgent>(); agent.speed = baseSpeed; agent.radius = sizeRadius; //Assert the correct player id: thisPlayer = GetComponentInParent <PlayerID>().playerID; enemyPlayer = (thisPlayer == 1) ? 2 : 1; //Assert the correct TargetInformation to this unit targetInfo = GetComponent <UnitTargetInfo>(); targetInfo.SetTargetEnum(targets); targetInfo.SetCharacteristicsEnum(characteristcs); //Add the unit's Transform to the current battlefield units Hashset: targetManager = FindObjectOfType <TargetingManager>(); targetManager.RegisterUnit(gameObject.transform, thisPlayer); //Initialize the Unit States, so the game will orient the unit correctly starting from Update() currentState = AIstate.NoState; previousState = AIstate.NoState; AudioFW.Play("Unit_Knight_Ready"); }
private void Awake() { //Initialize the correct UnitType, and place it in variable thisUnit unitContainer = FindObjectOfType <UnitTypeContainer>(); unitTypes = unitContainer.unitTypes; for (int i = 0; i < unitTypes.Count; i++) { if (unitTypes[i].unitTypeName.Equals(unitTypeName)) { thisUnit = unitTypes[i]; break; } } //Basic For-loop to find the correct UnitType from container //Initialize the UnitType stats to this instance health = thisUnit.health; attackPower = thisUnit.attackPower; attackPerSecond = thisUnit.attackPerSecond; baseSpeed = thisUnit.baseSpeed; sizeRadius = thisUnit.sizeRadius; attackRadius = thisUnit.attackRadius; aggroRadius = thisUnit.aggroRadius; targets = thisUnit.targets; characteristcs = thisUnit.characteristcs; //Assert the correct player id: thisPlayer = GetComponentInParent <PlayerID>().playerID; enemyPlayer = (thisPlayer == 1) ? 2 : 1; //Assert the correct TargetInformation to this unit targetInfo = GetComponent <UnitTargetInfo>(); targetInfo.SetTargetEnum(targets); targetInfo.SetCharacteristicsEnum(characteristcs); //Add the unit's Transform to the current battlefield units Hashset: targetManager = FindObjectOfType <TargetingManager>(); AudioFW.Play("Unit_Fireball_Crash"); }