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