public float CalcDamage(float power, DamageType kind = DamageType.Physics) { DamageType exposedFilter = Exposed; float damageValue = 0; Dictionary <DamageType, float> results = new Dictionary <DamageType, float>(); foreach (DamageType s in Enum.GetValues(typeof(DamageType))) { if ((s & Exposed) > 0) { results.Add(s, 0); } } //Считаем повреждения по каждому типу foreach (var modificator in modificators) { if ((modificator.type & exposedFilter) == 0) { continue; } if ((modificator.type & kind) == 0) { continue; } switch (modificator.effect) { case DamageEffect.OnlyThis: results[modificator.type] = power * modificator.power; exposedFilter &= ~modificator.type; break; case DamageEffect.Add: results[modificator.type] = (results.ContainsKey(modificator.type)? results[modificator.type] : 0) + power * modificator.power; break; case DamageEffect.Concurent: if (results.ContainsKey(modificator.type)) { results[modificator.type] = Mathf.Max(results[modificator.type], power * modificator.power); } break; } } //Считаем суммарные повреждения foreach (var result in results) { damageValue += result.Value; } return(KingUtil.Round(damageValue * ScaleDamage, 0.1f)); }
float getValue(Rect position, GUIContent label, float value) { float left = rangeAttribute.left; float right = rangeAttribute.right; float step = rangeAttribute.step; float newValue = EditorGUI.Slider(position, label, value, left, right); if (newValue != left && newValue != right && step > float.Epsilon) { newValue = newValue - left; newValue = KingUtil.Round(newValue, step); newValue = newValue + left; newValue = Mathf.Clamp(newValue, Mathf.Min(left, right), Mathf.Max(left, right)); } return(newValue); }