| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.Serialization; |
| | 7 | |
|
| | 8 | | namespace DCL |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// This ScriptableObject is used to control toon shader and avatar rendering values |
| | 12 | | /// assigned to any RenderProfileWorld. |
| | 13 | | /// |
| | 14 | | /// Values can change depending if we are in avatar editor mode or in-game world. |
| | 15 | | /// </summary> |
| | 16 | | [CreateAssetMenu(menuName = "DCL/Rendering/Create Avatar Profile", fileName = "RenderProfileAvatar", order = 0)] |
| | 17 | | public class RenderProfileAvatar : ScriptableObject |
| | 18 | | { |
| | 19 | | [System.Serializable] |
| | 20 | | public class MaterialProfile |
| | 21 | | { |
| | 22 | | [SerializeField] internal Color tintColor; |
| | 23 | | [SerializeField] internal Color lightColor; |
| | 24 | | [SerializeField] internal Vector3 lightDirection; |
| | 25 | | } |
| | 26 | |
|
| | 27 | | [NonSerialized] public MaterialProfile currentProfile; |
| | 28 | |
|
| | 29 | | public MaterialProfile avatarEditor; |
| | 30 | |
|
| | 31 | | public MaterialProfile inWorld; |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Applies the material profile. |
| | 35 | | /// </summary> |
| | 36 | | /// <param name="targetMaterial">If target material is null, the properties will be applied globally.</param> |
| | 37 | | public void Apply(Material targetMaterial = null) |
| | 38 | | { |
| 746 | 39 | | if (currentProfile == null) |
| 0 | 40 | | currentProfile = inWorld; |
| | 41 | |
|
| 746 | 42 | | if (targetMaterial != null) |
| | 43 | | { |
| 0 | 44 | | targetMaterial.SetVector(ShaderUtils.LightDir, currentProfile.lightDirection); |
| 0 | 45 | | targetMaterial.SetColor(ShaderUtils.LightColor, currentProfile.lightColor); |
| 0 | 46 | | targetMaterial.SetColor(ShaderUtils.TintColor, currentProfile.tintColor); |
| 0 | 47 | | return; |
| | 48 | | } |
| | 49 | |
|
| 746 | 50 | | Shader.SetGlobalVector(ShaderUtils.LightDir, currentProfile.lightDirection); |
| 746 | 51 | | Shader.SetGlobalColor(ShaderUtils.LightColor, currentProfile.lightColor); |
| 746 | 52 | | Shader.SetGlobalColor(ShaderUtils.TintColor, currentProfile.tintColor); |
| 746 | 53 | | } |
| | 54 | | } |
| | 55 | | } |