public void UnlagAll() { foreach (KeyValuePair <Laggable, Tuple <float, float> > lagInfo in laggedObjects) { Laggable laggedObject = lagInfo.Key; float amount = lagInfo.Value.Item1; laggedObject.deltaCpu += amount; //Item2 stores total lag used on object usableCpu += lagInfo.Value.Item2; } laggedObjects.Clear(); }
//Hit stuff void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.layer == LayerMask.NameToLayer("Hitbox")) { Laggable toLag = other.gameObject.GetComponentInParent <Laggable>(); if (lag != null) { lag.Lag(toLag, lagAmount); } Die(); } }
//Positive lag reduces speed negative increases public void Lag(Laggable toLag, float amount) { amount = Mathf.Min(toLag.CurrentCpu, amount); usableCpu -= Mathf.Abs(amount); toLag.deltaCpu -= amount; int index = laggedObjects.FindIndex(kv => kv.Key.Equals(toLag)); //Track objects we are lagging if (index != -1) { laggedObjects[index] = new KeyValuePair <Laggable, Tuple <float, float> > (toLag, new Tuple <float, float>(laggedObjects[index].Value.Item1 + amount, laggedObjects[index].Value.Item2 + Mathf.Abs(amount))); } else { laggedObjects.Add(new KeyValuePair <Laggable, Tuple <float, float> >(toLag, new Tuple <float, float>(amount, Mathf.Abs(amount)))); } }
public void SetSource(Laggable src) { lag = src; }