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