void SortList() { //continue looping untill the list is sorted. //In the case that we enter higher priority zones later (as we should) then this should take as little as 1-2 loops //In the case that we run in to a extremely low priority later, this will take count^2 amount of times. //Swap this for a better sorting algorithm later. bool isSorted = false; while (isSorted == false) { isSorted = true; for (int i = 0; i < volumes.Count - 1; i++) { LoadingVolume currentVolume = volumes[i]; LoadingVolume nextVolume = volumes[i + 1]; if (currentVolume.priority > nextVolume.priority) { volumes.Remove(currentVolume); volumes.Insert(i + 1, currentVolume); isSorted = false; } } } }
private void OnTriggerExit(Collider other) { if (other.CompareTag("LoadingVolume")) { LoadingVolume volume = other.GetComponent <LoadingVolume>(); if (volume != null) { volumes.Remove(volume); StartCoroutine(RecalculateLoadedScenes()); } } }
void OnTriggerEnter(Collider other) { if (other.CompareTag("LoadingVolume")) { LoadingVolume volume = other.GetComponent <LoadingVolume>(); if (volume != null && !volumes.Contains(volume)) { AddToList(volume); StartCoroutine(RecalculateLoadedScenes()); } } }
public void AddToList(LoadingVolume volume) { for (int i = 0; i < volumes.Count; i++) { LoadingVolume currentVolume = volumes[i]; if (currentVolume.priority > volume.priority) { volumes.Insert(i, volume); return; } } volumes.Add(volume); }