/// <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); }
public static ImmutableDataTrigger GetRandomSceneTrigger(string scene) { instance.InitXMLLoader(); ImmutableDataTrigger randomTrigger = null; Dictionary <string, ImmutableDataTrigger> sceneTriggers = instance.GetData <Dictionary <string, ImmutableDataTrigger> >(scene); //Get random element from the dictionary randomTrigger = sceneTriggers.ElementAt(UnityEngine.Random.Range(0, sceneTriggers.Count)).Value; return(randomTrigger); }
public static ImmutableDataTrigger GetTriggerData(string triggerID) { instance.InitXMLLoader(); ImmutableDataTrigger triggerData = null; List <Dictionary <string, ImmutableDataTrigger> > scenes = instance.GetDataList <Dictionary <string, ImmutableDataTrigger> >(); foreach (Dictionary <string, ImmutableDataTrigger> sceneTriggers in scenes) { if (sceneTriggers.ContainsKey(triggerID)) { triggerData = sceneTriggers[triggerID]; break; } } return(triggerData); }
protected override void XMLNodeHandler(string id, IXMLNode xmlNode, Hashtable hashData, string errorMessage) { ImmutableDataTrigger data = new ImmutableDataTrigger(id, xmlNode, errorMessage); string scene = data.Scene; if (!hashData.ContainsKey(scene)) { hashData.Add(scene, new Dictionary <string, ImmutableDataTrigger>()); } Dictionary <string, ImmutableDataTrigger> sceneTriggers = (Dictionary <string, ImmutableDataTrigger>)hashData[scene]; if (sceneTriggers.ContainsKey(id)) { Debug.LogError("Duplicate trigger id: " + id + " for " + scene); } else { sceneTriggers.Add(id, data); } }