| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Skybox |
| | 6 | | { |
| | 7 | | [CreateAssetMenu(fileName = "SkyboxMaterialData", menuName = "ScriptableObjects/SkyboxMaterialData", order = 1)] |
| | 8 | | public class MaterialReferenceContainer : ScriptableObject |
| | 9 | | { |
| | 10 | | [System.Serializable] |
| | 11 | | public class Mat_Layer |
| | 12 | | { |
| | 13 | | public int numberOfSlots; |
| | 14 | | public Material material; |
| | 15 | | } |
| | 16 | |
|
| | 17 | | private static MaterialReferenceContainer instance; |
| 0 | 18 | | public static MaterialReferenceContainer i => GetOrLoad(ref instance, "Skybox Materials/SkyboxMaterialData"); |
| | 19 | |
|
| | 20 | | private static T GetOrLoad<T>(ref T variable, string path) where T : Object |
| | 21 | | { |
| 0 | 22 | | if (variable == null) |
| | 23 | | { |
| 0 | 24 | | variable = Resources.Load<T>(path); |
| | 25 | | } |
| | 26 | |
|
| 0 | 27 | | return variable; |
| | 28 | | } |
| | 29 | |
|
| | 30 | | public Mat_Layer[] materials; |
| | 31 | |
|
| | 32 | | public Material GetMaterialForLayers(int numOfLayer) |
| | 33 | | { |
| 0 | 34 | | for (int i = 0; i < materials.Length; i++) |
| | 35 | | { |
| 0 | 36 | | if (numOfLayer <= materials[i].numberOfSlots) |
| | 37 | | { |
| 0 | 38 | | return materials[i].material; |
| | 39 | | } |
| | 40 | | } |
| 0 | 41 | | return null; |
| | 42 | | } |
| | 43 | |
|
| | 44 | | public Mat_Layer GetMat_LayerForLayers(int numOfSlots) |
| | 45 | | { |
| 0 | 46 | | for (int i = 0; i < materials.Length; i++) |
| | 47 | | { |
| 0 | 48 | | if (numOfSlots <= materials[i].numberOfSlots) |
| | 49 | | { |
| 0 | 50 | | return materials[i]; |
| | 51 | | } |
| | 52 | | } |
| 0 | 53 | | return null; |
| | 54 | | } |
| | 55 | | } |
| | 56 | | } |