| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using UnityEditor; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | namespace DCL.Skybox |
| | 9 | | { |
| | 10 | | public class SkyboxEditorWindow : 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; |
| 0 | 21 | | public float lifecycleDuration = 1; |
| | 22 | |
|
| | 23 | | private Material selectedMat; |
| | 24 | | private Vector2 leftPanelScrollPos; |
| | 25 | | private Vector2 rightPanelScrollPos; |
| | 26 | | private Vector2 topScroll; |
| | 27 | | private Light directionalLight; |
| | 28 | | private bool creatingNewConfig; |
| | 29 | | private string newConfigName; |
| | 30 | | private bool overridingController; |
| | 31 | | private List<string> renderingOrderList; |
| | 32 | |
|
| | 33 | | private float leftPanelWidth; |
| 0 | 34 | | private List<RightPanelPins> rightPanelPins = new List<RightPanelPins>() { new RightPanelPins { part = SkyboxEdi |
| | 35 | |
|
| | 36 | | private CopyFunctionality copyPasteObj; |
| | 37 | | private SkyboxElements skyboxElements; |
| | 38 | |
|
| | 39 | | [MenuItem("Window/Skybox Editor")] |
| | 40 | | static void Init() |
| | 41 | | { |
| 0 | 42 | | SkyboxEditorWindow window = (SkyboxEditorWindow)EditorWindow.GetWindow(typeof(SkyboxEditorWindow)); |
| 0 | 43 | | window.minSize = new Vector2(500, 500); |
| 0 | 44 | | window.Initialize(); |
| 0 | 45 | | window.Show(); |
| 0 | 46 | | window.InitializeWindow(); |
| 0 | 47 | | } |
| | 48 | |
|
| 0 | 49 | | private void OnDisable() { skyboxElements?.Dispose(); } |
| | 50 | |
|
| 0 | 51 | | void Initialize() { toolSize = AssetDatabase.LoadAssetAtPath<EditorToolMeasurements>(SkyboxEditorLiterals.Paths. |
| | 52 | |
|
| 0 | 53 | | public void InitializeWindow() { EnsureDependencies(); } |
| | 54 | |
|
| | 55 | | private void Update() |
| | 56 | | { |
| 0 | 57 | | if (selectedConfiguration == null || isPaused) |
| | 58 | | { |
| 0 | 59 | | return; |
| | 60 | | } |
| | 61 | |
|
| 0 | 62 | | float timeNormalizationFactor = lifecycleDuration * 60 / SkyboxUtils.CYCLE_TIME; |
| 0 | 63 | | timeOfTheDay += Time.deltaTime / timeNormalizationFactor; |
| 0 | 64 | | timeOfTheDay = Mathf.Clamp(timeOfTheDay, 0.01f, SkyboxUtils.CYCLE_TIME); |
| | 65 | |
|
| 0 | 66 | | ApplyOnMaterial(false); |
| | 67 | |
|
| 0 | 68 | | if (timeOfTheDay >= SkyboxUtils.CYCLE_TIME) |
| | 69 | | { |
| 0 | 70 | | timeOfTheDay = 0.01f; |
| 0 | 71 | | selectedConfiguration.CycleResets(); |
| | 72 | | } |
| | 73 | |
|
| 0 | 74 | | Repaint(); |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | private void OnGUI() |
| | 78 | | { |
| 0 | 79 | | EditorGUI.DrawRect(new Rect(toolSize.topPanelLeftStart, toolSize.topPanelTopStart, position.width - toolSize |
| 0 | 80 | | GUILayout.BeginArea(new Rect(toolSize.topPanelLeftStart, toolSize.topPanelTopStart, position.width - toolSiz |
| 0 | 81 | | RenderTopPanel(); |
| 0 | 82 | | GUILayout.EndArea(); |
| | 83 | |
|
| | 84 | | // Left Panel |
| 0 | 85 | | float topLeft = toolSize.topPanelLeftStart; |
| 0 | 86 | | float top = toolSize.topPanelTopStart + toolSize.topPanelHeight + toolSize.panelsPadding; |
| 0 | 87 | | float width = (position.width - toolSize.toolRightPadding) * toolSize.leftPanelWidthPercentage; |
| 0 | 88 | | float height = (position.height - top - toolSize.panelsPadding); |
| 0 | 89 | | leftPanelWidth = width - toolSize.leftPanelPadding.xMax; |
| 0 | 90 | | EditorGUI.DrawRect(new Rect(topLeft, top, width, height), toolSize.panelBGColor); |
| 0 | 91 | | GUILayout.BeginArea(new Rect(topLeft + toolSize.leftPanelPadding.xMin, top + toolSize.leftPanelPadding.yMin, |
| 0 | 92 | | RenderLeftPanel(); |
| 0 | 93 | | GUILayout.EndArea(); |
| | 94 | |
|
| | 95 | | // Right Panel |
| 0 | 96 | | topLeft = toolSize.topPanelLeftStart + width + toolSize.panelsPadding; |
| 0 | 97 | | width = position.width - toolSize.toolRightPadding - topLeft; |
| 0 | 98 | | GUILayout.BeginArea(new Rect(topLeft + toolSize.rightPanelPadding.xMin, top + toolSize.rightPanelPadding.yMi |
| 0 | 99 | | RenderRightPanel(topLeft + toolSize.rightPanelPadding.xMin, top + toolSize.rightPanelPadding.yMin, width - t |
| 0 | 100 | | GUILayout.EndArea(); |
| | 101 | |
|
| 0 | 102 | | if (GUI.changed) |
| | 103 | | { |
| 0 | 104 | | ApplyOnMaterial(true); |
| | 105 | | } |
| 0 | 106 | | } |
| | 107 | |
|
| | 108 | | #region Top Panel |
| | 109 | |
|
| | 110 | | void RenderTopPanel() |
| | 111 | | { |
| 0 | 112 | | topScroll = EditorGUILayout.BeginScrollView(topScroll); |
| 0 | 113 | | GUIStyle style = new GUIStyle(); |
| 0 | 114 | | style.alignment = TextAnchor.MiddleLeft; |
| | 115 | |
|
| 0 | 116 | | style.fixedWidth = position.width - toolSize.toolRightPadding; |
| 0 | 117 | | EditorGUILayout.BeginHorizontal(style); |
| | 118 | |
|
| 0 | 119 | | style.fixedWidth = (position.width - toolSize.toolRightPadding) / 2; |
| 0 | 120 | | EditorGUILayout.BeginVertical(style); |
| 0 | 121 | | RenderProfileControl(); |
| 0 | 122 | | EditorGUILayout.EndVertical(); |
| | 123 | |
|
| 0 | 124 | | EditorGUILayout.BeginVertical(style); |
| 0 | 125 | | RenderTimePanel(); |
| 0 | 126 | | EditorGUILayout.EndVertical(); |
| | 127 | |
|
| 0 | 128 | | EditorGUILayout.EndHorizontal(); |
| | 129 | |
|
| | 130 | | // Timeline Tags |
| 0 | 131 | | EditorGUILayout.BeginHorizontal(); |
| | 132 | |
|
| 0 | 133 | | style = new GUIStyle(); |
| 0 | 134 | | style.alignment = TextAnchor.MiddleLeft; |
| 0 | 135 | | style.fixedWidth = (position.width - toolSize.toolRightPadding) / 2; |
| 0 | 136 | | EditorGUILayout.BeginVertical(style); |
| 0 | 137 | | if (GUILayout.Button(SkyboxEditorLiterals.Labels.timeLineTags, GUILayout.Width(100))) |
| | 138 | | { |
| 0 | 139 | | AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Timeline_Tags, name = SkyboxEditorLit |
| | 140 | | } |
| 0 | 141 | | EditorGUILayout.EndVertical(); |
| | 142 | |
|
| 0 | 143 | | style = new GUIStyle(); |
| 0 | 144 | | style.alignment = TextAnchor.MiddleRight; |
| 0 | 145 | | style.fixedWidth = 100; |
| 0 | 146 | | EditorGUILayout.BeginVertical(style); |
| 0 | 147 | | if (GUILayout.Button(SkyboxEditorLiterals.Labels.config)) |
| | 148 | | { |
| 0 | 149 | | Selection.activeObject = AssetDatabase.LoadAssetAtPath<EditorToolMeasurements>(SkyboxEditorLiterals.Path |
| | 150 | | } |
| 0 | 151 | | EditorGUILayout.EndVertical(); |
| 0 | 152 | | EditorGUILayout.EndHorizontal(); |
| | 153 | |
|
| 0 | 154 | | EditorGUILayout.EndScrollView(); |
| 0 | 155 | | if (Application.isPlaying && SkyboxController.i == null) |
| 0 | 156 | | EditorGUILayout.HelpBox("There's no SkyboxController in the scene, try this in InitialScene!", MessageTy |
| 0 | 157 | | } |
| | 158 | |
|
| | 159 | | private void RenderProfileControl() |
| | 160 | | { |
| 0 | 161 | | if (creatingNewConfig) |
| | 162 | | { |
| 0 | 163 | | EditorGUILayout.BeginHorizontal(); |
| 0 | 164 | | GUILayout.Label(SkyboxEditorLiterals.Labels.name); |
| 0 | 165 | | newConfigName = EditorGUILayout.TextField(newConfigName, GUILayout.Width(200)); |
| | 166 | |
|
| 0 | 167 | | if (GUILayout.Button(SkyboxEditorLiterals.Labels.create, GUILayout.Width(50))) |
| | 168 | | { |
| | 169 | | // Make new configuration |
| 0 | 170 | | selectedConfiguration = AddNewConfiguration(newConfigName); |
| | 171 | |
|
| | 172 | | // Update configuration list |
| 0 | 173 | | UpdateConfigurationsList(); |
| 0 | 174 | | creatingNewConfig = false; |
| | 175 | |
|
| 0 | 176 | | if (Application.isPlaying && SkyboxController.i != null && overridingController) |
| | 177 | | { |
| 0 | 178 | | SkyboxController.i.UpdateConfigurationTimelineEvent(selectedConfiguration); |
| | 179 | | } |
| | 180 | | } |
| | 181 | |
|
| 0 | 182 | | if (GUILayout.Button(SkyboxEditorLiterals.Labels.cancel, GUILayout.Width(50))) |
| | 183 | | { |
| 0 | 184 | | creatingNewConfig = false; |
| | 185 | | } |
| 0 | 186 | | EditorGUILayout.EndHorizontal(); |
| 0 | 187 | | } |
| | 188 | | else |
| | 189 | | { |
| 0 | 190 | | EditorGUILayout.BeginHorizontal(); |
| | 191 | |
|
| 0 | 192 | | EditorGUILayout.LabelField(SkyboxEditorLiterals.Labels.currentProfile); |
| 0 | 193 | | selectedConfiguration = (SkyboxConfiguration)EditorGUILayout.ObjectField(selectedConfiguration, typeof(S |
| | 194 | |
|
| 0 | 195 | | if (selectedConfiguration != configurations[selectedConfigurationIndex]) |
| | 196 | | { |
| 0 | 197 | | UpdateConfigurationsList(); |
| | 198 | |
|
| 0 | 199 | | if (Application.isPlaying && SkyboxController.i != null && overridingController) |
| | 200 | | { |
| 0 | 201 | | SkyboxController.i.UpdateConfigurationTimelineEvent(selectedConfiguration); |
| | 202 | | } |
| | 203 | | } |
| | 204 | |
|
| 0 | 205 | | if (GUILayout.Button(SkyboxEditorLiterals.Characters.sign_add, GUILayout.Width(50))) |
| | 206 | | { |
| 0 | 207 | | creatingNewConfig = true; |
| | 208 | | } |
| 0 | 209 | | EditorGUILayout.EndHorizontal(); |
| | 210 | | } |
| 0 | 211 | | } |
| | 212 | |
|
| | 213 | | private void RenderTimePanel() |
| | 214 | | { |
| | 215 | |
|
| 0 | 216 | | EditorGUILayout.BeginVertical(); |
| 0 | 217 | | EditorGUILayout.BeginHorizontal(); |
| 0 | 218 | | EditorGUILayout.LabelField("Time : " + timeOfTheDay.ToString("f2")); |
| 0 | 219 | | timeOfTheDay = EditorGUILayout.Slider(timeOfTheDay, 0.01f, SkyboxUtils.CYCLE_TIME); |
| 0 | 220 | | if (isPaused) |
| | 221 | | { |
| 0 | 222 | | if (GUILayout.Button(SkyboxEditorLiterals.Labels.play)) |
| | 223 | | { |
| 0 | 224 | | ResumeTime(); |
| | 225 | | } |
| 0 | 226 | | } |
| | 227 | | else |
| | 228 | | { |
| 0 | 229 | | if (GUILayout.Button(SkyboxEditorLiterals.Labels.pause)) |
| | 230 | | { |
| 0 | 231 | | PauseTime(); |
| | 232 | | } |
| | 233 | | } |
| 0 | 234 | | EditorGUILayout.EndHorizontal(); |
| | 235 | |
|
| 0 | 236 | | EditorGUILayout.BeginHorizontal(); |
| 0 | 237 | | EditorGUILayout.LabelField(SkyboxEditorLiterals.Labels.cycle); |
| 0 | 238 | | lifecycleDuration = EditorGUILayout.FloatField(lifecycleDuration); |
| 0 | 239 | | EditorGUILayout.EndHorizontal(); |
| 0 | 240 | | EditorGUILayout.EndVertical(); |
| 0 | 241 | | } |
| | 242 | |
|
| | 243 | | #endregion |
| | 244 | |
|
| | 245 | | #region Left Panel |
| | 246 | |
|
| | 247 | | private void RenderLeftPanel() |
| | 248 | | { |
| 0 | 249 | | leftPanelScrollPos = EditorGUILayout.BeginScrollView(leftPanelScrollPos, true, false); |
| 0 | 250 | | EditorGUILayout.BeginVertical(); |
| | 251 | | // Render BG Layer Button |
| 0 | 252 | | if (GUILayout.Button(SkyboxEditorLiterals.Layers.backgroundLayer, EditorStyles.toolbarButton)) |
| | 253 | | { |
| 0 | 254 | | AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.BG_Layer, name = SkyboxEditorLiterals |
| | 255 | | } |
| | 256 | |
|
| 0 | 257 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| 0 | 258 | | if (GUILayout.Button(SkyboxEditorLiterals.Layers.horizonPlane, EditorStyles.toolbarButton)) |
| | 259 | | { |
| 0 | 260 | | AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Horizon_Plane, name = SkyboxEditorLit |
| | 261 | | } |
| | 262 | |
|
| 0 | 263 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| 0 | 264 | | if (GUILayout.Button(SkyboxEditorLiterals.Layers.ambientLayer, EditorStyles.toolbarButton)) |
| | 265 | | { |
| 0 | 266 | | AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Ambient_Layer, name = SkyboxEditorLit |
| | 267 | | } |
| | 268 | |
|
| 0 | 269 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| 0 | 270 | | if (GUILayout.Button(SkyboxEditorLiterals.Layers.avatarLayer, EditorStyles.toolbarButton)) |
| | 271 | | { |
| 0 | 272 | | AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Avatar_Layer, name = SkyboxEditorLite |
| | 273 | | } |
| | 274 | |
|
| 0 | 275 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| 0 | 276 | | if (GUILayout.Button(SkyboxEditorLiterals.Layers.fogLayer, EditorStyles.toolbarButton)) |
| | 277 | | { |
| 0 | 278 | | AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Fog_Layer, name = SkyboxEditorLiteral |
| | 279 | | } |
| | 280 | |
|
| 0 | 281 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| 0 | 282 | | if (GUILayout.Button(SkyboxEditorLiterals.Layers.directionalLightLayer, EditorStyles.toolbarButton)) |
| | 283 | | { |
| 0 | 284 | | AddToRightPanel(new RightPanelPins { part = SkyboxEditorToolsParts.Directional_Light_Layer, name = Skybo |
| | 285 | | } |
| | 286 | |
|
| 0 | 287 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| | 288 | |
|
| | 289 | | // Render Base 2D layers |
| 0 | 290 | | EditorGUILayout.LabelField(SkyboxEditorLiterals.Layers.twoDLayers, EditorStyles.label, GUILayout.Width(leftP |
| | 291 | |
|
| 0 | 292 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| | 293 | |
|
| 0 | 294 | | RenderLeftPanelBaseSkyboxLayers.Render(ref timeOfTheDay, toolSize, selectedConfiguration, AddToRightPanel, r |
| | 295 | |
|
| | 296 | | // Render Domes List |
| 0 | 297 | | EditorGUILayout.LabelField(SkyboxEditorLiterals.Layers.RenderDomeLayers, EditorStyles.label, GUILayout.Width |
| | 298 | |
|
| 0 | 299 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| | 300 | |
|
| 0 | 301 | | RenderLeftPanelDomeLayers.Render(ref timeOfTheDay, toolSize, selectedConfiguration, AddToRightPanel, copyPas |
| | 302 | |
|
| 0 | 303 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| | 304 | |
|
| | 305 | | // Render Satellite list |
| 0 | 306 | | EditorGUILayout.LabelField(SkyboxEditorLiterals.Layers.RenderSatelliteLayers, EditorStyles.label, GUILayout. |
| | 307 | |
|
| 0 | 308 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| | 309 | |
|
| 0 | 310 | | RenderLeftPanelSatelliteLayers.Render(ref timeOfTheDay, toolSize, selectedConfiguration, AddToRightPanel, co |
| | 311 | |
|
| | 312 | | // Render Satellite list |
| 0 | 313 | | EditorGUILayout.LabelField(SkyboxEditorLiterals.Layers.RenderPlanarLayers, EditorStyles.label, GUILayout.Wid |
| | 314 | |
|
| 0 | 315 | | EditorGUILayout.Space(toolSize.leftPanelButtonSpace); |
| | 316 | |
|
| 0 | 317 | | RenderLeftPanelPlanarLayers.Render(ref timeOfTheDay, toolSize, selectedConfiguration, AddToRightPanel, copyP |
| | 318 | |
|
| 0 | 319 | | EditorGUILayout.EndVertical(); |
| 0 | 320 | | EditorGUILayout.EndScrollView(); |
| 0 | 321 | | } |
| | 322 | |
|
| | 323 | | #endregion |
| | 324 | |
|
| | 325 | | #region Right Panel |
| | 326 | |
|
| | 327 | | private void AddToRightPanel(RightPanelPins obj) |
| | 328 | | { |
| 0 | 329 | | List<RightPanelPins> pinnedPanels = new List<RightPanelPins>(); |
| | 330 | | // Remove |
| 0 | 331 | | for (int i = 0; i < rightPanelPins.Count; i++) |
| | 332 | | { |
| 0 | 333 | | if (rightPanelPins[i].pinned) |
| | 334 | | { |
| 0 | 335 | | pinnedPanels.Add(rightPanelPins[i]); |
| | 336 | | } |
| | 337 | | } |
| 0 | 338 | | pinnedPanels.Add(obj); |
| | 339 | | // Add |
| 0 | 340 | | rightPanelPins = pinnedPanels; |
| 0 | 341 | | } |
| | 342 | |
|
| | 343 | | void RenderRightPanel(float topLeft, float top, float width, float height) |
| | 344 | | { |
| 0 | 345 | | RefreshPinnedPanels(); |
| | 346 | |
|
| 0 | 347 | | rightPanelScrollPos = EditorGUILayout.BeginScrollView(rightPanelScrollPos); |
| | 348 | |
|
| 0 | 349 | | topLeft = 0; |
| 0 | 350 | | top = 0; |
| | 351 | |
|
| 0 | 352 | | for (int i = 0; i < rightPanelPins.Count - 1; i++) |
| | 353 | | { |
| | 354 | | // Make a box for pinned panel |
| 0 | 355 | | EditorGUI.DrawRect(new Rect(0 + toolSize.pinnedPanelBGOffset.x, top + toolSize.pinnedPanelBGOffset.y, wi |
| 0 | 356 | | GUILayout.BeginArea(new Rect(0, top, width - toolSize.rightPanelPadding.xMax, toolSize.pinnedPanelHeight |
| 0 | 357 | | RenderPinnedRightPanel(rightPanelPins[i]); |
| 0 | 358 | | GUILayout.EndArea(); |
| | 359 | |
|
| 0 | 360 | | topLeft = 0; |
| 0 | 361 | | top = top + toolSize.pinnedPanelHeight + toolSize.pinnedPanelBGOffset.yMax + toolSize.pinnedPanelBGOffse |
| | 362 | | } |
| | 363 | |
|
| | 364 | | // Make a box for pinned panel |
| 0 | 365 | | EditorGUI.DrawRect(new Rect(0 + toolSize.pinnedPanelBGOffset.x, top + toolSize.pinnedPanelBGOffset.y, width |
| 0 | 366 | | GUILayout.BeginArea(new Rect(0, top, width - toolSize.rightPanelPadding.xMax, height - top)); |
| | 367 | |
|
| 0 | 368 | | if (rightPanelPins.Count > 0) |
| | 369 | | { |
| 0 | 370 | | RenderPinnedRightPanel(rightPanelPins[rightPanelPins.Count - 1]); |
| | 371 | | } |
| | 372 | |
|
| 0 | 373 | | GUILayout.EndArea(); |
| | 374 | |
|
| 0 | 375 | | EditorGUILayout.EndScrollView(); |
| 0 | 376 | | } |
| | 377 | |
|
| | 378 | | private void RefreshPinnedPanels() |
| | 379 | | { |
| 0 | 380 | | List<RightPanelPins> pinnedPanels = new List<RightPanelPins>(); |
| | 381 | |
|
| 0 | 382 | | for (int i = 0; i < rightPanelPins.Count; i++) |
| | 383 | | { |
| | 384 | | // Check if pinned panel object (in case of Base_Skybox and Elements3D_Dome) is deleted or not if delete |
| 0 | 385 | | if (rightPanelPins[i].part == SkyboxEditorToolsParts.Base_Skybox) |
| | 386 | | { |
| 0 | 387 | | if (!selectedConfiguration.layers.Contains(rightPanelPins[i].baseSkyboxTargetLayer)) |
| | 388 | | { |
| | 389 | | continue; |
| | 390 | | } |
| | 391 | | } |
| | 392 | |
|
| 0 | 393 | | if (rightPanelPins[i].part == SkyboxEditorToolsParts.Elements3D_Dome) |
| | 394 | | { |
| 0 | 395 | | if (!selectedConfiguration.additional3Dconfig.Contains(rightPanelPins[i].targetDomeElement)) |
| | 396 | | { |
| | 397 | | continue; |
| | 398 | | } |
| | 399 | | } |
| | 400 | |
|
| 0 | 401 | | if (rightPanelPins[i].pinned) |
| | 402 | | { |
| 0 | 403 | | pinnedPanels.Add(rightPanelPins[i]); |
| 0 | 404 | | } |
| 0 | 405 | | else if (i == (rightPanelPins.Count - 1)) |
| | 406 | | { |
| 0 | 407 | | pinnedPanels.Add(rightPanelPins[i]); |
| | 408 | | } |
| | 409 | | } |
| 0 | 410 | | rightPanelPins = pinnedPanels; |
| 0 | 411 | | } |
| | 412 | |
|
| | 413 | | private void RenderPinnedRightPanel(RightPanelPins obj) |
| | 414 | | { |
| 0 | 415 | | RenderRightPanelHeading(obj.name, obj); |
| 0 | 416 | | obj.scroll = EditorGUILayout.BeginScrollView(obj.scroll); |
| | 417 | |
|
| 0 | 418 | | EditorGUILayout.Space(5); |
| 0 | 419 | | switch (obj.part) |
| | 420 | | { |
| | 421 | | case SkyboxEditorToolsParts.Timeline_Tags: |
| 0 | 422 | | RenderTimelineTags.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration); |
| 0 | 423 | | break; |
| | 424 | | case SkyboxEditorToolsParts.BG_Layer: |
| 0 | 425 | | RenderBackgroundColorLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration); |
| 0 | 426 | | break; |
| | 427 | | case SkyboxEditorToolsParts.Horizon_Plane: |
| 0 | 428 | | RenderHorizonPlane.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration); |
| 0 | 429 | | break; |
| | 430 | | case SkyboxEditorToolsParts.Ambient_Layer: |
| 0 | 431 | | RenderAmbientLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration); |
| 0 | 432 | | break; |
| | 433 | | case SkyboxEditorToolsParts.Avatar_Layer: |
| 0 | 434 | | RenderAvatarLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration); |
| 0 | 435 | | break; |
| | 436 | | case SkyboxEditorToolsParts.Fog_Layer: |
| 0 | 437 | | RenderFogLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration); |
| 0 | 438 | | break; |
| | 439 | | case SkyboxEditorToolsParts.Directional_Light_Layer: |
| 0 | 440 | | DirectionalLightLayer.RenderLayer(ref timeOfTheDay, toolSize, selectedConfiguration, directionalLigh |
| 0 | 441 | | break; |
| | 442 | | case SkyboxEditorToolsParts.Base_Skybox: |
| 0 | 443 | | RenderTextureLayer.RenderLayer(ref timeOfTheDay, toolSize, obj.baseSkyboxTargetLayer); |
| 0 | 444 | | break; |
| | 445 | | case SkyboxEditorToolsParts.Elements3D_Dome: |
| 0 | 446 | | RenderDome3DLayer.RenderLayer(ref timeOfTheDay, toolSize, obj.targetDomeElement); |
| 0 | 447 | | break; |
| | 448 | | case SkyboxEditorToolsParts.Elements3D_Satellite: |
| 0 | 449 | | RenderSatellite3DLayer.RenderLayer(ref timeOfTheDay, toolSize, obj.targetSatelliteElement); |
| 0 | 450 | | break; |
| | 451 | | case SkyboxEditorToolsParts.Elements3D_Planar: |
| 0 | 452 | | RenderPlanar3DLayer.RenderLayer(ref timeOfTheDay, toolSize, obj.targetPlanarElement); |
| | 453 | | break; |
| | 454 | | default: |
| | 455 | | break; |
| | 456 | | } |
| | 457 | |
|
| 0 | 458 | | EditorGUILayout.EndScrollView(); |
| 0 | 459 | | } |
| | 460 | |
|
| | 461 | | void RenderRightPanelHeading(string text, RightPanelPins obj) |
| | 462 | | { |
| 0 | 463 | | GUIStyle style = new GUIStyle(EditorStyles.miniBoldLabel); |
| 0 | 464 | | style.normal.background = toolSize.rightPanelHeadingState.backgroundTex; |
| 0 | 465 | | EditorGUILayout.BeginHorizontal(style); |
| 0 | 466 | | style = new GUIStyle(EditorStyles.boldLabel); |
| 0 | 467 | | style.normal.textColor = toolSize.rightPanelHeadingTextColor.textColor; |
| 0 | 468 | | EditorGUILayout.LabelField(text, style, GUILayout.Width(200)); |
| | 469 | |
|
| 0 | 470 | | string btnTxt = (obj.pinned) ? SkyboxEditorLiterals.Labels.unpin : SkyboxEditorLiterals.Labels.pin; |
| 0 | 471 | | if (GUILayout.Button(btnTxt, GUILayout.Width(50))) |
| | 472 | | { |
| 0 | 473 | | obj.pinned = !obj.pinned; |
| | 474 | | } |
| 0 | 475 | | EditorGUILayout.EndHorizontal(); |
| 0 | 476 | | } |
| | 477 | |
|
| | 478 | | #endregion |
| | 479 | |
|
| | 480 | | private void EnsureDependencies() |
| | 481 | | { |
| 0 | 482 | | if (!Application.isPlaying) |
| | 483 | | { |
| 0 | 484 | | overridingController = false; |
| | 485 | | } |
| | 486 | |
|
| 0 | 487 | | if (Application.isPlaying && !overridingController) |
| | 488 | | { |
| 0 | 489 | | TakeControlAtRuntime(); |
| | 490 | | } |
| | 491 | |
|
| 0 | 492 | | if (selectedConfiguration == null) |
| | 493 | | { |
| 0 | 494 | | UpdateConfigurationsList(); |
| | 495 | | } |
| | 496 | |
|
| 0 | 497 | | if (selectedMat == null) |
| | 498 | | { |
| 0 | 499 | | UpdateMaterial(); |
| | 500 | | } |
| | 501 | |
|
| 0 | 502 | | if (copyPasteObj == null) |
| | 503 | | { |
| 0 | 504 | | copyPasteObj = new CopyFunctionality(); |
| | 505 | | } |
| | 506 | |
|
| 0 | 507 | | EditorUtility.SetDirty(selectedConfiguration); |
| | 508 | |
|
| | 509 | | // Fill rendering order array |
| 0 | 510 | | if (renderingOrderList == null) |
| | 511 | | { |
| 0 | 512 | | renderingOrderList = new List<string>(); |
| | 513 | |
|
| 0 | 514 | | for (int i = 0; i < 5; i++) |
| | 515 | | { |
| 0 | 516 | | renderingOrderList.Add((i + 1).ToString()); |
| | 517 | | } |
| | 518 | | } |
| | 519 | |
|
| 0 | 520 | | if (directionalLight != null) |
| | 521 | | { |
| 0 | 522 | | return; |
| | 523 | | } |
| | 524 | |
|
| | 525 | | // Cache directional light reference |
| 0 | 526 | | directionalLight = GameObject.FindObjectsOfType<Light>(true).Where(s => s.type == LightType.Directional).Fir |
| | 527 | |
|
| | 528 | | // Make a directional light object if can't find |
| 0 | 529 | | if (directionalLight == null) |
| | 530 | | { |
| 0 | 531 | | GameObject temp = new GameObject(SkyboxEditorLiterals.Labels.sunObjectName); |
| | 532 | | // Add the light component |
| 0 | 533 | | directionalLight = temp.AddComponent<Light>(); |
| 0 | 534 | | directionalLight.type = LightType.Directional; |
| | 535 | | } |
| | 536 | |
|
| 0 | 537 | | if (skyboxElements == null) |
| | 538 | | { |
| 0 | 539 | | skyboxElements = new SkyboxElements(); |
| | 540 | | } |
| 0 | 541 | | } |
| | 542 | |
|
| | 543 | | void TakeControlAtRuntime() |
| | 544 | | { |
| 0 | 545 | | if (SkyboxController.i != null) |
| | 546 | | { |
| 0 | 547 | | isPaused = SkyboxController.i.IsPaused(); |
| 0 | 548 | | lifecycleDuration = (float)SkyboxController.i.lifecycleDuration; |
| 0 | 549 | | selectedConfiguration = SkyboxController.i.GetCurrentConfiguration(); |
| 0 | 550 | | overridingController = SkyboxController.i.SetOverrideController(true); |
| 0 | 551 | | timeOfTheDay = SkyboxController.i.GetCurrentTimeOfTheDay(); |
| 0 | 552 | | skyboxElements = SkyboxController.i.GetSkyboxElements(); |
| 0 | 553 | | UpdateConfigurationsList(); |
| | 554 | | } |
| 0 | 555 | | } |
| | 556 | |
|
| | 557 | | void InitializeMaterial() |
| | 558 | | { |
| 0 | 559 | | selectedMat = MaterialReferenceContainer.i.skyboxMat; |
| 0 | 560 | | selectedConfiguration.ResetMaterial(selectedMat, MaterialReferenceContainer.i.skyboxMatSlots); |
| 0 | 561 | | RenderSettings.skybox = selectedMat; |
| 0 | 562 | | } |
| | 563 | |
|
| 0 | 564 | | private void UpdateMaterial() { InitializeMaterial(); } |
| | 565 | |
|
| | 566 | | private SkyboxConfiguration AddNewConfiguration(string name) |
| | 567 | | { |
| | 568 | | SkyboxConfiguration temp = null; |
| 0 | 569 | | temp = ScriptableObject.CreateInstance<SkyboxConfiguration>(); |
| 0 | 570 | | temp.skyboxID = name; |
| | 571 | |
|
| 0 | 572 | | string path = AssetDatabase.GenerateUniqueAssetPath("Assets/Rendering/ProceduralSkybox/Resources/Skybox Conf |
| 0 | 573 | | AssetDatabase.CreateAsset(temp, path); |
| 0 | 574 | | AssetDatabase.SaveAssets(); |
| | 575 | |
|
| 0 | 576 | | return temp; |
| | 577 | | } |
| | 578 | |
|
| | 579 | | private void UpdateConfigurationsList() |
| | 580 | | { |
| 0 | 581 | | SkyboxConfiguration[] tConfigurations = Resources.LoadAll<SkyboxConfiguration>("Skybox Configurations/"); |
| 0 | 582 | | configurations = new List<SkyboxConfiguration>(tConfigurations); |
| 0 | 583 | | configurationNames = new List<string>(); |
| | 584 | |
|
| | 585 | | // If no configurations exist, make and select new one. |
| 0 | 586 | | if (configurations == null || configurations.Count < 1) |
| | 587 | | { |
| 0 | 588 | | selectedConfiguration = AddNewConfiguration(SkyboxEditorLiterals.Labels.defaultskyboxName); |
| | 589 | |
|
| 0 | 590 | | configurations = new List<SkyboxConfiguration>(); |
| 0 | 591 | | configurations.Add(selectedConfiguration); |
| | 592 | | } |
| | 593 | |
|
| 0 | 594 | | if (selectedConfiguration == null) |
| | 595 | | { |
| 0 | 596 | | selectedConfiguration = configurations[0]; |
| | 597 | | } |
| | 598 | |
|
| 0 | 599 | | for (int i = 0; i < configurations.Count; i++) |
| | 600 | | { |
| 0 | 601 | | configurations[i].skyboxID = configurations[i].name; |
| | 602 | |
|
| 0 | 603 | | configurationNames.Add(configurations[i].skyboxID); |
| 0 | 604 | | if (selectedConfiguration == configurations[i]) |
| | 605 | | { |
| 0 | 606 | | selectedConfigurationIndex = i; |
| | 607 | | } |
| | 608 | | } |
| | 609 | |
|
| 0 | 610 | | InitializeMaterial(); |
| | 611 | |
|
| 0 | 612 | | if (!Application.isPlaying) |
| | 613 | | { |
| 0 | 614 | | isPaused = true; |
| | 615 | | } |
| 0 | 616 | | } |
| | 617 | |
|
| 0 | 618 | | void ResumeTime() { isPaused = false; } |
| | 619 | |
|
| 0 | 620 | | void PauseTime() { isPaused = true; } |
| | 621 | |
|
| | 622 | | private void ApplyOnMaterial(bool isEditor) |
| | 623 | | { |
| 0 | 624 | | EnsureDependencies(); |
| 0 | 625 | | float normalizedDayTime = SkyboxUtils.GetNormalizedDayTime(timeOfTheDay); |
| 0 | 626 | | selectedConfiguration.ApplyOnMaterial(selectedMat, timeOfTheDay, normalizedDayTime, MaterialReferenceContain |
| | 627 | |
|
| 0 | 628 | | skyboxElements?.ApplyConfigTo3DElements(selectedConfiguration, timeOfTheDay, normalizedDayTime, directionalL |
| | 629 | |
|
| | 630 | | // If in play mode, call avatar color from skybox controller class |
| 0 | 631 | | if (Application.isPlaying && SkyboxController.i != null) |
| | 632 | | { |
| 0 | 633 | | SkyboxController.i.ApplyAvatarColor(normalizedDayTime); |
| | 634 | | } |
| 0 | 635 | | } |
| | 636 | | } |
| | 637 | | } |