public void Concatinate(SubstanceMixture otherMixture) { _temperature = (_temperature * Volume + otherMixture.Temperature * otherMixture.Volume) / (Volume + otherMixture.Volume); foreach (var substanceInfo in otherMixture) { int index = IndexOfSubstance(substanceInfo.SubstanceId); if (index == -1) { _listImplementation.Add(substanceInfo); //otherMixture.Remove(substanceInfo); } else { SubstanceInfo info = _listImplementation[index]; /*info.Temperature = (substanceInfo.Temperature * substanceInfo.Volume + info.Temperature * info.Volume) / * (info.Volume + substanceInfo.Volume);*/ info.Volume += substanceInfo.Volume; _listImplementation[index] = info; } } _wasModified = true; }
public object Clone() { SubstanceMixture mixture = new SubstanceMixture(_listImplementation.Count); mixture.AddRange(_listImplementation); return(mixture); }
public Color GetSubtanceColor(SubstanceMixture list) { if (!Current.WasLoaded) { return(Color.clear); } if (list.Count == 0) { return(Color.clear); } Color color = GetSubstance(list[0].SubstanceId).Color *list.GetElementPart(0); for (int i = 1; i < list.Count; i++) { Color elementColor = GetSubstance(list[i].SubstanceId).Color *list.GetElementPart(i); color += elementColor; } return(color); }
public SubstanceMixture SubtractPart(float part) { if (part > 1 || part <= 0) { throw new ArgumentOutOfRangeException(nameof(part), "Must be inside (0, 1]"); } SubstanceMixture mixture = new SubstanceMixture(_listImplementation.Count); for (int i = 0; i < _listImplementation.Count; i++) { SubstanceInfo info = _listImplementation[i]; SubstanceInfo subtracted = info; subtracted.Volume *= part; info.Volume -= subtracted.Volume; mixture.Add(subtracted); _listImplementation[i] = info; } return(mixture); }
IEnumerator WaitForGameReady() { while (ServerController.Current == null || !ServerController.Current.Ready) { yield return(new WaitForEndOfFrame()); } if (_spawnMixture.Length != 0) { ISubstanceContainer container; if (_target == null) { container = GetComponent <ISubstanceContainer>(); } else { container = _target as ISubstanceContainer; } SubstanceMixture mixture = new SubstanceMixture(_spawnMixture.Length, _temperature); mixture.AddRange(_spawnMixture); //Debug.Log("SubstanceSpawner: " + mixture); if (container != null) { container.TransferInto(mixture); } else { Debug.LogError("Target not found! Please, attach target to field or make this script a component of an ISubstanceContainer"); } } }
public SubstanceMixture SubtractVolume(float volume) { if (volume > Volume) { throw new ArgumentOutOfRangeException(nameof(volume), "Must be inside (0, Volume of this instance]. Current volume: " + Volume); } SubstanceMixture mixture = new SubstanceMixture(_listImplementation.Count); float volumeTmp = Volume; for (int i = 0; i < _listImplementation.Count; i++) { SubstanceInfo info = _listImplementation[i]; SubstanceInfo subtracted = info; subtracted.Volume = volume * info.Volume / volumeTmp; info.Volume -= subtracted.Volume; _listImplementation[i] = info; mixture.Add(subtracted); } return(mixture); }