< Summary

Class:DCL.Skybox.SkyboxEditorWindow_v2
Assembly:SkyboxEditorAssembly
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/ProceduralSkybox/ToolProceduralSkybox/Scripts/Editor/Procedural Skybox/SkyboxEditor_v2.cs
Covered lines:0
Uncovered lines:317
Coverable lines:317
Total lines:661
Line coverage:0% (0 of 317)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SkyboxEditorWindow_v2()0%2100%
Init()0%2100%
Initialize()0%2100%
InitializeWindow()0%2100%
Update()0%20400%
OnGUI()0%6200%
RenderPinnedRightPanel(...)0%6200%
AddToRightPanel(...)0%12300%
RefreshPinnedPanels()0%20400%
RenderTopPanel()0%12300%
RenderProfileControl()0%1561200%
RenderTimePanel()0%20400%
RenderLeftPanel()0%42600%
RenderLeftPanelBaseSkybox()0%2401500%
RenderRightPanel(...)0%72800%
RenderRightPanelHeading(...)0%20400%
EnsureDependencies()0%1561200%
TakeControlAtRuntime()0%6200%
InitializeMaterial()0%6200%
UpdateMaterial()0%2100%
AddNewConfiguration(...)0%2100%
UpdateConfigurationsList()0%56700%
ResumeTime()0%2100%
PauseTime()0%2100%
ApplyOnMaterial()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/ProceduralSkybox/ToolProceduralSkybox/Scripts/Editor/Procedural Skybox/SkyboxEditor_v2.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEditor;
 6using UnityEngine;
 7
 8namespace DCL.Skybox
 9{
 10    public class SkyboxEditorWindow_v2 : EditorWindow
 11    {
 12        private EditorToolMeasurements toolSize;
 13
 14        private List<SkyboxConfiguration> configurations;
 15        private List<string> configurationNames;
 16        private int selectedConfigurationIndex;
 17        private SkyboxConfiguration selectedConfiguration;
 18
 19        public bool isPaused;
 20        public float timeOfTheDay;
 021        public float lifecycleDuration = 1;
 22
 23        private Material selectedMat;
 24        private Vector2 leftPanelScrollPos;
 25        private Vector2 rightPanelScrollPos;
 26        private Light directionalLight;
 27        private bool creatingNewConfig;
 28        private string newConfigName;
 29        private bool overridingController;
 30
 31        private MaterialReferenceContainer.Mat_Layer matLayer = null;
 32
 33        private List<string> renderingOrderList;
 34
 35        private float leftPanelWidth;
 036        private List<RightPanelPins> rightPanelPins = new List<RightPanelPins>() { new RightPanelPins { part = SkyboxEdi
 37
 38        [MenuItem("Window/Skybox Editor")]
 39        static void Init()
 40        {
 041            SkyboxEditorWindow_v2 window = (SkyboxEditorWindow_v2)EditorWindow.GetWindow(typeof(SkyboxEditorWindow_v2));
 042            window.minSize = new Vector2(500, 500);
 043            window.Initialize();
 044            window.Show();
 045            window.InitializeWindow();
 046        }
 47
 048        void Initialize() { toolSize = AssetDatabase.LoadAssetAtPath<EditorToolMeasurements>(SkyboxEditorLiterals.toolMe
 49
 050        public void InitializeWindow() { EnsureDependencies(); }
 51
 52        private void Update()
 53        {
 054            if (selectedConfiguration == null || isPaused)
 55            {
 056                return;
 57            }
 58
 059            float timeNormalizationFactor = lifecycleDuration * 60 / 24;
 060            timeOfTheDay += Time.deltaTime / timeNormalizationFactor;
 061            timeOfTheDay = Mathf.Clamp(timeOfTheDay, 0.01f, 24);
 62
 063            ApplyOnMaterial();
 64
 065            if (timeOfTheDay >= 24)
 66            {
 067                timeOfTheDay = 0.01f;
 068                selectedConfiguration.CycleResets();
 69            }
 70
 071            Repaint();
 072        }
 73
 74        private void OnGUI()
 75        {
 076            EditorGUI.DrawRect(new Rect(toolSize.topPanelLeftStart, toolSize.topPanelTopStart, position.width - toolSize
 077            GUILayout.BeginArea(new Rect(toolSize.topPanelLeftStart, toolSize.topPanelTopStart, position.width - toolSiz
 078            RenderTopPanel();
 079            GUILayout.EndArea();
 80
 81            // Left Panel
 082            float topLeft = toolSize.topPanelLeftStart;
 083            float top = toolSize.topPanelTopStart + toolSize.topPanelHeight + toolSize.panelsPadding;
 084            float width = (position.width - toolSize.toolRightPadding) * toolSize.leftPanelWidthPercentage;
 085            float height = (position.height - top - toolSize.panelsPadding);
 086            leftPanelWidth = width - toolSize.leftPanelPadding.xMax;
 087            EditorGUI.DrawRect(new Rect(topLeft, top, width, height), toolSize.panelBGColor);
 088            GUILayout.BeginArea(new Rect(topLeft + toolSize.leftPanelPadding.xMin, top + toolSize.leftPanelPadding.yMin,
 089            RenderLeftPanel();
 090            GUILayout.EndArea();
 91
 92            // Right Panel
 093            topLeft = toolSize.topPanelLeftStart + width + toolSize.panelsPadding;
 094            width = position.width - toolSize.toolRightPadding - topLeft;
 095            GUILayout.BeginArea(new Rect(topLeft + toolSize.rightPanelPadding.xMin, top + toolSize.rightPanelPadding.yMi
 096            RenderPinnedRightPanel(topLeft + toolSize.rightPanelPadding.xMin, top + toolSize.rightPanelPadding.yMin, wid
 097            GUILayout.EndArea();
 98
 099            if (GUI.changed)
 100            {
 0101                ApplyOnMaterial();
 102            }
 0103        }
 104
 105        void RenderPinnedRightPanel(float topLeft, float top, float width, float height)
 106        {
 0107            RefreshPinnedPanels();
 108
 0109            rightPanelScrollPos = EditorGUILayout.BeginScrollView(rightPanelScrollPos);
 110
 0111            topLeft = 0;
 0112            top = 0;
 113
 0114            for (int i = 0; i < rightPanelPins.Count - 1; i++)
 115            {
 116                // Make a box for pinned panel
 0117                EditorGUI.DrawRect(new Rect(0 + toolSize.pinnedPanelBGOffset.x, top + toolSize.pinnedPanelBGOffset.y, wi
 0118                GUILayout.BeginArea(new Rect(0, top, width - toolSize.rightPanelPadding.xMax, toolSize.pinnedPanelHeight
 0119                RenderRightPanel(rightPanelPins[i]);
 0120                GUILayout.EndArea();
 121
 0122                topLeft = 0;
 0123                top = top + toolSize.pinnedPanelHeight + toolSize.pinnedPanelBGOffset.yMax + toolSize.pinnedPanelBGOffse
 124            }
 125
 126            // Make a box for pinned panel
 0127            EditorGUI.DrawRect(new Rect(0 + toolSize.pinnedPanelBGOffset.x, top + toolSize.pinnedPanelBGOffset.y, width 
 0128            GUILayout.BeginArea(new Rect(0, top, width - toolSize.rightPanelPadding.xMax, height - top));
 0129            RenderRightPanel(rightPanelPins[rightPanelPins.Count - 1]);
 0130            GUILayout.EndArea();
 131
 0132            EditorGUILayout.EndScrollView();
 0133        }
 134
 135        private void AddToRightPanel(RightPanelPins obj)
 136        {
 0137            List<RightPanelPins> pinnedPanels = new List<RightPanelPins>();
 138            // Remove
 0139            for (int i = 0; i < rightPanelPins.Count; i++)
 140            {
 0141                if (rightPanelPins[i].pinned)
 142                {
 0143                    pinnedPanels.Add(rightPanelPins[i]);
 144                }
 145            }
 0146            pinnedPanels.Add(obj);
 147            // Add
 0148            rightPanelPins = pinnedPanels;
 0149        }
 150
 151        private void RefreshPinnedPanels()
 152        {
 0153            List<RightPanelPins> pinnedPanels = new List<RightPanelPins>();
 154
 0155            for (int i = 0; i < rightPanelPins.Count; i++)
 156            {
 0157                if (rightPanelPins[i].pinned)
 158                {
 0159                    pinnedPanels.Add(rightPanelPins[i]);
 0160                }
 0161                else if (i == (rightPanelPins.Count - 1))
 162                {
 0163                    pinnedPanels.Add(rightPanelPins[i]);
 164                }
 165            }
 0166            rightPanelPins = pinnedPanels;
 0167        }
 168
 169        #region Top Panel
 170
 171        Vector2 topScroll;
 172        void RenderTopPanel()
 173        {
 0174            topScroll = EditorGUILayout.BeginScrollView(topScroll);
 0175            GUIStyle style = new GUIStyle();
 0176            style.alignment = TextAnchor.MiddleLeft;
 177
 0178            style.fixedWidth = position.width - toolSize.toolRightPadding;
 0179            EditorGUILayout.BeginHorizontal(style);
 180
 0181            style.fixedWidth = (position.width - toolSize.toolRightPadding) / 2;
 0182            EditorGUILayout.BeginVertical(style);
 0183            RenderProfileControl();
 0184            EditorGUILayout.EndVertical();
 185
 0186            EditorGUILayout.BeginVertical(style);
 0187            RenderTimePanel();
 0188            EditorGUILayout.EndVertical();
 189
 0190            EditorGUILayout.EndHorizontal();
 191
 192            // Timeline Tags
 0193            EditorGUILayout.BeginHorizontal();
 194
 0195            style = new GUIStyle();
 0196            style.alignment = TextAnchor.MiddleLeft;
 0197            style.fixedWidth = (position.width - toolSize.toolRightPadding) / 2;
 0198            EditorGUILayout.BeginVertical(style);
 0199            if (GUILayout.Button(SkyboxEditorLiterals.timeLineTags, GUILayout.Width(100)))
 200            {
 0201                AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Timeline_Tags, name = SkyboxEditorLit
 202            }
 0203            EditorGUILayout.EndVertical();
 204
 0205            style = new GUIStyle();
 0206            style.alignment = TextAnchor.MiddleRight;
 0207            style.fixedWidth = 100;
 0208            EditorGUILayout.BeginVertical(style);
 0209            if (GUILayout.Button(SkyboxEditorLiterals.config))
 210            {
 0211                Selection.activeObject = AssetDatabase.LoadAssetAtPath<EditorToolMeasurements>(SkyboxEditorLiterals.tool
 212            }
 0213            EditorGUILayout.EndVertical();
 0214            EditorGUILayout.EndHorizontal();
 215
 0216            EditorGUILayout.EndScrollView();
 0217        }
 218
 219        private void RenderProfileControl()
 220        {
 0221            if (creatingNewConfig)
 222            {
 0223                EditorGUILayout.BeginHorizontal();
 0224                GUILayout.Label(SkyboxEditorLiterals.name);
 0225                newConfigName = EditorGUILayout.TextField(newConfigName, GUILayout.Width(200));
 226
 0227                if (GUILayout.Button(SkyboxEditorLiterals.create, GUILayout.Width(50)))
 228                {
 229                    // Make new configuration
 0230                    selectedConfiguration = AddNewConfiguration(newConfigName);
 231
 232                    // Update configuration list
 0233                    UpdateConfigurationsList();
 0234                    creatingNewConfig = false;
 235
 0236                    if (Application.isPlaying && SkyboxController.i != null && overridingController)
 237                    {
 0238                        SkyboxController.i.UpdateConfigurationTimelineEvent(selectedConfiguration);
 239                    }
 240                }
 241
 0242                if (GUILayout.Button(SkyboxEditorLiterals.cancel, GUILayout.Width(50)))
 243                {
 0244                    creatingNewConfig = false;
 245                }
 0246                EditorGUILayout.EndHorizontal();
 0247            }
 248            else
 249            {
 0250                EditorGUILayout.BeginHorizontal();
 251
 0252                EditorGUILayout.LabelField(SkyboxEditorLiterals.currentProfile);
 0253                selectedConfiguration = (SkyboxConfiguration)EditorGUILayout.ObjectField(selectedConfiguration, typeof(S
 254
 0255                if (selectedConfiguration != configurations[selectedConfigurationIndex])
 256                {
 0257                    UpdateConfigurationsList();
 258
 0259                    if (Application.isPlaying && SkyboxController.i != null && overridingController)
 260                    {
 0261                        SkyboxController.i.UpdateConfigurationTimelineEvent(selectedConfiguration);
 262                    }
 263                }
 264
 0265                if (GUILayout.Button(SkyboxEditorLiterals.sign_add, GUILayout.Width(50)))
 266                {
 0267                    creatingNewConfig = true;
 268                }
 0269                EditorGUILayout.EndHorizontal();
 270            }
 0271        }
 272
 273        private void RenderTimePanel()
 274        {
 275
 0276            EditorGUILayout.BeginVertical();
 0277            EditorGUILayout.BeginHorizontal();
 0278            EditorGUILayout.LabelField("Time : " + timeOfTheDay.ToString("f2"));
 0279            timeOfTheDay = EditorGUILayout.Slider(timeOfTheDay, 0.01f, 24.00f);
 0280            if (isPaused)
 281            {
 0282                if (GUILayout.Button(SkyboxEditorLiterals.play))
 283                {
 0284                    ResumeTime();
 285                }
 0286            }
 287            else
 288            {
 0289                if (GUILayout.Button(SkyboxEditorLiterals.pause))
 290                {
 0291                    PauseTime();
 292                }
 293            }
 0294            EditorGUILayout.EndHorizontal();
 295
 0296            EditorGUILayout.BeginHorizontal();
 0297            EditorGUILayout.LabelField(SkyboxEditorLiterals.cycle);
 0298            lifecycleDuration = EditorGUILayout.FloatField(lifecycleDuration);
 0299            EditorGUILayout.EndHorizontal();
 0300            EditorGUILayout.EndVertical();
 0301        }
 302
 303        #endregion
 304
 305        #region Left Panel
 306
 307        private void RenderLeftPanel()
 308        {
 0309            leftPanelScrollPos = EditorGUILayout.BeginScrollView(leftPanelScrollPos);
 0310            EditorGUILayout.BeginVertical();
 311            // Render BG Layer Button
 0312            if (GUILayout.Button(SkyboxEditorLiterals.backgroundLayer, EditorStyles.toolbarButton))
 313            {
 0314                AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.BG_Layer, name = SkyboxEditorLiterals
 315            }
 316
 0317            EditorGUILayout.Space(toolSize.leftPanelButtonSpace);
 0318            if (GUILayout.Button(SkyboxEditorLiterals.ambientLayer, EditorStyles.toolbarButton))
 319            {
 0320                AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Ambient_Layer, name = SkyboxEditorLit
 321            }
 322
 0323            EditorGUILayout.Space(toolSize.leftPanelButtonSpace);
 0324            if (GUILayout.Button(SkyboxEditorLiterals.avatarLayer, EditorStyles.toolbarButton))
 325            {
 0326                AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Avatar_Layer, name = SkyboxEditorLite
 327            }
 328
 0329            EditorGUILayout.Space(toolSize.leftPanelButtonSpace);
 0330            if (GUILayout.Button(SkyboxEditorLiterals.fogLayer, EditorStyles.toolbarButton))
 331            {
 0332                AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Fog_Layer, name = SkyboxEditorLiteral
 333            }
 334
 0335            EditorGUILayout.Space(toolSize.leftPanelButtonSpace);
 0336            if (GUILayout.Button(SkyboxEditorLiterals.directionalLightLayer, EditorStyles.toolbarButton))
 337            {
 0338                AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Directional_Light_Layer, name = Skybo
 339            }
 340
 0341            EditorGUILayout.Space(toolSize.leftPanelButtonSpace);
 342
 343            // Render Base 2D layers
 0344            EditorGUILayout.LabelField(SkyboxEditorLiterals.twoDLayers, EditorStyles.label, GUILayout.Width(leftPanelWid
 345
 0346            EditorGUILayout.Space(toolSize.leftPanelButtonSpace);
 347
 0348            RenderLeftPanelBaseSkybox();
 349
 0350            EditorGUILayout.EndVertical();
 0351            EditorGUILayout.EndScrollView();
 0352        }
 353
 354        private void RenderLeftPanelBaseSkybox()
 355        {
 356            // Loop through texture layer and print the name of all layers
 0357            for (int i = 0; i < selectedConfiguration.layers.Count; i++)
 358            {
 359
 0360                EditorGUILayout.BeginHorizontal(toolSize.leftPanelHorizontal);
 361
 0362                selectedConfiguration.layers[i].enabled = EditorGUILayout.Toggle(selectedConfiguration.layers[i].enabled
 363
 0364                if (GUILayout.Button(selectedConfiguration.layers[i].nameInEditor, GUILayout.Width(toolSize.layerButtonW
 365                {
 0366                    AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Base_Skybox, name = selectedConfi
 367                }
 368
 0369                selectedConfiguration.layers[i].slotID = EditorGUILayout.Popup(selectedConfiguration.layers[i].slotID, r
 370
 0371                if (i == 0)
 372                {
 0373                    GUI.enabled = false;
 374                }
 0375                if (GUILayout.Button(SkyboxEditorLiterals.upArrow.ToString()))
 376                {
 0377                    TextureLayer temp = null;
 378
 0379                    if (i >= 1)
 380                    {
 0381                        temp = selectedConfiguration.layers[i - 1];
 0382                        selectedConfiguration.layers[i - 1] = selectedConfiguration.layers[i];
 0383                        selectedConfiguration.layers[i] = temp;
 384                    }
 385                }
 386
 0387                GUI.enabled = true;
 388
 0389                if (i == selectedConfiguration.layers.Count - 1)
 390                {
 0391                    GUI.enabled = false;
 392                }
 393
 0394                if (GUILayout.Button(SkyboxEditorLiterals.downArrow.ToString()))
 395                {
 0396                    TextureLayer temp = null;
 0397                    if (i < (selectedConfiguration.layers.Count - 1))
 398                    {
 0399                        temp = selectedConfiguration.layers[i + 1];
 0400                        selectedConfiguration.layers[i + 1] = selectedConfiguration.layers[i];
 0401                        selectedConfiguration.layers[i] = temp;
 402                    }
 0403                    break;
 404                }
 405
 0406                GUI.enabled = true;
 407
 0408                if (GUILayout.Button(SkyboxEditorLiterals.sign_remove))
 409                {
 0410                    selectedConfiguration.layers.RemoveAt(i);
 0411                    break;
 412                }
 413
 0414                Color circleColor = Color.green;
 0415                switch (selectedConfiguration.layers[i].renderType)
 416                {
 417                    case LayerRenderType.Rendering:
 0418                        circleColor = Color.green;
 0419                        break;
 420                    case LayerRenderType.NotRendering:
 0421                        circleColor = Color.gray;
 0422                        break;
 423                    case LayerRenderType.Conflict_Playing:
 0424                        circleColor = Color.yellow;
 0425                        break;
 426                    case LayerRenderType.Conflict_NotPlaying:
 0427                        circleColor = Color.red;
 428                        break;
 429                    default:
 430                        break;
 431                }
 432
 0433                Color normalContentColor = GUI.color;
 0434                GUI.color = circleColor;
 435
 0436                EditorGUILayout.LabelField(SkyboxEditorLiterals.renderMarker.ToString(), SkyboxEditorStyles.Instance.ren
 437
 0438                GUI.color = normalContentColor;
 0439                EditorGUILayout.EndHorizontal();
 440
 0441                EditorGUILayout.Space(toolSize.leftPanelButtonSpace);
 442            }
 0443            Rect r = EditorGUILayout.BeginHorizontal();
 0444            if (GUI.Button(new Rect(r.width - 35, r.y, 25, 25), SkyboxEditorLiterals.sign_add))
 445            {
 0446                selectedConfiguration.layers.Add(new TextureLayer("Tex Layer " + (selectedConfiguration.layers.Count + 1
 447            }
 0448            EditorGUILayout.EndHorizontal();
 449
 0450        }
 451
 452        #endregion
 453
 454        #region Right Panel
 455
 456        private void RenderRightPanel(RightPanelPins obj)
 457        {
 0458            RenderRightPanelHeading(obj.name, obj);
 0459            obj.scroll = EditorGUILayout.BeginScrollView(obj.scroll);
 460
 0461            EditorGUILayout.Space(5);
 0462            switch (obj.part)
 463            {
 464                case SkyboxEditorToolsParts.Timeline_Tags:
 0465                    RenderTimelineTags.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration);
 0466                    break;
 467                case SkyboxEditorToolsParts.BG_Layer:
 0468                    RenderBackgroundColorLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration);
 0469                    break;
 470                case SkyboxEditorToolsParts.Ambient_Layer:
 0471                    RenderAmbientLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration);
 0472                    break;
 473                case SkyboxEditorToolsParts.Avatar_Layer:
 0474                    RenderAvatarLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration);
 0475                    break;
 476                case SkyboxEditorToolsParts.Fog_Layer:
 0477                    RenderFogLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration);
 0478                    break;
 479                case SkyboxEditorToolsParts.Directional_Light_Layer:
 0480                    DirectionalLightLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration, directionalLigh
 0481                    break;
 482                case SkyboxEditorToolsParts.Base_Skybox:
 0483                    RenderTextureLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration.layers[obj.baseSkyb
 484                    break;
 485                default:
 486                    break;
 487            }
 488
 0489            EditorGUILayout.EndScrollView();
 0490        }
 491
 492        void RenderRightPanelHeading(string text, RightPanelPins obj)
 493        {
 0494            GUIStyle style = new GUIStyle(EditorStyles.miniBoldLabel);
 0495            style.normal.background = toolSize.rightPanelHeadingState.backgroundTex;
 0496            EditorGUILayout.BeginHorizontal(style);
 0497            style = new GUIStyle(EditorStyles.boldLabel);
 0498            style.normal.textColor = toolSize.rightPanelHeadingTextColor.textColor;
 0499            EditorGUILayout.LabelField(text, style, GUILayout.Width(200));
 500
 0501            string btnTxt = (obj.pinned) ? SkyboxEditorLiterals.unpin : SkyboxEditorLiterals.pin;
 0502            if (GUILayout.Button(btnTxt, GUILayout.Width(50)))
 503            {
 0504                obj.pinned = !obj.pinned;
 505            }
 0506            EditorGUILayout.EndHorizontal();
 0507        }
 508
 509        #endregion
 510
 511        private void EnsureDependencies()
 512        {
 0513            if (!Application.isPlaying)
 514            {
 0515                overridingController = false;
 516            }
 517
 0518            if (Application.isPlaying && !overridingController)
 519            {
 0520                TakeControlAtRuntime();
 521            }
 522
 0523            if (selectedConfiguration == null)
 524            {
 0525                UpdateConfigurationsList();
 526            }
 527
 0528            if (matLayer == null || selectedMat == null)
 529            {
 0530                UpdateMaterial();
 531            }
 532
 0533            EditorUtility.SetDirty(selectedConfiguration);
 534
 535            // Fill rendering order array
 0536            if (renderingOrderList == null)
 537            {
 0538                renderingOrderList = new List<string>();
 539
 0540                for (int i = 0; i < 5; i++)
 541                {
 0542                    renderingOrderList.Add((i + 1).ToString());
 543                }
 544            }
 545
 0546            if (directionalLight != null)
 547            {
 0548                return;
 549            }
 550
 551            // Cache directional light reference
 0552            directionalLight = GameObject.FindObjectsOfType<Light>(true).Where(s => s.type == LightType.Directional).Fir
 553
 554            // Make a directional light object if can't find
 0555            if (directionalLight == null)
 556            {
 0557                GameObject temp = new GameObject(SkyboxEditorLiterals.sunObjectName);
 558                // Add the light component
 0559                directionalLight = temp.AddComponent<Light>();
 0560                directionalLight.type = LightType.Directional;
 561            }
 0562        }
 563
 564        void TakeControlAtRuntime()
 565        {
 0566            if (SkyboxController.i != null)
 567            {
 0568                isPaused = SkyboxController.i.IsPaused();
 0569                lifecycleDuration = (float)SkyboxController.i.lifecycleDuration;
 0570                selectedConfiguration = SkyboxController.i.GetCurrentConfiguration();
 0571                overridingController = SkyboxController.i.SetOverrideController(true);
 0572                timeOfTheDay = SkyboxController.i.GetCurrentTimeOfTheDay();
 0573                UpdateConfigurationsList();
 574            }
 0575        }
 576
 577        void InitializeMaterial()
 578        {
 0579            matLayer = MaterialReferenceContainer.i.GetMat_LayerForLayers(5);
 580
 0581            if (matLayer == null)
 582            {
 0583                matLayer = MaterialReferenceContainer.i.materials[0];
 584            }
 585
 0586            selectedMat = matLayer.material;
 0587            selectedConfiguration.ResetMaterial(selectedMat, matLayer.numberOfSlots);
 0588            RenderSettings.skybox = selectedMat;
 0589        }
 590
 0591        private void UpdateMaterial() { InitializeMaterial(); }
 592
 593        private SkyboxConfiguration AddNewConfiguration(string name)
 594        {
 595            SkyboxConfiguration temp = null;
 0596            temp = ScriptableObject.CreateInstance<SkyboxConfiguration>();
 0597            temp.skyboxID = name;
 598
 0599            string path = AssetDatabase.GenerateUniqueAssetPath("Assets/Rendering/ProceduralSkybox/Resources/Skybox Conf
 0600            AssetDatabase.CreateAsset(temp, path);
 0601            AssetDatabase.SaveAssets();
 602
 0603            return temp;
 604        }
 605
 606        private void UpdateConfigurationsList()
 607        {
 0608            SkyboxConfiguration[] tConfigurations = Resources.LoadAll<SkyboxConfiguration>("Skybox Configurations/");
 0609            configurations = new List<SkyboxConfiguration>(tConfigurations);
 0610            configurationNames = new List<string>();
 611
 612            // If no configurations exist, make and select new one.
 0613            if (configurations == null || configurations.Count < 1)
 614            {
 0615                selectedConfiguration = AddNewConfiguration(SkyboxEditorLiterals.defaultskyboxName);
 616
 0617                configurations = new List<SkyboxConfiguration>();
 0618                configurations.Add(selectedConfiguration);
 619            }
 620
 0621            if (selectedConfiguration == null)
 622            {
 0623                selectedConfiguration = configurations[0];
 624            }
 625
 0626            for (int i = 0; i < configurations.Count; i++)
 627            {
 0628                configurations[i].skyboxID = configurations[i].name;
 629
 0630                configurationNames.Add(configurations[i].skyboxID);
 0631                if (selectedConfiguration == configurations[i])
 632                {
 0633                    selectedConfigurationIndex = i;
 634                }
 635            }
 636
 0637            InitializeMaterial();
 638
 0639            if (!Application.isPlaying)
 640            {
 0641                isPaused = true;
 642            }
 0643        }
 644
 0645        void ResumeTime() { isPaused = false; }
 646
 0647        void PauseTime() { isPaused = true; }
 648
 649        private void ApplyOnMaterial()
 650        {
 0651            EnsureDependencies();
 0652            selectedConfiguration.ApplyOnMaterial(selectedMat, timeOfTheDay, SkyboxEditorUtils.GetNormalizedDayTime(time
 653
 654            // If in play mode, call avatar color from skybox controller class
 0655            if (Application.isPlaying && SkyboxController.i != null)
 656            {
 0657                SkyboxController.i.ApplyAvatarColor(SkyboxEditorUtils.GetNormalizedDayTime(timeOfTheDay));
 658            }
 0659        }
 660    }
 661}