Ejemplo n.º 1
0
    //##############################################################################################
    // Build the lookup dictionary and warn if it's configured without a fallback
    //##############################################################################################
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }

        // Build the lookup dictionary, and warn if no fallback is found
        for (int i = 0, count = lookupData.lookups.Length; i < count; ++i)
        {
            if (lookupData.lookups[i].materialName == MaterialName.Fallback)
            {
                fallback = lookupData.lookups[i];
            }
            else
            {
                lookupDataDictionary.Add(lookupData.lookups[i].materialName, lookupData.lookups[i]);
            }
        }

        if (fallback == null)
        {
            Debug.LogWarning("In MaterialLookupSourceComponent, there is no fallback defined, and therefore nothing can be returned during lookup if no matching material is found.");
        }
    }
Ejemplo n.º 2
0
    //##############################################################################################
    // Get the lookup data for the given material, then build a list of the spawnables based on the
    // type. Use the fallback if indicated.
    //
    // This value should be cached by the callee, and only re-evaluated when materials change.
    //##############################################################################################
    public static List <GameObject> GetMaterialSpawnables(MaterialName materialName, MaterialSpawnableType spawnableType, bool useFallbackIfNotFound = false)
    {
        List <GameObject> data = new List <GameObject>();

        if (instance.lookupDataDictionary.ContainsKey(materialName))
        {
            MaterialLookupEntry lookup = instance.lookupDataDictionary[materialName];

            foreach (MaterialSpawnable materialSpawnable in lookup.spawnables)
            {
                if (materialSpawnable.type == spawnableType)
                {
                    data.Add(materialSpawnable.spawnable);
                }
            }
        }

        if ((materialName == MaterialName.Fallback || (data.Count == 0 && useFallbackIfNotFound)) && instance.fallback != null)
        {
            foreach (MaterialSpawnable materialSpawnable in instance.fallback.spawnables)
            {
                if (materialSpawnable.type == spawnableType)
                {
                    data.Add(materialSpawnable.spawnable);
                }
            }
        }

        return(data);
    }
Ejemplo n.º 3
0
    //##############################################################################################
    // Get the lookup data for the given material, then build a list of the sounds based on the
    // type. Use the fallback if indicated.
    //
    // This value should be cached by the callee, and only re-evaluated when materials change.
    //##############################################################################################
    public static List <AudioClip> GetMaterialSounds(MaterialName materialName, MaterialSoundType soundType, bool useFallbackIfNotFound = false)
    {
        List <AudioClip> data = new List <AudioClip>();

        if (instance.lookupDataDictionary.ContainsKey(materialName))
        {
            MaterialLookupEntry lookup = instance.lookupDataDictionary[materialName];

            foreach (MaterialSound materialSound in lookup.sounds)
            {
                if (materialSound.type == soundType)
                {
                    data.Add(materialSound.sound);
                }
            }
        }

        if ((materialName == MaterialName.Fallback || (data.Count == 0 && useFallbackIfNotFound)) && instance.fallback != null)
        {
            foreach (MaterialSound materialSound in instance.fallback.sounds)
            {
                if (materialSound.type == soundType)
                {
                    data.Add(materialSound.sound);
                }
            }
        }

        return(data);
    }