< Summary

Class:DCL.Skybox.SkyboxConfiguration
Assembly:ProceduralSkybox
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/ProceduralSkybox/ToolProceduralSkybox/Scripts/SkyboxConfiguration.cs
Covered lines:0
Uncovered lines:381
Coverable lines:381
Total lines:827
Line coverage:0% (0 of 381)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SkyboxConfiguration()0%2100%
ApplyOnMaterial(...)0%30500%
ApplyInWorldAvatarColor(...)0%72800%
ApplyEditorAvatarColor()0%2100%
ApplyAllSlots(...)0%20400%
GetActiveLayer(...)0%90900%
CheckAndFireTimelineEvents(...)0%2401500%
CycleResets()0%20400%
ApplyDLIntensity(...)0%20400%
ApplyDLDirection(...)0%56700%
ApplyTextureLayer(...)0%90900%
CheckFadingIn(...)0%12300%
CheckFadingOut(...)0%20400%
ApplyCubemapTextureLayer(...)0%12300%
ApplyPlanarTextureLayer(...)0%20400%
ApplySatelliteTextureLayer(...)0%6200%
ApplyParticleTextureLayer(...)0%2100%
GetTransitionValue(...)0%56700%
GetTransitionValue(...)0%56700%
GetTransitionValue(...)0%56700%
ResetMaterial(...)0%6200%
ResetSlot(...)0%2100%
Vector4ToQuaternion(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/ProceduralSkybox/ToolProceduralSkybox/Scripts/SkyboxConfiguration.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using DCL.Helpers;
 6
 7namespace DCL.Skybox
 8{
 9    //[CreateAssetMenu(fileName = "Skybox Configuration", menuName = "ScriptableObjects/SkyboxConfiguration", order = 1)
 10    public class SkyboxConfiguration : ScriptableObject
 11    {
 12        public delegate void TimelineEvents(string tag, bool enable, bool trigger);
 13        public event TimelineEvents OnTimelineEvent;
 14
 15        // ID
 16        public string skyboxID;
 17
 18        // Background Color
 019        public Gradient skyColor = new Gradient();
 020        public Gradient horizonColor = new Gradient();
 021        public Gradient groundColor = new Gradient();
 22
 23        // Horizon Layer
 024        public List<TransitioningFloat> horizonWidth = new List<TransitioningFloat>();
 025        public List<TransitioningFloat> horizonHeight = new List<TransitioningFloat>();
 26        public Texture2D horizonMask;
 027        public Vector3 horizonMaskValues = new Vector3(0, 0, 0);
 028        public Gradient horizonPlaneColor = new Gradient();
 029        public List<TransitioningFloat> horizonPlaneHeight = new List<TransitioningFloat>();
 30
 31        // Ambient Color
 032        public bool ambientTrilight = true;
 033        public Gradient ambientSkyColor = new Gradient();
 034        public Gradient ambientEquatorColor = new Gradient();
 035        public Gradient ambientGroundColor = new Gradient();
 36
 37        // Avatar Color
 038        public bool useAvatarGradient = true;
 039        public Gradient avatarTintGradient = new Gradient();
 040        public Color avatarTintColor = Color.white;
 041        public bool useAvatarRealtimeDLDirection = true;
 042        public Vector3 avatarLightConstantDir = new Vector3(-18f, 144f, -72f);
 043        public bool useAvatarRealtimeLightColor = true;
 044        public Gradient avatarLightColorGradient = new Gradient();
 45
 46        // Avatar Editor Color
 047        public Color avatarEditorTintColor = Color.white;
 048        public Vector3 avatarEditorLightDir = new Vector3(-18f, 144f, -72f);
 049        public Color avatarEditorLightColor = Color.white;
 50
 51        // Fog Properties
 52        public bool useFog = false;
 053        public FogMode fogMode = FogMode.ExponentialSquared;
 054        public Gradient fogColor = new Gradient();
 055        public float fogDensity = 0.05f;
 56        public float fogStartDistance = 0;
 057        public float fogEndDistance = 300;
 58
 59        // DirectionalLight Properties
 060        public bool useDirectionalLight = true;
 061        public DirectionalLightAttributes directionalLightLayer = new DirectionalLightAttributes();
 62
 63        // Layers
 064        public List<TextureLayer> layers = new List<TextureLayer>();
 65
 66        // Timeline Tags
 067        public List<TimelineTagsDuration> timelineTags = new List<TimelineTagsDuration>();
 68
 069        private float cycleTime = 24;
 70
 71        public void ApplyOnMaterial(Material selectedMat, float dayTime, float normalizedDayTime, int slotCount = 5, Lig
 72        {
 073            float percentage = normalizedDayTime * 100;
 74
 75            // General Values
 076            selectedMat.SetColor(SkyboxShaderUtils.LightTint, directionalLightLayer.tintColor.Evaluate(normalizedDayTime
 077            selectedMat.SetVector(SkyboxShaderUtils.LightDirection, directionalLightGO.transform.rotation.eulerAngles);
 78
 79            // Apply Base Values
 080            selectedMat.SetColor(SkyboxShaderUtils.SkyColor, skyColor.Evaluate(normalizedDayTime));
 081            selectedMat.SetColor(SkyboxShaderUtils.GroundColor, groundColor.Evaluate(normalizedDayTime));
 82
 83            // Apply Horizon Values
 084            selectedMat.SetColor(SkyboxShaderUtils.HorizonColor, horizonColor.Evaluate(normalizedDayTime));
 085            selectedMat.SetFloat(SkyboxShaderUtils.HorizonHeight, GetTransitionValue(horizonHeight, percentage, 0f));
 086            selectedMat.SetFloat(SkyboxShaderUtils.HorizonWidth, GetTransitionValue(horizonWidth, percentage, 0f));
 087            selectedMat.SetTexture(SkyboxShaderUtils.HorizonMask, horizonMask);
 088            selectedMat.SetVector(SkyboxShaderUtils.HorizonMaskValues, horizonMaskValues);
 089            selectedMat.SetColor(SkyboxShaderUtils.HorizonPlaneColor, horizonPlaneColor.Evaluate(normalizedDayTime));
 090            selectedMat.SetFloat(SkyboxShaderUtils.HorizonPlaneHeight, GetTransitionValue(horizonPlaneHeight, percentage
 91
 92
 93            // Apply Ambient colors to the rendering settings
 094            if (ambientTrilight)
 95            {
 096                RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Trilight;
 097                RenderSettings.ambientSkyColor = ambientSkyColor.Evaluate(normalizedDayTime);
 098                RenderSettings.ambientEquatorColor = ambientEquatorColor.Evaluate(normalizedDayTime);
 099                RenderSettings.ambientGroundColor = ambientGroundColor.Evaluate(normalizedDayTime);
 0100            }
 101            else
 102            {
 0103                RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox;
 104            }
 105
 106            //Fog Values
 0107            RenderSettings.fog = useFog;
 0108            if (useFog)
 109            {
 0110                RenderSettings.fogColor = fogColor.Evaluate(normalizedDayTime);
 0111                RenderSettings.fogMode = fogMode;
 0112                switch (fogMode)
 113                {
 114                    case FogMode.Linear:
 0115                        RenderSettings.fogStartDistance = fogStartDistance;
 0116                        RenderSettings.fogEndDistance = fogEndDistance;
 0117                        break;
 118                    default:
 0119                        RenderSettings.fogDensity = fogDensity;
 120                        break;
 121                }
 122            }
 123
 124            //Directional List
 0125            if (useDirectionalLight)
 126            {
 127                // Apply Direction light color
 0128                directionalLightGO.color = directionalLightLayer.lightColor.Evaluate(normalizedDayTime);
 129
 130                // Apply direction
 0131                ApplyDLDirection(normalizedDayTime, directionalLightGO);
 132
 133                // Apply Intensity
 0134                ApplyDLIntensity(normalizedDayTime, directionalLightGO);
 0135            }
 136            else
 137            {
 0138                directionalLightGO.gameObject.SetActive(false);
 139            }
 140
 141            // Check and Fire timeline events
 0142            CheckAndFireTimelineEvents(dayTime);
 143
 0144            ApplyAllSlots(selectedMat, dayTime, normalizedDayTime, slotCount, cycleTime);
 0145        }
 146
 147        public void ApplyInWorldAvatarColor(float normalizedDayTime, GameObject directionalLightGO)
 148        {
 0149            if (useAvatarGradient)
 150            {
 0151                Shader.SetGlobalColor(ShaderUtils.TintColor, avatarTintGradient.Evaluate(normalizedDayTime));
 0152            }
 153            else
 154            {
 0155                Shader.SetGlobalColor(ShaderUtils.TintColor, avatarTintColor);
 156            }
 157
 158            // Apply Avatar Light Direction
 0159            if (!useAvatarRealtimeDLDirection || directionalLightGO == null || !useDirectionalLight)
 160            {
 0161                Shader.SetGlobalVector(ShaderUtils.LightDir, avatarLightConstantDir / 180);
 0162            }
 163            else
 164            {
 0165                Vector3 tempDir = directionalLightGO.transform.rotation.eulerAngles;
 0166                Shader.SetGlobalVector(ShaderUtils.LightDir, tempDir / 180);
 167            }
 168
 169            // Apply Avatar Light Color
 0170            if (!useAvatarRealtimeLightColor || directionalLightGO == null || !useDirectionalLight)
 171            {
 0172                Shader.SetGlobalColor(ShaderUtils.LightColor, avatarLightColorGradient.Evaluate(normalizedDayTime));
 0173            }
 174            else
 175            {
 0176                Shader.SetGlobalColor(ShaderUtils.LightColor, directionalLightLayer.lightColor.Evaluate(normalizedDayTim
 177            }
 0178        }
 179
 180        public void ApplyEditorAvatarColor()
 181        {
 0182            Shader.SetGlobalColor(ShaderUtils.TintColor, avatarEditorTintColor);
 0183            Shader.SetGlobalVector(ShaderUtils.LightDir, avatarEditorLightDir / 180);
 0184            Shader.SetGlobalColor(ShaderUtils.LightColor, avatarEditorLightColor);
 0185        }
 186
 187        void ApplyAllSlots(Material selectedMat, float dayTime, float normalizedDayTime, int slotCount = 5, float cycleT
 188        {
 0189            for (int i = 0; i < slotCount; i++)
 190            {
 0191                TextureLayer layer = GetActiveLayer(dayTime, i);
 192
 0193                if (layer == null || !layer.enabled)
 194                {
 0195                    ResetSlot(selectedMat, i);
 0196                    continue;
 197                }
 198
 0199                ApplyTextureLayer(selectedMat, dayTime, normalizedDayTime, i, layer, cycleTime);
 200            }
 0201        }
 202
 203        public TextureLayer GetActiveLayer(float currentTime, int slotID)
 204        {
 0205            TextureLayer temp = null;
 206
 0207            for (int i = 0; i < layers.Count; i++)
 208            {
 0209                if (layers[i].slotID != slotID)
 210                {
 211                    continue;
 212                }
 213
 0214                float endTimeEdited = layers[i].timeSpan_End;
 0215                float dayTimeEdited = currentTime;
 216
 0217                if (layers[i].timeSpan_End < layers[i].timeSpan_start)
 218                {
 0219                    endTimeEdited = cycleTime + layers[i].timeSpan_End;
 0220                    if (currentTime < layers[i].timeSpan_start)
 221                    {
 0222                        dayTimeEdited = cycleTime + currentTime;
 223                    }
 224                }
 225
 0226                if (dayTimeEdited >= layers[i].timeSpan_start && dayTimeEdited <= endTimeEdited)
 227                {
 0228                    if (layers[i].enabled)
 229                    {
 0230                        if (temp == null)
 231                        {
 0232                            layers[i].renderType = LayerRenderType.Rendering;
 0233                            temp = layers[i];
 0234                        }
 235                        else
 236                        {
 0237                            temp.renderType = LayerRenderType.Conflict_Playing;
 0238                            layers[i].renderType = LayerRenderType.Conflict_NotPlaying;
 239                        }
 0240                    }
 241                    else
 242                    {
 0243                        layers[i].renderType = LayerRenderType.NotRendering;
 244                    }
 0245                }
 246                else
 247                {
 0248                    layers[i].renderType = LayerRenderType.NotRendering;
 249                }
 250
 251
 252            }
 0253            return temp;
 254        }
 255
 256        #region Timeline Events
 257
 258        /// <summary>
 259        /// Check if any event has to be fired
 260        /// TODO:: Can be optimised.
 261        /// </summary>
 262        /// <param name="dayTime">Current day time</param>
 263        private void CheckAndFireTimelineEvents(float dayTime)
 264        {
 0265            float endTimeEdited = 0;
 0266            float dayTimeEdited = dayTime;
 0267            for (int i = 0; i < timelineTags.Count; i++)
 268            {
 269                // If current event is a trigger event, fire trigger event. It's boolean will be disable when cycle rese
 0270                if (timelineTags[i].isTrigger)
 271                {
 0272                    if (dayTime > timelineTags[i].startTime && !timelineTags[i].startEventExecuted)
 273                    {
 0274                        OnTimelineEvent?.Invoke(timelineTags[i].tag, true, true);
 0275                        timelineTags[i].startEventExecuted = true;
 276                    }
 0277                    continue;
 278                }
 279
 280
 0281                endTimeEdited = timelineTags[i].endTime;
 0282                dayTimeEdited = dayTime;
 283
 284                // Change time if this is over a day scenario
 0285                if (timelineTags[i].endTime < timelineTags[i].startTime)
 286                {
 0287                    endTimeEdited = cycleTime + timelineTags[i].endTime;
 288
 0289                    if (dayTime < timelineTags[i].startTime)
 290                    {
 0291                        dayTimeEdited = cycleTime + dayTime;
 292                    }
 293                }
 294
 295                // If current time is between start and end time and start event is not executed, Fire start event
 0296                if (dayTimeEdited >= timelineTags[i].startTime && dayTimeEdited < endTimeEdited && !timelineTags[i].star
 297                {
 0298                    OnTimelineEvent?.Invoke(timelineTags[i].tag, true, false);
 0299                    timelineTags[i].startEventExecuted = true;
 300                }
 301
 302                // If current time is greater than end time and start event is executed, fire end event
 0303                if (dayTimeEdited >= endTimeEdited && timelineTags[i].startEventExecuted)
 304                {
 0305                    OnTimelineEvent?.Invoke(timelineTags[i].tag, false, false);
 0306                    timelineTags[i].startEventExecuted = false;
 307                }
 308
 309            }
 0310        }
 311
 312        public void CycleResets()
 313        {
 314            // Resets all timeline triggers and normal flow events
 0315            for (int i = 0; i < timelineTags.Count; i++)
 316            {
 0317                if (timelineTags[i].isTrigger)
 318                {
 0319                    timelineTags[i].startEventExecuted = false;
 0320                    continue;
 321                }
 322
 0323                if (timelineTags[i].endTime > timelineTags[i].startTime)
 324                {
 0325                    timelineTags[i].startEventExecuted = false;
 326                }
 327            }
 0328        }
 329
 330        #endregion
 331
 332        #region Directional Light
 333
 334        void ApplyDLIntensity(float normalizedDayTime, Light lightGO)
 335        {
 0336            if (lightGO == null)
 337            {
 0338                Debug.LogError("Directional Light option is on, with light reference");
 0339                return;
 340            }
 341
 0342            if (directionalLightLayer.intensity.Count == 0)
 343            {
 0344                Debug.Log("Directional Light option is on with no intensity data");
 0345                return;
 346            }
 347
 0348            if (directionalLightLayer.intensity.Count == 1)
 349            {
 0350                lightGO.intensity = directionalLightLayer.intensity[0].value;
 0351                return;
 352            }
 353
 354
 0355            lightGO.intensity = GetTransitionValue(directionalLightLayer.intensity, normalizedDayTime * 100);
 0356        }
 357
 358        void ApplyDLDirection(float normalizedDayTime, Light lightGO)
 359        {
 0360            if (lightGO == null)
 361            {
 0362                Debug.LogError("Directional Light option is on, with light reference");
 0363                return;
 364            }
 365
 0366            if (directionalLightLayer.lightDirection.Count == 0)
 367            {
 0368                Debug.Log("Directional Light option is on with no rotation data");
 0369                return;
 370            }
 371
 0372            if (directionalLightLayer.lightDirection.Count == 1)
 373            {
 0374                lightGO.transform.rotation = directionalLightLayer.lightDirection[0].value;
 0375                return;
 376            }
 377
 0378            float percentage = normalizedDayTime * 100;
 0379            TransitioningQuaternion min = directionalLightLayer.lightDirection[0], max = directionalLightLayer.lightDire
 380
 381            // Apply Direction
 0382            for (int i = 0; i < directionalLightLayer.lightDirection.Count; i++)
 383            {
 0384                if (percentage <= directionalLightLayer.lightDirection[i].percentage)
 385                {
 0386                    max = directionalLightLayer.lightDirection[i];
 387
 0388                    if ((i - 1) > 0)
 389                    {
 0390                        min = directionalLightLayer.lightDirection[i - 1];
 391                    }
 392
 0393                    break;
 394                }
 395            }
 396
 0397            float t = Mathf.InverseLerp(min.percentage, max.percentage, percentage);
 0398            lightGO.transform.rotation = Quaternion.Lerp(min.value, max.value, t);
 0399        }
 400
 401        #endregion
 402
 403        #region Apply texture layers
 404
 405        void ApplyTextureLayer(Material selectedMat, float dayTime, float normalizedDayTime, int slotNum, TextureLayer l
 406        {
 0407            float endTimeEdited = layer.timeSpan_End;
 0408            float dayTimeEdited = dayTime;
 0409            if (layer.timeSpan_End < layer.timeSpan_start)
 410            {
 0411                endTimeEdited = cycleTime + layer.timeSpan_End;
 0412                if (dayTime < layer.timeSpan_start)
 413                {
 0414                    dayTimeEdited = cycleTime + dayTime;
 415                }
 416            }
 0417            float normalizedLayerTime = Mathf.InverseLerp(layer.timeSpan_start, endTimeEdited, dayTimeEdited);
 418
 0419            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_layerType_" + slotNum), (int)layer.layerType);
 420
 0421            bool fadeInChange = CheckFadingIn(selectedMat, dayTime, normalizedDayTime, slotNum, layer, cycleTime);
 422
 0423            bool fadeOutChange = CheckFadingOut(selectedMat, dayTime, normalizedDayTime, slotNum, layer, cycleTime);
 424
 0425            if (!fadeInChange && !fadeOutChange)
 426            {
 0427                selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_fadeTime_" + slotNum), 1);
 428            }
 429
 0430            switch (layer.layerType)
 431            {
 432                case LayerType.Planar:
 433                case LayerType.Radial:
 0434                    ApplyPlanarTextureLayer(selectedMat, dayTime, normalizedLayerTime, slotNum, layer, true);
 0435                    break;
 436                case LayerType.Satellite:
 0437                    ApplySatelliteTextureLayer(selectedMat, dayTime, normalizedLayerTime, slotNum, layer, true);
 0438                    break;
 439                case LayerType.Cubemap:
 0440                    ApplyCubemapTextureLayer(selectedMat, dayTime, normalizedLayerTime, slotNum, layer, true);
 0441                    break;
 442                case LayerType.Particles:
 0443                    ApplyParticleTextureLayer(selectedMat, dayTime, normalizedLayerTime, slotNum, layer, true);
 444                    break;
 445                default:
 446                    break;
 447            }
 0448        }
 449
 450        private bool CheckFadingIn(Material selectedMat, float dayTime, float normalizedDayTime, int slotNum, TextureLay
 451        {
 0452            bool fadeChanged = false;
 0453            float fadeInCompletionTime = layer.timeSpan_start + layer.fadingInTime;
 0454            float dayTimeEdited = dayTime;
 0455            if (dayTime < layer.timeSpan_start)
 456            {
 0457                dayTimeEdited = 24 + dayTime;
 458            }
 459
 0460            if (dayTimeEdited < fadeInCompletionTime)
 461            {
 0462                float percentage = Mathf.InverseLerp(layer.timeSpan_start, fadeInCompletionTime, dayTimeEdited);
 0463                fadeChanged = true;
 0464                selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_fadeTime_" + slotNum), percentage);
 465            }
 466
 0467            return fadeChanged;
 468        }
 469
 470        private bool CheckFadingOut(Material selectedMat, float dayTime, float normalizedDayTime, int slotNum, TextureLa
 471        {
 0472            bool fadeChanged = false;
 0473            float endTimeEdited = layer.timeSpan_End;
 0474            float dayTimeEdited = dayTime;
 475
 0476            if (layer.timeSpan_End < layer.timeSpan_start)
 477            {
 0478                endTimeEdited = cycleTime + layer.timeSpan_End;
 479            }
 480
 0481            if (dayTime < layer.timeSpan_start)
 482            {
 0483                dayTimeEdited = cycleTime + dayTime;
 484            }
 485
 486
 0487            float fadeOutStartTime = endTimeEdited - layer.fadingOutTime;
 488
 0489            if (dayTimeEdited > fadeOutStartTime)
 490            {
 0491                float percentage = Mathf.InverseLerp(endTimeEdited, fadeOutStartTime, dayTimeEdited);
 0492                fadeChanged = true;
 0493                selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_fadeTime_" + slotNum), percentage);
 494            }
 495
 0496            return fadeChanged;
 497        }
 498
 499        void ApplyCubemapTextureLayer(Material selectedMat, float dayTime, float normalizedLayerTime, int layerNum, Text
 500        {
 0501            if (changeAlllValues)
 502            {
 0503                selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_RenderDistance_" + layerNum), 0);
 0504                selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_tex_" + layerNum), null);
 0505                selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_cubemap_" + layerNum), layer.cubemap);
 0506                selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_normals_" + layerNum), null);
 0507                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_timeFrame_" + layerNum), new Vector4(layer.ti
 0508                selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_lightIntensity_" + layerNum), layer.tintPercen
 0509                selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_normalIntensity_" + layerNum), 0);
 0510                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortIntAndSize_" + layerNum), Vector2.zero
 0511                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortSpeedAndSharp_" + layerNum), Vector4.z
 512                // Particles
 0513                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_rowAndCollumns_" + layerNum), Vector2.zero);
 0514                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesMainParameters_" + layerNum), Vector
 0515                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesSecondaryParameters_" + layerNum), V
 516            }
 517
 518
 0519            selectedMat.SetColor(SkyboxShaderUtils.GetLayerProperty("_color_" + layerNum), layer.color.Evaluate(normaliz
 520
 521            // Set cubemap rotation. (Shader variable reused)
 0522            if (layer.movementTypeCubemap == MovementType.PointBased)
 523            {
 0524                Vector3 currentRotation = GetTransitionValue(layer.rotations_Vector3, normalizedLayerTime * 100);
 0525                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), new Vector4(cu
 0526                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(0
 0527            }
 528            else
 529            {
 0530                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), new Vector4(0,
 0531                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(l
 532            }
 533
 0534        }
 535
 536        void ApplyPlanarTextureLayer(Material selectedMat, float dayTime, float normalizedLayerTime, int layerNum, Textu
 537        {
 0538            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_RenderDistance_" + layerNum), GetTransitionValue(l
 0539            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_tex_" + layerNum), layer.texture);
 0540            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_normals_" + layerNum), layer.textureNormal);
 0541            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_cubemap_" + layerNum), null);
 542
 0543            selectedMat.SetColor(SkyboxShaderUtils.GetLayerProperty("_color_" + layerNum), layer.color.Evaluate(normaliz
 544
 545
 0546            if (layer.movementTypePlanar_Radial == MovementType.Speed)
 547            {
 548                // speed and Rotation
 0549                float rot = 0;
 0550                if (layer.layerType == LayerType.Planar)
 551                {
 0552                    rot = GetTransitionValue(layer.rotations_float, normalizedLayerTime * 100);
 553                }
 554
 0555                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(l
 556
 557                // Tiling and Offset
 0558                Vector4 t = new Vector4(layer.tiling.x, layer.tiling.y, 0, 0);
 0559                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), t);
 0560            }
 561            else
 562            {
 563                // speed and Rotation
 0564                float rot = 0;
 0565                if (layer.layerType == LayerType.Planar)
 566                {
 0567                    rot = GetTransitionValue(layer.rotations_float, normalizedLayerTime * 100);
 568                }
 569
 0570                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(0
 571
 572                // Tiling and Offset
 0573                Vector2 currentOffset = GetTransitionValue(layer.offset, normalizedLayerTime * 100);
 0574                Vector4 t = new Vector4(layer.tiling.x, layer.tiling.y, currentOffset.x, currentOffset.y);
 0575                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), t);
 576            }
 577
 578
 579            // Time frame
 0580            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_timeFrame_" + layerNum), new Vector4(layer.timeSp
 581            // normal intensity
 0582            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_normalIntensity_" + layerNum), layer.normalIntensi
 583            // Tint
 0584            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_lightIntensity_" + layerNum), layer.tintPercentage
 585
 586            // Reset Particle related Params
 0587            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_rowAndCollumns_" + layerNum), layer.flipbookRowsA
 0588            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesMainParameters_" + layerNum), new Vector
 0589            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesSecondaryParameters_" + layerNum), Vecto
 590
 591            // Apply Distortion Values
 0592            Vector2 distortIntAndSize = new Vector2(GetTransitionValue(layer.distortIntensity, normalizedLayerTime * 100
 0593            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortIntAndSize_" + layerNum), distortIntAndSiz
 594
 0595            Vector2 distortSpeed = GetTransitionValue(layer.distortSpeed, normalizedLayerTime * 100);
 0596            Vector2 distortSharpness = GetTransitionValue(layer.distortSharpness, normalizedLayerTime * 100);
 0597            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortSpeedAndSharp_" + layerNum), new Vector4(d
 0598        }
 599
 600        void ApplySatelliteTextureLayer(Material selectedMat, float dayTime, float normalizedLayerTime, int layerNum, Te
 601        {
 0602            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_tex_" + layerNum), layer.texture);
 0603            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_normals_" + layerNum), layer.textureNormal);
 0604            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_cubemap_" + layerNum), null);
 605
 0606            selectedMat.SetColor(SkyboxShaderUtils.GetLayerProperty("_color_" + layerNum), layer.color.Evaluate(normaliz
 607
 0608            if (layer.movementTypeSatellite == MovementType.Speed)
 609            {
 610                // Tiling and Offset
 0611                Vector2 currentWidthHeight = GetTransitionValue(layer.satelliteWidthHeight, normalizedLayerTime * 100, n
 0612                Vector4 t = new Vector4(currentWidthHeight.x, currentWidthHeight.y, 0, 0);
 0613                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), t);
 614
 615
 616                // speed and Rotation
 0617                float rot = GetTransitionValue(layer.rotations_float, normalizedLayerTime * 100);
 0618                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(l
 0619            }
 620            else
 621            {
 622                // Tiling and Offset
 0623                Vector2 currentOffset = GetTransitionValue(layer.offset, normalizedLayerTime * 100);
 0624                Vector2 currentWidthHeight = GetTransitionValue(layer.satelliteWidthHeight, normalizedLayerTime * 100, n
 0625                Vector4 t = new Vector4(currentWidthHeight.x, currentWidthHeight.y, currentOffset.x, currentOffset.y);
 0626                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), t);
 627
 628                // speed and Rotation
 0629                float rot = GetTransitionValue(layer.rotations_float, normalizedLayerTime * 100);
 0630                selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), new Vector4(0
 631            }
 632
 633            // Time frame
 0634            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_timeFrame_" + layerNum), new Vector4(layer.timeSp
 635            // normal intensity
 0636            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_normalIntensity_" + layerNum), layer.normalIntensi
 637            // Tint
 0638            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_lightIntensity_" + layerNum), layer.tintPercentage
 639
 640            // Reset Particle related Params
 0641            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_rowAndCollumns_" + layerNum), layer.flipbookRowsA
 0642            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesMainParameters_" + layerNum), new Vector
 0643            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesSecondaryParameters_" + layerNum), Vecto
 644
 645            // Reset Distortion values
 0646            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortIntAndSize_" + layerNum), Vector2.zero);
 0647            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortSpeedAndSharp_" + layerNum), Vector4.zero)
 648
 0649        }
 650
 651        void ApplyParticleTextureLayer(Material selectedMat, float dayTime, float normalizedLayerTime, int layerNum, Tex
 652        {
 653            // Reset Unused params
 0654            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_RenderDistance_" + layerNum), 0);
 0655            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_cubemap_" + layerNum), null);
 0656            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortIntAndSize_" + layerNum), Vector2.zero);
 0657            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortSpeedAndSharp_" + layerNum), Vector4.zero)
 658
 659
 660            // Time frame
 0661            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_timeFrame_" + layerNum), new Vector4(layer.timeSp
 662            // Tint
 0663            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_lightIntensity_" + layerNum), layer.tintPercentage
 664
 665            // Particles
 0666            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_tex_" + layerNum), layer.texture);
 0667            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_normals_" + layerNum), layer.textureNormal);
 0668            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_normalIntensity_" + layerNum), layer.normalIntensi
 0669            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_rowAndCollumns_" + layerNum), layer.flipbookRowsA
 0670            selectedMat.SetColor(SkyboxShaderUtils.GetLayerProperty("_color_" + layerNum), layer.color.Evaluate(normaliz
 0671            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + layerNum), new Vector4(layer.
 0672            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + layerNum), GetTransitionValu
 0673            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesMainParameters_" + layerNum), new Vector
 0674            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesSecondaryParameters_" + layerNum), new V
 675
 676
 0677        }
 678
 679        #endregion
 680
 681        #region Transition Values Utility Methods
 682
 683        float GetTransitionValue(List<TransitioningFloat> list, float percentage, float defaultVal = 0)
 684        {
 0685            if (list == null || list.Count < 1)
 686            {
 0687                return defaultVal;
 688            }
 689
 0690            if (list.Count == 1)
 691            {
 0692                return list[0].value;
 693            }
 694
 0695            TransitioningFloat min = list[0], max = list[0];
 696
 697
 0698            for (int i = 0; i < list.Count; i++)
 699            {
 0700                if (percentage <= list[i].percentage)
 701                {
 0702                    max = list[i];
 703
 0704                    if ((i - 1) > 0)
 705                    {
 0706                        min = list[i - 1];
 707                    }
 708
 0709                    break;
 710                }
 711            }
 712
 0713            float t = Mathf.InverseLerp(min.percentage, max.percentage, percentage);
 0714            return Mathf.Lerp(min.value, max.value, t);
 715        }
 716
 717        Vector2 GetTransitionValue(List<TransitioningVector2> list, float percentage, Vector2 defaultVal = default(Vecto
 718        {
 0719            Vector2 offset = defaultVal;
 720
 0721            if (list == null || list.Count == 0)
 722            {
 0723                return offset;
 724            }
 725
 0726            if (list.Count == 1)
 727            {
 0728                offset = list[0].value;
 0729                return offset;
 730            }
 731
 732
 0733            TransitioningVector2 min = list[0], max = list[0];
 734
 0735            for (int i = 0; i < list.Count; i++)
 736            {
 0737                if (percentage <= list[i].percentage)
 738                {
 0739                    max = list[i];
 740
 0741                    if ((i - 1) > 0)
 742                    {
 0743                        min = list[i - 1];
 744                    }
 745
 0746                    break;
 747                }
 748            }
 0749            float t = Mathf.InverseLerp(min.percentage, max.percentage, percentage);
 0750            offset = Vector2.Lerp(min.value, max.value, t);
 751
 0752            return offset;
 753        }
 754
 755        Vector3 GetTransitionValue(List<TransitioningVector3> list, float percentage)
 756        {
 0757            Vector3 offset = new Vector3(0, 0, 0);
 758
 0759            if (list == null || list.Count == 0)
 760            {
 0761                return offset;
 762            }
 763
 0764            if (list.Count == 1)
 765            {
 0766                offset = list[0].value;
 0767                return offset;
 768            }
 769
 770
 0771            TransitioningVector3 min = list[0], max = list[0];
 772
 0773            for (int i = 0; i < list.Count; i++)
 774            {
 0775                if (percentage <= list[i].percentage)
 776                {
 0777                    max = list[i];
 778
 0779                    if ((i - 1) > 0)
 780                    {
 0781                        min = list[i - 1];
 782                    }
 783
 0784                    break;
 785                }
 786            }
 787
 0788            float t = Mathf.InverseLerp(min.percentage, max.percentage, percentage);
 0789            offset = Vector3.Lerp(min.value, max.value, t);
 790
 0791            return offset;
 792        }
 793
 794        #endregion
 795
 796        public void ResetMaterial(Material selectedMat, int slotCount)
 797        {
 0798            for (int i = 0; i < slotCount; i++)
 799            {
 0800                ResetSlot(selectedMat, i);
 801            }
 0802        }
 803
 804        public void ResetSlot(Material selectedMat, int slotCount)
 805        {
 0806            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_layerType_" + slotCount), 0);
 0807            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_tex_" + slotCount), null);
 0808            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_cubemap_" + slotCount), null);
 0809            selectedMat.SetTexture(SkyboxShaderUtils.GetLayerProperty("_normals_" + slotCount), null);
 0810            selectedMat.SetColor(SkyboxShaderUtils.GetLayerProperty("_color_" + slotCount), new Color(1, 1, 1, 0));
 0811            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_tilingAndOffset_" + slotCount), new Vector4(1, 1,
 0812            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_speedAndRotation_" + slotCount), new Vector4(0, 0
 0813            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_timeFrame_" + slotCount), new Vector4(0, 0));
 0814            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_fadeTime_" + slotCount), 1);
 0815            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_normalIntensity_" + slotCount), 0);
 0816            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_lightIntensity_" + slotCount), 0);
 0817            selectedMat.SetFloat(SkyboxShaderUtils.GetLayerProperty("_RenderDistance_" + slotCount), 3.4f);
 0818            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortIntAndSize_" + slotCount), new Vector2(0, 
 0819            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_distortSpeedAndSharp_" + slotCount), new Vector4(
 0820            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_rowAndCollumns_" + slotCount), new Vector4(1, 1))
 0821            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesMainParameters_" + slotCount), new Vecto
 0822            selectedMat.SetVector(SkyboxShaderUtils.GetLayerProperty("_particlesSecondaryParameters_" + slotCount), new 
 0823        }
 824
 0825        Quaternion Vector4ToQuaternion(Vector4 val) { return new Quaternion(val.x, val.y, val.z, val.w); }
 826    }
 827}

Methods/Properties

SkyboxConfiguration()
ApplyOnMaterial(UnityEngine.Material, System.Single, System.Single, System.Int32, UnityEngine.Light, System.Single)
ApplyInWorldAvatarColor(System.Single, UnityEngine.GameObject)
ApplyEditorAvatarColor()
ApplyAllSlots(UnityEngine.Material, System.Single, System.Single, System.Int32, System.Single)
GetActiveLayer(System.Single, System.Int32)
CheckAndFireTimelineEvents(System.Single)
CycleResets()
ApplyDLIntensity(System.Single, UnityEngine.Light)
ApplyDLDirection(System.Single, UnityEngine.Light)
ApplyTextureLayer(UnityEngine.Material, System.Single, System.Single, System.Int32, DCL.Skybox.TextureLayer, System.Single, System.Boolean)
CheckFadingIn(UnityEngine.Material, System.Single, System.Single, System.Int32, DCL.Skybox.TextureLayer, System.Single, System.Boolean)
CheckFadingOut(UnityEngine.Material, System.Single, System.Single, System.Int32, DCL.Skybox.TextureLayer, System.Single, System.Boolean)
ApplyCubemapTextureLayer(UnityEngine.Material, System.Single, System.Single, System.Int32, DCL.Skybox.TextureLayer, System.Boolean)
ApplyPlanarTextureLayer(UnityEngine.Material, System.Single, System.Single, System.Int32, DCL.Skybox.TextureLayer, System.Boolean)
ApplySatelliteTextureLayer(UnityEngine.Material, System.Single, System.Single, System.Int32, DCL.Skybox.TextureLayer, System.Boolean)
ApplyParticleTextureLayer(UnityEngine.Material, System.Single, System.Single, System.Int32, DCL.Skybox.TextureLayer, System.Boolean)
GetTransitionValue(System.Collections.Generic.List[TransitioningFloat], System.Single, System.Single)
GetTransitionValue(System.Collections.Generic.List[TransitioningVector2], System.Single, UnityEngine.Vector2)
GetTransitionValue(System.Collections.Generic.List[TransitioningVector3], System.Single)
ResetMaterial(UnityEngine.Material, System.Int32)
ResetSlot(UnityEngine.Material, System.Int32)
Vector4ToQuaternion(UnityEngine.Vector4)