public override void SpawnObject(int index, Vector3 position, UnitMode mode) { base.SpawnObject(index, position, mode); enemyMovement.Speed = enemy.Speed; enemyMovement.MoveEnded += HandleMoveEnded; currentHealth = enemy.Health; }
private string getRulerText(IRenderer r, double distMesure, out bool isMinor, out Point2D TextOffset, bool isVerticalAxis) { string rulertext = UnitMode.GetDistanceString(Distance.FromMetres(distMesure), "?"); isMinor = rulertext.StartsWith("?"); rulertext = rulertext.TrimStart("?".ToCharArray()); if (isVerticalAxis && (rulertext.Length > 6)) { rulertext = rulertext.Replace("mm", "\r\n mm"); rulertext = rulertext.Replace("mils", "\r\n mils"); } TextFormat fmt = isMinor ? fmtMinor : fmtMajor; Size size = r.MeasureString(rulertext, fmt.font); //update the max seen zise if ((MaxSeenLabelSize.Width < size.Width) || (MaxSeenLabelSize.Height < size.Height)) { MaxSeenLabelSize = new Size(Math.Max(MaxSeenLabelSize.Width, size.Width), Math.Max(MaxSeenLabelSize.Height, size.Height)); } //calculate an appropriate text offset if (isVerticalAxis) { //TextOffset = new Point2D(1, -7); TextOffset = new Point2D(1, -(size.Height / 2)); } else { TextOffset = new Point2D(-(size.Width / 2), 2); } return(rulertext); }
private IEnumerator SpawnEnemiesRoutine(RedemptionTDSpawnInfo spawnInfo) { yield return(new WaitForSeconds(spawnInfo.StartSpawnDelay)); var enemies = objectPool.GetUnits(spawnInfo.EnemyType, spawnInfo.NumberToSpawn); foreach (var enemy in enemies) { var enemyMode = UnitMode.CreateUnitMode(); enemy.SpawnObject(currentSpawnCount, spawnInfo.SpawnPosition.transform.position, enemyMode); if (currentSpawnCount < currentSpawns.Count) { currentSpawns[currentSpawnCount] = enemy; } else { currentSpawns.Add(enemy); } currentSpawnCount++; enemy.ObjectReturned += HandleEnemyReturned; var movement = enemy.GetComponent <EnemyMovement>(); movement.Initialize(spawnInfo.SpawnPosition); movement.Move(); yield return(new WaitForSeconds(spawnInfo.TimeBetweenSpawns)); } yield return(new WaitForSeconds(spawnInfo.StopSpawnDelay)); }
private static string GetUnitL10NKey(double weight, UnitMode unitMode) { if (unitMode == UnitMode.Tons || (unitMode == UnitMode.Auto && weight > 1000)) { return(App.GetLocalizedString("UnitTons")); } return(App.GetLocalizedString("UnitKilograms")); }
private static string FormatWeight(double weight, UnitMode unitMode) { if (unitMode == UnitMode.Tons || (unitMode == UnitMode.Auto && weight > 1000)) { return((weight / 1000).ToString("#,0.##")); } return(weight.ToString("#,0")); }
UnitResult IInternalUnit.PerformUnit(object argument, UnitMode unitMode) { Argument = (T)argument; var eventArgs = new UnitEventArgs <T>(Argument, unitMode); OnExecute(eventArgs); return(eventArgs.UnitResult); }
static void ExecuteInSequence( Dictionary <UnitBase <T>, T> unitDictionary, UnitMode unitMode) { foreach (KeyValuePair <UnitBase <T>, T> pair in unitDictionary) { var unit = (IInternalUnit)pair.Key; unit.PerformUnit(pair.Value, unitMode); } }
protected internal virtual void ExecuteInternal( Dictionary <UndoableUnitBase <T>, T> unitDictionary, UnitMode unitMode) { if (Parallel) { ExecuteInParallel(unitDictionary, unitMode); } else { ExecuteSequentially(unitDictionary, unitMode); } }
public static UnitMode CreateUnitMode(WeaponMode weapon = WeaponMode.NONE, EnemyMode enemy = EnemyMode.NONE, ResourceMode resource = ResourceMode.NONE) { var unitMode = new UnitMode(); unitMode.WeaponMode = weapon; unitMode.EnemyMode = enemy; unitMode.ResourceMode = resource; return(unitMode); }
static async void ExecuteInParallel( Dictionary <UnitBase <T>, T> unitDictionary, UnitMode unitMode) { /* When we move to .NET 4 we may use System.Threading.Parallel for the Desktop CLR. */ var performedUnits = new List <UnitBase <T> >(); object performedUnitsLock = new object(); var exceptions = new List <Exception>(); object exceptionsLock = new object(); var events = unitDictionary.ToDictionary(x => x, x => new AutoResetEvent(false)); foreach (KeyValuePair <UnitBase <T>, T> pair in unitDictionary) { var autoResetEvent = events[pair]; var unit = (IInternalUnit)pair.Key; var undoableUnit = pair.Key; var arg = pair.Value; #pragma warning disable 4014 Task.Run( #pragma warning restore 4014 delegate { try { unit.PerformUnit(arg, unitMode); lock (performedUnitsLock) { performedUnits.Add(undoableUnit); } } catch (Exception ex) { /* TODO: improve this to capture undone unit errors. */ lock (exceptionsLock) { exceptions.Add(ex); } } autoResetEvent.Set(); }); } foreach (var autoResetEvent in events.Values) { autoResetEvent.WaitOne(); } if (exceptions.Count > 0) { throw new AggregateException("Unable to undo units", exceptions); } }
private void SpawnWeapon(Vector2 position) { if (!ResourcesOverseer.DecreaseResourceEvent(currentWeapon.WeaponCost)) { return; } var weapons = objectPool.GetUnits(currentWeapon.WeaponType, 1); var weaponMode = UnitMode.CreateUnitMode(currentWeapon.WeaponMode); foreach (var weapon in weapons) { weapon.SpawnObject(0, position, weaponMode); } }
private void SpawnResourceDrops(LiteUnit liteUnit, Vector3 pos) { var enemy = liteUnit.HeavyReference as Enemy; if (enemy == null) { return; } var numToSpawn = UnityEngine.Random.Range(0, enemy.MaxResourceDrops); var units = objectPool.GetUnits(objectPool.GetResourceDropType(enemy.Color), numToSpawn); var count = 0; var resourceMode = UnitMode.CreateUnitMode(); foreach (var resourceDrop in units) { var position = new Vector3(pos.x + UnityEngine.Random.Range(-0.1f, 0.1f), pos.y + UnityEngine.Random.Range(-0.1f, 0.1f), -1f); resourceDrop.SpawnObject(count, position, resourceMode); count++; } }
// Changes the unit mode from Tower to Van, or vice versa public void Toggle(bool isBeforeDeath = false) { if (currentMode == UnitMode.Tank) { return; } FindObjectOfType <AudioManager>().Play("antennae"); if (currentMode == UnitMode.Van) { transform.rotation = Quaternion.FromToRotation(transform.up, Vector3.up) * transform.rotation; RadioSphereCollider.enabled = false; currentMode = UnitMode.Tower; vanObj.GetComponent <Animator>().SetBool("isShrunk", true); towerObj.GetComponent <Animator>().SetBool("isShrunk", false); GetComponent <NavMeshAgent>().enabled = false; GetComponent <ClickToMove>().StopMovement(); StartCoroutine(EnableTowerCr(0.75f)); } if (currentMode == UnitMode.Tower && isBeforeDeath) { towerObj.GetComponent <Animator>().SetBool("isShrunk", true); StartCoroutine(EnableVanCr(0.5f)); } #if false else { currentMode = UnitMode.Van; vanObj.GetComponent <Animator>().SetBool("isShrunk", false); towerObj.GetComponent <Animator>().SetBool("isShrunk", true); StartCoroutine(EnableVanCr(0.5f)); } #endif }
static void ExecuteSequentially(Dictionary <UndoableUnitBase <T>, T> unitDictionary, UnitMode unitMode) { var performedUnits = new List <UndoableUnitBase <T> >(); foreach (KeyValuePair <UndoableUnitBase <T>, T> pair in unitDictionary) { var unit = (IInternalUnit)pair.Key; try { unit.PerformUnit(pair.Value, unitMode); performedUnits.Add(pair.Key); } catch (Exception) { /* TODO: improve this to capture undone unit errors. */ SafelyUndoUnits(performedUnits); throw; } } }
private WeightViewModel(double weight, UnitMode unitMode) { this.Weight = weight; _unitMode = unitMode; }
public void Start() { currentMode = UnitMode.Van; IsConnectedToMotherbase = false; activatedHouses = new List <HouseObject>(); }
public virtual void SpawnObject(int index, Vector3 position, UnitMode mode) { Index = index; transform.position = position; RaiseOnSpawn(); }
/// <summary> /// Initializes a new instance of the <see cref="UnitEventArgs{TArgument}"/> class. /// </summary> /// <param name="argument">The argument used by the concrete /// <code>UnitBase</code> implementation.</param> /// <param name="unitMode">Indicates whether this unit is being performed /// for the fist time, if it is being redone, or if it is being repeated.</param> internal UnitEventArgs(TArgument argument, UnitMode unitMode) : this(argument) { UnitMode = unitMode; }
public override void SpawnObject(int index, Vector3 position, UnitMode mode) { base.SpawnObject(index, position, mode); InitializeWeaponState(mode.WeaponMode); }
internal UnitResult PerformUnit(object argument, UnitMode unitMode) { var internalUnit = (IInternalUnit)this; return(internalUnit.PerformUnit(argument, unitMode)); }
/// <summary> /// Initializes a new instance of the <see cref="UndoableUnitEventArgs{TArgument}"/> class. /// </summary> /// <param name="argument">The argument used by the concrete /// <code>UnitBase</code> implementation, which is propagated during /// the can and perform events.</param> /// <param name="unitMode">Indicates whether this unit is being performed /// for the fist time, if it is being redone, or if it is being repeated.</param> internal UndoableUnitEventArgs(TArgument argument, UnitMode unitMode) : base(argument, unitMode) { /* Intentionally left blank. */ }