| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.Rendering; |
| | 8 | |
|
| | 9 | | /// <summary> |
| | 10 | | /// RenderProfileWorld allows us to toggle between several global rendering configuration presets. |
| | 11 | | /// This is useful for events, setting day/night cycles, lerping between any of those, etc. |
| | 12 | | /// |
| | 13 | | /// All the presets are stored in the RenderProfileManifest object. |
| | 14 | | /// </summary> |
| | 15 | | [CreateAssetMenu(menuName = "DCL/Rendering/Create World Profile", fileName = "RenderProfileWorld", order = 0)] |
| | 16 | | public class RenderProfileWorld : ScriptableObject |
| | 17 | | { |
| | 18 | | [Header("Loading Blocker")] public GameObject loadingBlockerPrefab; |
| | 19 | |
|
| | 20 | | [Header("Ambient And Reflection")] [SerializeField] |
| | 21 | | private Material skyboxMaterial; |
| | 22 | |
|
| | 23 | | [SerializeField] private Cubemap reflectionCubemap; |
| | 24 | | [SerializeField] private Color skyColor; |
| | 25 | | [SerializeField] private Color equatorColor; |
| | 26 | | [SerializeField] private Color groundColor; |
| | 27 | | [SerializeField] private Color fogColor; |
| | 28 | |
|
| | 29 | | [Header("Directional Light")] [SerializeField] |
| | 30 | | private Color directionalColorLight; |
| | 31 | |
|
| | 32 | | [SerializeField] private Vector3 directionalColorAngle; |
| | 33 | |
|
| | 34 | | [Header("Misc")] public RenderProfileAvatar avatarProfile; |
| | 35 | |
|
| | 36 | | #if UNITY_EDITOR |
| | 37 | | public bool fillWithRenderSettings; |
| | 38 | | public bool copyToRenderSettings; |
| | 39 | |
|
| | 40 | | //NOTE(Brian): Workaround to make an editor-time action. |
| | 41 | | // ContextMenu doesn't seem to work with ScriptableObjects. |
| | 42 | | private void OnValidate() |
| | 43 | | { |
| 3 | 44 | | if (fillWithRenderSettings) |
| | 45 | | { |
| 0 | 46 | | FillWithRenderSettings(); |
| | 47 | | } |
| | 48 | |
|
| 3 | 49 | | if (copyToRenderSettings) |
| | 50 | | { |
| 0 | 51 | | Apply(); |
| | 52 | | } |
| | 53 | |
|
| 3 | 54 | | fillWithRenderSettings = false; |
| 3 | 55 | | copyToRenderSettings = false; |
| | 56 | |
|
| 3 | 57 | | if (RenderProfileManifest.i.currentProfile == this) |
| | 58 | | { |
| 0 | 59 | | Apply(); |
| | 60 | | } |
| 3 | 61 | | } |
| | 62 | |
|
| | 63 | | public void FillWithRenderSettings() |
| | 64 | | { |
| 0 | 65 | | skyboxMaterial = RenderSettings.skybox; |
| 0 | 66 | | equatorColor = RenderSettings.ambientEquatorColor; |
| 0 | 67 | | skyColor = RenderSettings.ambientSkyColor; |
| 0 | 68 | | groundColor = RenderSettings.ambientGroundColor; |
| 0 | 69 | | fogColor = RenderSettings.fogColor; |
| | 70 | |
|
| 0 | 71 | | if (RenderSettings.sun != null) |
| | 72 | | { |
| 0 | 73 | | directionalColorLight = RenderSettings.sun.color; |
| 0 | 74 | | directionalColorAngle = RenderSettings.sun.transform.rotation.eulerAngles; |
| | 75 | | } |
| | 76 | |
|
| 0 | 77 | | reflectionCubemap = RenderSettings.customReflection; |
| 0 | 78 | | } |
| | 79 | | #endif |
| | 80 | |
|
| | 81 | | public void Apply(bool verbose = false) |
| | 82 | | { |
| 666 | 83 | | RenderSettings.ambientMode = AmbientMode.Trilight; |
| | 84 | |
|
| 666 | 85 | | RenderSettings.skybox = skyboxMaterial; |
| 666 | 86 | | RenderSettings.ambientEquatorColor = equatorColor; |
| 666 | 87 | | RenderSettings.ambientSkyColor = skyColor; |
| 666 | 88 | | RenderSettings.ambientGroundColor = groundColor; |
| | 89 | |
|
| 666 | 90 | | RenderSettings.fogColor = fogColor; |
| | 91 | |
|
| 666 | 92 | | if (RenderSettings.sun != null) |
| | 93 | | { |
| 666 | 94 | | RenderSettings.sun.color = directionalColorLight; |
| 666 | 95 | | RenderSettings.sun.transform.rotation = Quaternion.Euler(directionalColorAngle); |
| | 96 | | } |
| | 97 | |
|
| 666 | 98 | | RenderSettings.customReflection = reflectionCubemap; |
| | 99 | |
|
| 666 | 100 | | avatarProfile.Apply(); |
| | 101 | |
|
| 666 | 102 | | if (verbose) |
| 0 | 103 | | Debug.Log("Applying profile... " + name); |
| 666 | 104 | | } |
| | 105 | | } |