Ejemplo n.º 1
0
    /// <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);
        }
    }
Ejemplo n.º 2
0
    // 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);
    }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
    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);
    }
Ejemplo n.º 5
0
    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);
        }
    }