/// <summary> /// Sets up triggers. /// This function just SETS UP the triggers and /// where they should spawn. The actual triggers are /// spawned from the DegradationUIManager. /// </summary> private void SetUpTriggers() { Debug.Log("SETTING UP TRIGGERS"); // get list of available locations to spawn triggers List <ImmutableDataTriggerLocation> listAvailable = DataLoaderTriggerLocations.GetAvailableTriggerLocations("Bedroom"); // get the number of triggers to spawn based on the previously uncleaned triggers and the new ones to spawn, with a max int numToSpawn = GetNumTriggersToSpawn(); DataManager.Instance.GameData.Degradation.UncleanedTriggers = numToSpawn; List <ImmutableDataTriggerLocation> listChosen = ListUtils.GetRandomElements(listAvailable, numToSpawn); //create trigger data to be spawned for (int i = 0; i < listChosen.Count; i++) { ImmutableDataTriggerLocation location = listChosen[i]; ImmutableDataTrigger randomTrigger = DataLoaderTriggers.GetRandomSceneTrigger("Bedroom"); //spawn them at a pre defined location ID is the order in which the data are created degradationTriggers.Add(new DegradData(randomTrigger.ID, location.Partition, location.Position)); } if (degradationTriggers.Count > 0) { AudioManager.Instance.backgroundMusic = "bgClinic"; AudioManager.Instance.StartCoroutine("PlayBackground"); } if (OnRefreshTriggers != null) { OnRefreshTriggers(this, EventArgs.Empty); } }
// Note that this function assumes it is okay to be spawning triggers. private DegradTrigger PlaceTrigger(DegradData degradData) { string triggerID = degradData.TriggerID; int partition = degradData.Partition; Vector3 position = degradData.Position; ImmutableDataTrigger triggerData = DataLoaderTriggers.GetTriggerData(triggerID); //instantiate all the triggers saved in DataManager Transform parent = PartitionManager.Instance.GetInteractableParent(partition); GameObject triggerPrefab = (GameObject)Resources.Load(triggerData.PrefabName); GameObject trigger = GameObjectUtils.AddChild(parent.gameObject, triggerPrefab); trigger.transform.localPosition = position; //keep a local reference currentSpawnTriggers.Add(trigger); // set the trigger's ID DegradTrigger scriptTrigger = trigger.GetComponent <DegradTrigger>(); scriptTrigger.ID = triggerID; return(scriptTrigger); }