public void Initialise() { IHasSpeed hasSpeed = GetComponent <IHasSpeed>(); BaseSpeed baseSpeed = new BaseSpeed(8); hasSpeed.MyHasSpeedAlterer.AddAlteration(hasSpeed, baseSpeed); }
private void printSpeed(Toy toy) { if (toy is IHasSpeed) { IHasSpeed temp = (IHasSpeed)(toy); System.Console.WriteLine("Speed: " + temp.Speed); } }
public void AddAlteration(IHasSpeed hasSpeed, ISpeedAlteration speedAlteration) { if (!MySpeedAlterationsDict.ContainsKey(hasSpeed)) { MySpeedAlterationsDict[hasSpeed] = new List <ISpeedAlteration>(); } MySpeedAlterationsDict[hasSpeed].Add(speedAlteration); }
public void RemoveAlteration(IHasSpeed hasSpeed, ISpeedAlteration speedAlteration) { if (!MySpeedAlterationsDict.ContainsKey(hasSpeed)) { Debug.LogError("Attempting to remove speed alteration from a HasSpeed that is not registered."); } MySpeedAlterationsDict[hasSpeed].Remove(speedAlteration); }
public void ChangeSpeed(double value) { if (toysList.Count > 1) { foreach (Toy toy in toysList) { if (toy is IHasSpeed) { IHasSpeed temp = (IHasSpeed)(toy); temp.Speed = value; } } } }
public int GetTotalMoveSpeed(IHasSpeed hasSpeed) { if (!MySpeedAlterationsDict.ContainsKey(hasSpeed)) { Debug.LogError("HasSpeed did not register in the dictionary."); } List <ISpeedAlteration> speedAlterations = MySpeedAlterationsDict[hasSpeed]; speedAlterations.Sort(new SpeedAlterationSort()); float speed = 0; foreach (ISpeedAlteration speedAlteration in speedAlterations) { speed = speedAlteration.Alter(speed); } return(Mathf.FloorToInt(speed)); }
private void Awake() { HasSpeed = (IHasSpeed)_hasSpeedObject; }