EnviroManagerBase.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Enviro
  5. {
  6. [System.Serializable]
  7. public class GeneralObjects
  8. {
  9. public GameObject sun;
  10. public GameObject moon;
  11. public GameObject stars;
  12. public Light directionalLight;
  13. public Light additionalDirectionalLight;
  14. public EnviroReflectionProbe globalReflectionProbe;
  15. public GameObject effects;
  16. public GameObject audio;
  17. }
  18. [System.Serializable]
  19. public class EnviroCameras
  20. {
  21. public Camera camera;
  22. public EnviroQuality quality;
  23. }
  24. public class EnviroManagerBase : MonoBehaviour
  25. {
  26. //Modules
  27. public EnviroConfiguration configuration;
  28. [SerializeField]
  29. private EnviroConfiguration lastConfiguration;
  30. public EnviroTimeModule Time;
  31. public EnviroLightingModule Lighting;
  32. public EnviroSkyModule Sky;
  33. public EnviroFogModule Fog;
  34. public EnviroVolumetricCloudsModule VolumetricClouds;
  35. public EnviroFlatCloudsModule FlatClouds;
  36. public EnviroWeatherModule Weather;
  37. public EnviroAuroraModule Aurora;
  38. public EnviroAudioModule Audio;
  39. public EnviroEffectsModule Effects;
  40. public EnviroLightningModule Lightning;
  41. public EnviroQualityModule Quality;
  42. public EnviroEnvironmentModule Environment;
  43. public EnviroEventModule Events;
  44. //Enum
  45. public enum ModuleType
  46. {
  47. Time,
  48. Lighting,
  49. Sky,
  50. Fog,
  51. VolumetricClouds,
  52. FlatClouds,
  53. Weather,
  54. Aurora,
  55. Effects,
  56. Lightning,
  57. Environment,
  58. Audio,
  59. Quality,
  60. Events
  61. }
  62. public void EnableModules()
  63. {
  64. if(Time != null)
  65. Time.Enable();
  66. if(Sky != null)
  67. Sky.Enable();
  68. if(Lighting != null)
  69. Lighting.Enable();
  70. if(VolumetricClouds != null)
  71. VolumetricClouds.Enable();
  72. if(FlatClouds != null)
  73. FlatClouds.Enable();
  74. if(Fog != null)
  75. Fog.Enable();
  76. if(Weather != null)
  77. Weather.Enable();
  78. if(Aurora != null)
  79. Aurora.Enable();
  80. if(Environment != null)
  81. Environment.Enable();
  82. if(Audio != null)
  83. Audio.Enable();
  84. if(Effects != null)
  85. Effects.Enable();
  86. if(Lightning != null)
  87. Lightning.Enable();
  88. if(Quality != null)
  89. Quality.Enable();
  90. if(Events != null)
  91. Events.Enable();
  92. }
  93. public void DisableModules()
  94. {
  95. if(Time != null)
  96. Time.Disable();
  97. if(Sky != null)
  98. Sky.Disable();
  99. if(Lighting != null)
  100. Lighting.Disable();
  101. if(VolumetricClouds != null)
  102. VolumetricClouds.Disable();
  103. if(FlatClouds != null)
  104. FlatClouds.Disable();
  105. if(Fog != null)
  106. Fog.Disable();
  107. if(Weather != null)
  108. Weather.Disable();
  109. if(Aurora != null)
  110. Aurora.Disable();
  111. if(Environment != null)
  112. Environment.Disable();
  113. if(Audio != null)
  114. Audio.Disable();
  115. if(Effects != null)
  116. Effects.Disable();
  117. if(Lightning != null)
  118. Lightning.Disable();
  119. if(Quality != null)
  120. Quality.Disable();
  121. if(Events != null)
  122. Events.Disable();
  123. }
  124. public void DisableAndRemoveModules()
  125. {
  126. if(Time != null)
  127. {
  128. Time.Disable();
  129. Time = null;
  130. }
  131. if(Sky != null)
  132. {
  133. Sky.Disable();
  134. Sky = null;
  135. }
  136. if(Lighting != null)
  137. {
  138. Lighting.Disable();
  139. Lighting = null;
  140. }
  141. if(VolumetricClouds != null)
  142. {
  143. VolumetricClouds.Disable();
  144. VolumetricClouds = null;
  145. }
  146. if(FlatClouds != null)
  147. {
  148. FlatClouds.Disable();
  149. FlatClouds = null;
  150. }
  151. if(Fog != null)
  152. {
  153. Fog.Disable();
  154. Fog = null;
  155. }
  156. if(Weather != null)
  157. {
  158. Weather.Disable();
  159. Weather = null;
  160. }
  161. if(Aurora != null)
  162. {
  163. Aurora.Disable();
  164. Aurora = null;
  165. }
  166. if(Environment != null)
  167. {
  168. Environment.Disable();
  169. Environment = null;
  170. }
  171. if(Audio != null)
  172. {
  173. Audio.Disable();
  174. Audio = null;
  175. }
  176. if(Effects != null)
  177. {
  178. Effects.Disable();
  179. Effects = null;
  180. }
  181. if(Lightning != null)
  182. {
  183. Lightning.Disable();
  184. Lightning = null;
  185. }
  186. if(Quality != null)
  187. {
  188. Quality.Disable();
  189. Quality = null;
  190. }
  191. if(Events != null)
  192. {
  193. Events.Disable();
  194. Events = null;
  195. }
  196. }
  197. public void StartModules ()
  198. {
  199. if(Time != null)
  200. {
  201. Time = Instantiate(Time);
  202. }
  203. if(Sky != null)
  204. {
  205. Sky = Instantiate(Sky);
  206. }
  207. if(Lighting != null)
  208. {
  209. Lighting = Instantiate(Lighting);
  210. }
  211. if(Fog != null)
  212. {
  213. Fog = Instantiate(Fog);
  214. }
  215. if(VolumetricClouds != null)
  216. {
  217. VolumetricClouds = Instantiate(VolumetricClouds);
  218. }
  219. if(FlatClouds != null)
  220. {
  221. FlatClouds = Instantiate(FlatClouds);
  222. }
  223. if(Weather != null)
  224. {
  225. Weather = Instantiate(Weather);
  226. }
  227. if(Aurora != null)
  228. {
  229. Aurora = Instantiate(Aurora);
  230. }
  231. if(Environment != null)
  232. {
  233. Environment = Instantiate(Environment);
  234. }
  235. if(Audio != null)
  236. {
  237. Audio = Instantiate(Audio);
  238. }
  239. if(Effects != null)
  240. {
  241. Effects = Instantiate(Effects);
  242. }
  243. if(Lightning != null)
  244. {
  245. Lightning = Instantiate(Lightning);
  246. }
  247. if(Quality != null)
  248. {
  249. Quality = Instantiate(Quality);
  250. }
  251. if(Events != null)
  252. {
  253. Events = Instantiate(Events);
  254. }
  255. }
  256. public void UpdateModules ()
  257. {
  258. if(Time != null)
  259. Time.UpdateModule();
  260. if(Sky != null)
  261. Sky.UpdateModule();
  262. if(Lighting != null)
  263. Lighting.UpdateModule();
  264. if(Fog != null)
  265. Fog.UpdateModule();
  266. if(VolumetricClouds != null)
  267. VolumetricClouds.UpdateModule();
  268. if(FlatClouds != null)
  269. FlatClouds.UpdateModule();
  270. if(Weather != null)
  271. Weather.UpdateModule();
  272. if(Aurora != null)
  273. Aurora.UpdateModule();
  274. if(Environment != null)
  275. Environment.UpdateModule();
  276. if(Audio != null)
  277. Audio.UpdateModule();
  278. if(Effects != null)
  279. Effects.UpdateModule();
  280. if(Lightning != null)
  281. Lightning.UpdateModule();
  282. if(Quality != null)
  283. Quality.UpdateModule();
  284. if(Events != null)
  285. Events.UpdateModule();
  286. }
  287. //Saves all the modules settings to its assigned presets.
  288. public void SaveAllModules()
  289. {
  290. if(Time != null && Time.preset != null)
  291. Time.SaveModuleValues(Time.preset);
  292. if(Sky != null && Sky.preset != null)
  293. Sky.SaveModuleValues(Sky.preset);
  294. if(Lighting != null && Lighting.preset != null)
  295. Lighting.SaveModuleValues(Lighting.preset);
  296. if(Fog != null && Fog.preset != null)
  297. Fog.SaveModuleValues(Fog.preset);
  298. if(VolumetricClouds != null && VolumetricClouds.preset != null)
  299. VolumetricClouds.SaveModuleValues(VolumetricClouds.preset);
  300. if(FlatClouds != null && FlatClouds.preset != null)
  301. FlatClouds.SaveModuleValues(FlatClouds.preset);
  302. if(Weather != null && Weather.preset != null)
  303. Weather.SaveModuleValues(Weather.preset);
  304. if(Aurora != null && Aurora.preset != null)
  305. Aurora.SaveModuleValues(Aurora.preset);
  306. if(Environment != null && Environment.preset != null)
  307. Environment.SaveModuleValues(Environment.preset);
  308. if(Audio != null && Audio.preset != null)
  309. Audio.SaveModuleValues(Audio.preset);
  310. if(Effects != null && Effects.preset != null)
  311. Effects.SaveModuleValues(Effects.preset);
  312. if(Lightning != null && Lightning.preset != null)
  313. Lightning.SaveModuleValues(Lightning.preset);
  314. if(Quality != null && Quality.preset != null)
  315. Quality.SaveModuleValues(Quality.preset);
  316. if(Events != null && Events.preset != null)
  317. Events.SaveModuleValues(Events.preset);
  318. #if UNITY_EDITOR
  319. UnityEditor.EditorUtility.SetDirty(configuration);
  320. #endif
  321. }
  322. //Loads all the modules settings from its assigned presets.
  323. public void LoadAllModules()
  324. {
  325. if(Time != null)
  326. Time.LoadModuleValues();
  327. if(Sky != null)
  328. Sky.LoadModuleValues();
  329. if(Lighting != null)
  330. Lighting.LoadModuleValues();
  331. if(Fog != null)
  332. Fog.LoadModuleValues();
  333. if(VolumetricClouds != null)
  334. VolumetricClouds.LoadModuleValues();
  335. if(FlatClouds != null)
  336. FlatClouds.LoadModuleValues();
  337. if(Weather != null)
  338. Weather.LoadModuleValues();
  339. if(Aurora != null)
  340. Aurora.LoadModuleValues();
  341. if(Environment != null)
  342. Environment.LoadModuleValues();
  343. if(Audio != null)
  344. Audio.LoadModuleValues();
  345. if(Effects != null)
  346. Effects.LoadModuleValues();
  347. if(Lightning != null)
  348. Lightning.LoadModuleValues();
  349. if(Quality != null)
  350. Quality.LoadModuleValues();
  351. if(Events != null)
  352. Events.LoadModuleValues();
  353. #if UNITY_EDITOR
  354. //Set the head configuration dirty to not loose our child values!
  355. UnityEditor.EditorUtility.SetDirty(configuration);
  356. #endif
  357. }
  358. public void LoadConfiguration()
  359. {
  360. if(configuration != null)
  361. {
  362. if(configuration != lastConfiguration)
  363. DisableModules();
  364. Time = configuration.timeModule;
  365. Sky = configuration.Sky;
  366. Lighting = configuration.lightingModule;
  367. VolumetricClouds = configuration.volumetricCloudModule;
  368. FlatClouds = configuration.flatCloudModule;
  369. Fog = configuration.fogModule;
  370. Weather = configuration.Weather;
  371. Aurora = configuration.Aurora;
  372. Environment = configuration.Environment;
  373. Audio = configuration.Audio;
  374. Effects = configuration.Effects;
  375. Lightning = configuration.Lightning;
  376. Quality = configuration.Quality;
  377. Events = configuration.Events;
  378. if(configuration != lastConfiguration)
  379. EnableModules();
  380. lastConfiguration = configuration;
  381. }
  382. else if (configuration == null)
  383. DisableAndRemoveModules();
  384. }
  385. //Adds a module based on ModelType
  386. public void AddModule (ModuleType type)
  387. {
  388. switch (type)
  389. {
  390. case ModuleType.Time:
  391. if(Time != null)
  392. {
  393. Debug.Log("Time module already attached!");
  394. return;
  395. }
  396. else
  397. {
  398. Time = ScriptableObject.CreateInstance<EnviroTimeModule>();
  399. Time.name = "Time Module";
  400. Time.preset = (EnviroTimeModule)EnviroHelper.GetDefaultPreset("Default Time Preset");
  401. Time.LoadModuleValues();
  402. Time.Enable();
  403. #if UNITY_EDITOR
  404. if(configuration != null && !Application.isPlaying)
  405. {
  406. configuration.timeModule = Time;
  407. #if UNITY_EDITOR
  408. UnityEditor.AssetDatabase.AddObjectToAsset(Time,configuration);
  409. UnityEditor.AssetDatabase.SaveAssets();
  410. UnityEditor.AssetDatabase.Refresh();
  411. #endif
  412. }
  413. #endif
  414. }
  415. break;
  416. case ModuleType.Sky:
  417. if(Sky != null)
  418. {
  419. Debug.Log("Sky module already attached!");
  420. return;
  421. }
  422. else
  423. {
  424. Sky = ScriptableObject.CreateInstance<EnviroSkyModule>();
  425. Sky.name = "Sky Module";
  426. Sky.preset = (EnviroSkyModule)EnviroHelper.GetDefaultPreset("Default Sky Preset");
  427. Sky.LoadModuleValues();
  428. Sky.Enable();
  429. if(configuration != null && !Application.isPlaying)
  430. {
  431. configuration.Sky = Sky;
  432. #if UNITY_EDITOR
  433. UnityEditor.AssetDatabase.AddObjectToAsset(Sky,configuration);
  434. UnityEditor.AssetDatabase.SaveAssets();
  435. UnityEditor.AssetDatabase.Refresh();
  436. #endif
  437. }
  438. }
  439. break;
  440. case ModuleType.Lighting:
  441. if(Lighting != null)
  442. {
  443. Debug.Log("Lighting module already attached!");
  444. return;
  445. }
  446. else
  447. {
  448. Lighting = ScriptableObject.CreateInstance<EnviroLightingModule>();
  449. Lighting.name = "Lighting Module";
  450. Lighting.preset = (EnviroLightingModule)EnviroHelper.GetDefaultPreset("Default Lighting Preset");
  451. Lighting.LoadModuleValues();
  452. Lighting.Enable();
  453. if(configuration != null && !Application.isPlaying)
  454. {
  455. configuration.lightingModule = Lighting;
  456. #if UNITY_EDITOR
  457. UnityEditor.AssetDatabase.AddObjectToAsset(Lighting,configuration);
  458. UnityEditor.AssetDatabase.SaveAssets();
  459. UnityEditor.AssetDatabase.Refresh();
  460. #endif
  461. }
  462. }
  463. break;
  464. case ModuleType.Fog:
  465. if(Fog != null)
  466. {
  467. Debug.Log("Fog module already attached!");
  468. return;
  469. }
  470. else
  471. {
  472. Fog = ScriptableObject.CreateInstance<EnviroFogModule>();
  473. Fog.name = "Fog Module";
  474. Fog.preset = (EnviroFogModule)EnviroHelper.GetDefaultPreset("Default Fog Preset");
  475. Fog.LoadModuleValues();
  476. Fog.Enable();
  477. if(configuration != null && !Application.isPlaying)
  478. {
  479. configuration.fogModule = Fog;
  480. #if UNITY_EDITOR
  481. UnityEditor.AssetDatabase.AddObjectToAsset(Fog,configuration);
  482. UnityEditor.AssetDatabase.SaveAssets();
  483. UnityEditor.AssetDatabase.Refresh();
  484. #endif
  485. }
  486. }
  487. break;
  488. case ModuleType.VolumetricClouds:
  489. if(VolumetricClouds != null)
  490. {
  491. Debug.Log("Volumetric clouds module already attached!");
  492. return;
  493. }
  494. else
  495. {
  496. VolumetricClouds = ScriptableObject.CreateInstance<EnviroVolumetricCloudsModule>();
  497. VolumetricClouds.name = "Volumetric Cloud Module";
  498. VolumetricClouds.preset = (EnviroVolumetricCloudsModule)EnviroHelper.GetDefaultPreset("Default Volumetric Clouds Preset");
  499. VolumetricClouds.LoadModuleValues();
  500. VolumetricClouds.Enable();
  501. if(configuration != null && !Application.isPlaying)
  502. {
  503. configuration.volumetricCloudModule = VolumetricClouds;
  504. #if UNITY_EDITOR
  505. UnityEditor.AssetDatabase.AddObjectToAsset(VolumetricClouds,configuration);
  506. UnityEditor.AssetDatabase.SaveAssets();
  507. UnityEditor.AssetDatabase.Refresh();
  508. #endif
  509. }
  510. }
  511. break;
  512. case ModuleType.FlatClouds:
  513. if(FlatClouds != null)
  514. {
  515. Debug.Log("Flat clouds module already attached!");
  516. return;
  517. }
  518. else
  519. {
  520. FlatClouds = ScriptableObject.CreateInstance<EnviroFlatCloudsModule>();
  521. FlatClouds.name = "Flat Clouds Module";
  522. FlatClouds.preset = (EnviroFlatCloudsModule)EnviroHelper.GetDefaultPreset("Default Flat Clouds Preset");
  523. FlatClouds.LoadModuleValues();
  524. FlatClouds.Enable();
  525. if(configuration != null && !Application.isPlaying)
  526. {
  527. configuration.flatCloudModule = FlatClouds;
  528. #if UNITY_EDITOR
  529. UnityEditor.AssetDatabase.AddObjectToAsset(FlatClouds,configuration);
  530. UnityEditor.AssetDatabase.SaveAssets();
  531. UnityEditor.AssetDatabase.Refresh();
  532. #endif
  533. }
  534. }
  535. break;
  536. case ModuleType.Weather:
  537. if(Weather != null)
  538. {
  539. Debug.Log("Weather module already attached!");
  540. return;
  541. }
  542. else
  543. {
  544. Weather = ScriptableObject.CreateInstance<EnviroWeatherModule>();
  545. Weather.name = "Weather Module";
  546. Weather.preset = (EnviroWeatherModule)EnviroHelper.GetDefaultPreset("Default Weather Preset");
  547. Weather.LoadModuleValues();
  548. Weather.Enable();
  549. if(configuration != null && !Application.isPlaying)
  550. {
  551. configuration.Weather = Weather;
  552. #if UNITY_EDITOR
  553. UnityEditor.AssetDatabase.AddObjectToAsset(Weather,configuration);
  554. UnityEditor.AssetDatabase.SaveAssets();
  555. UnityEditor.AssetDatabase.Refresh();
  556. #endif
  557. }
  558. }
  559. break;
  560. case ModuleType.Aurora:
  561. if(Aurora != null)
  562. {
  563. Debug.Log("Aurora module already attached!");
  564. return;
  565. }
  566. else
  567. {
  568. Aurora = ScriptableObject.CreateInstance<EnviroAuroraModule>();
  569. Aurora.name = "Aurora Module";
  570. Aurora.preset = (EnviroAuroraModule)EnviroHelper.GetDefaultPreset("Default Aurora Preset");
  571. Aurora.LoadModuleValues();
  572. Aurora.Enable();
  573. if(configuration != null && !Application.isPlaying)
  574. {
  575. configuration.Aurora = Aurora;
  576. #if UNITY_EDITOR
  577. UnityEditor.AssetDatabase.AddObjectToAsset(Aurora,configuration);
  578. UnityEditor.AssetDatabase.SaveAssets();
  579. UnityEditor.AssetDatabase.Refresh();
  580. #endif
  581. }
  582. }
  583. break;
  584. case ModuleType.Environment:
  585. if(Environment != null)
  586. {
  587. Debug.Log("Environment module already attached!");
  588. return;
  589. }
  590. else
  591. {
  592. Environment = ScriptableObject.CreateInstance<EnviroEnvironmentModule>();
  593. Environment.name = "Environment Module";
  594. Environment.preset = (EnviroEnvironmentModule)EnviroHelper.GetDefaultPreset("Default Environment Preset");
  595. Environment.LoadModuleValues();
  596. Environment.Enable();
  597. if(configuration != null && !Application.isPlaying)
  598. {
  599. configuration.Environment = Environment;
  600. #if UNITY_EDITOR
  601. UnityEditor.AssetDatabase.AddObjectToAsset(Environment,configuration);
  602. UnityEditor.AssetDatabase.SaveAssets();
  603. UnityEditor.AssetDatabase.Refresh();
  604. #endif
  605. }
  606. }
  607. break;
  608. case ModuleType.Audio:
  609. if(Audio != null)
  610. {
  611. Debug.Log("Audio module already attached!");
  612. return;
  613. }
  614. else
  615. {
  616. Audio = ScriptableObject.CreateInstance<EnviroAudioModule>();
  617. Audio.name = "Audio Module";
  618. Audio.preset = (EnviroAudioModule)EnviroHelper.GetDefaultPreset("Default Audio Preset");
  619. Audio.LoadModuleValues();
  620. Audio.Enable();
  621. if(configuration != null && !Application.isPlaying)
  622. {
  623. configuration.Audio = Audio;
  624. #if UNITY_EDITOR
  625. UnityEditor.AssetDatabase.AddObjectToAsset(Audio,configuration);
  626. UnityEditor.AssetDatabase.SaveAssets();
  627. UnityEditor.AssetDatabase.Refresh();
  628. #endif
  629. }
  630. }
  631. break;
  632. case ModuleType.Effects:
  633. if(Effects != null)
  634. {
  635. Debug.Log("Effects module already attached!");
  636. return;
  637. }
  638. else
  639. {
  640. Effects = ScriptableObject.CreateInstance<EnviroEffectsModule>();
  641. Effects.name = "Effects Module";
  642. Effects.preset = (EnviroEffectsModule)EnviroHelper.GetDefaultPreset("Default Effects Preset");
  643. Effects.LoadModuleValues();
  644. Effects.Enable();
  645. if(configuration != null && !Application.isPlaying)
  646. {
  647. configuration.Effects = Effects;
  648. #if UNITY_EDITOR
  649. UnityEditor.AssetDatabase.AddObjectToAsset(Effects,configuration);
  650. UnityEditor.AssetDatabase.SaveAssets();
  651. UnityEditor.AssetDatabase.Refresh();
  652. #endif
  653. }
  654. }
  655. break;
  656. case ModuleType.Lightning:
  657. if(Lightning != null)
  658. {
  659. Debug.Log("Lighting module already attached!");
  660. return;
  661. }
  662. else
  663. {
  664. Lightning = ScriptableObject.CreateInstance<EnviroLightningModule>();
  665. Lightning.name = "Lightning Module";
  666. Lightning.preset = (EnviroLightningModule)EnviroHelper.GetDefaultPreset("Default Lightning Preset");
  667. Lightning.LoadModuleValues();
  668. Lightning.Enable();
  669. if(configuration != null && !Application.isPlaying)
  670. {
  671. configuration.Lightning = Lightning;
  672. #if UNITY_EDITOR
  673. UnityEditor.AssetDatabase.AddObjectToAsset(Lightning,configuration);
  674. UnityEditor.AssetDatabase.SaveAssets();
  675. UnityEditor.AssetDatabase.Refresh();
  676. #endif
  677. }
  678. }
  679. break;
  680. case ModuleType.Quality:
  681. if(Quality != null)
  682. {
  683. Debug.Log("Quality module already attached!");
  684. return;
  685. }
  686. else
  687. {
  688. Quality = ScriptableObject.CreateInstance<EnviroQualityModule>();
  689. Quality.name = "Quality Module";
  690. Quality.preset = (EnviroQualityModule)EnviroHelper.GetDefaultPreset("Default Quality Module Preset");
  691. Quality.LoadModuleValues();
  692. Quality.Enable();
  693. if(configuration != null && !Application.isPlaying)
  694. {
  695. configuration.Quality = Quality;
  696. #if UNITY_EDITOR
  697. UnityEditor.AssetDatabase.AddObjectToAsset(Quality,configuration);
  698. UnityEditor.AssetDatabase.SaveAssets();
  699. UnityEditor.AssetDatabase.Refresh();
  700. #endif
  701. }
  702. }
  703. break;
  704. case ModuleType.Events:
  705. if(Events != null)
  706. {
  707. Debug.Log("Event module already attached!");
  708. return;
  709. }
  710. else
  711. {
  712. Events = ScriptableObject.CreateInstance<EnviroEventModule>();
  713. Events.name = "Event Module";
  714. Events.preset = (EnviroEventModule)EnviroHelper.GetDefaultPreset("Default Event Preset");
  715. Events.LoadModuleValues();
  716. Events.Enable();
  717. if(configuration != null && !Application.isPlaying)
  718. {
  719. configuration.Events = Events;
  720. #if UNITY_EDITOR
  721. UnityEditor.AssetDatabase.AddObjectToAsset(Events,configuration);
  722. UnityEditor.AssetDatabase.SaveAssets();
  723. UnityEditor.AssetDatabase.Refresh();
  724. #endif
  725. }
  726. }
  727. break;
  728. }
  729. }
  730. //Removes a module
  731. public void RemoveModule (ModuleType type)
  732. {
  733. switch (type)
  734. {
  735. case ModuleType.Time:
  736. if(Time != null)
  737. {
  738. Time.Disable();
  739. DestroyImmediate(Time,true);
  740. if(!Application.isPlaying)
  741. {
  742. #if UNITY_EDITOR
  743. DestroyImmediate(configuration.timeModule,true);
  744. UnityEditor.EditorUtility.SetDirty(configuration);
  745. UnityEditor.AssetDatabase.SaveAssets();
  746. UnityEditor.AssetDatabase.Refresh();
  747. #endif
  748. }
  749. }
  750. else
  751. {
  752. Debug.Log("No time module attached!");
  753. return;
  754. }
  755. break;
  756. case ModuleType.Sky:
  757. if(Sky != null)
  758. {
  759. Sky.Disable();
  760. DestroyImmediate(Sky,true);
  761. if(!Application.isPlaying)
  762. {
  763. DestroyImmediate(configuration.Sky,true);
  764. #if UNITY_EDITOR
  765. UnityEditor.EditorUtility.SetDirty(configuration);
  766. UnityEditor.AssetDatabase.SaveAssets();
  767. UnityEditor.AssetDatabase.Refresh();
  768. #endif
  769. }
  770. }
  771. else
  772. {
  773. Debug.Log("No sky module attached!");
  774. return;
  775. }
  776. break;
  777. case ModuleType.Lighting:
  778. if(Lighting != null)
  779. {
  780. Lighting.Disable();
  781. DestroyImmediate(Lighting,true);
  782. if(!Application.isPlaying)
  783. {
  784. if(configuration != null)
  785. DestroyImmediate(configuration.lightingModule,true);
  786. #if UNITY_EDITOR
  787. UnityEditor.EditorUtility.SetDirty(configuration);
  788. UnityEditor.AssetDatabase.SaveAssets();
  789. UnityEditor.AssetDatabase.Refresh();
  790. #endif
  791. }
  792. }
  793. else
  794. {
  795. Debug.Log("No lighting module attached!");
  796. return;
  797. }
  798. break;
  799. case ModuleType.Fog:
  800. if(Fog != null)
  801. {
  802. Fog.Disable();
  803. DestroyImmediate(Fog,true);
  804. if(!Application.isPlaying)
  805. {
  806. if(configuration != null)
  807. DestroyImmediate(configuration.fogModule,true);
  808. #if UNITY_EDITOR
  809. UnityEditor.EditorUtility.SetDirty(configuration);
  810. UnityEditor.AssetDatabase.SaveAssets();
  811. UnityEditor.AssetDatabase.Refresh();
  812. #endif
  813. }
  814. }
  815. else
  816. {
  817. Debug.Log("No fog module attached!");
  818. return;
  819. }
  820. break;
  821. case ModuleType.VolumetricClouds:
  822. if(VolumetricClouds != null)
  823. {
  824. VolumetricClouds.Disable();
  825. DestroyImmediate(VolumetricClouds,true);
  826. if(!Application.isPlaying)
  827. {
  828. if(configuration != null)
  829. DestroyImmediate(configuration.volumetricCloudModule,true);
  830. #if UNITY_EDITOR
  831. UnityEditor.EditorUtility.SetDirty(configuration);
  832. UnityEditor.AssetDatabase.SaveAssets();
  833. UnityEditor.AssetDatabase.Refresh();
  834. #endif
  835. }
  836. }
  837. else
  838. {
  839. Debug.Log("No volumetric cloud module attached!");
  840. return;
  841. }
  842. break;
  843. case ModuleType.FlatClouds:
  844. if(FlatClouds != null)
  845. {
  846. FlatClouds.Disable();
  847. DestroyImmediate(FlatClouds,true);
  848. if(!Application.isPlaying)
  849. {
  850. if(configuration != null)
  851. DestroyImmediate(configuration.flatCloudModule,true);
  852. #if UNITY_EDITOR
  853. UnityEditor.EditorUtility.SetDirty(configuration);
  854. UnityEditor.AssetDatabase.SaveAssets();
  855. UnityEditor.AssetDatabase.Refresh();
  856. #endif
  857. }
  858. }
  859. else
  860. {
  861. Debug.Log("No flat cloud module attached!");
  862. return;
  863. }
  864. break;
  865. case ModuleType.Weather:
  866. if(Weather != null)
  867. {
  868. Weather.Disable();
  869. DestroyImmediate(Weather,true);
  870. if(!Application.isPlaying)
  871. {
  872. if(configuration != null)
  873. DestroyImmediate(configuration.Weather,true);
  874. #if UNITY_EDITOR
  875. UnityEditor.EditorUtility.SetDirty(configuration);
  876. UnityEditor.AssetDatabase.SaveAssets();
  877. UnityEditor.AssetDatabase.Refresh();
  878. #endif
  879. }
  880. }
  881. else
  882. {
  883. Debug.Log("No weather module attached!");
  884. return;
  885. }
  886. break;
  887. case ModuleType.Aurora:
  888. if(Aurora != null)
  889. {
  890. Aurora.Disable();
  891. DestroyImmediate(Aurora,true);
  892. if(!Application.isPlaying)
  893. {
  894. if(configuration != null)
  895. DestroyImmediate(configuration.Aurora,true);
  896. #if UNITY_EDITOR
  897. UnityEditor.EditorUtility.SetDirty(configuration);
  898. UnityEditor.AssetDatabase.SaveAssets();
  899. UnityEditor.AssetDatabase.Refresh();
  900. #endif
  901. }
  902. }
  903. else
  904. {
  905. Debug.Log("No aurora module attached!");
  906. return;
  907. }
  908. break;
  909. case ModuleType.Environment:
  910. if(Environment != null)
  911. {
  912. Environment.Disable();
  913. DestroyImmediate(Environment,true);
  914. if(!Application.isPlaying)
  915. {
  916. if(configuration != null)
  917. DestroyImmediate(configuration.Environment,true);
  918. #if UNITY_EDITOR
  919. UnityEditor.EditorUtility.SetDirty(configuration);
  920. UnityEditor.AssetDatabase.SaveAssets();
  921. UnityEditor.AssetDatabase.Refresh();
  922. #endif
  923. }
  924. }
  925. else
  926. {
  927. Debug.Log("No environment module attached!");
  928. return;
  929. }
  930. break;
  931. case ModuleType.Audio:
  932. if(Audio != null)
  933. {
  934. Audio.Disable();
  935. DestroyImmediate(Audio,true);
  936. if(!Application.isPlaying)
  937. {
  938. if(configuration != null)
  939. DestroyImmediate(configuration.Audio,true);
  940. #if UNITY_EDITOR
  941. UnityEditor.EditorUtility.SetDirty(configuration);
  942. UnityEditor.AssetDatabase.SaveAssets();
  943. UnityEditor.AssetDatabase.Refresh();
  944. #endif
  945. }
  946. }
  947. else
  948. {
  949. Debug.Log("No audio module attached!");
  950. return;
  951. }
  952. break;
  953. case ModuleType.Effects:
  954. if(Effects != null)
  955. {
  956. Effects.Disable();
  957. DestroyImmediate(Effects,true);
  958. if(!Application.isPlaying)
  959. {
  960. if(configuration != null)
  961. DestroyImmediate(configuration.Effects,true);
  962. #if UNITY_EDITOR
  963. UnityEditor.EditorUtility.SetDirty(configuration);
  964. UnityEditor.AssetDatabase.SaveAssets();
  965. UnityEditor.AssetDatabase.Refresh();
  966. #endif
  967. }
  968. }
  969. else
  970. {
  971. Debug.Log("No effects module attached!");
  972. return;
  973. }
  974. break;
  975. case ModuleType.Lightning:
  976. if(Lightning != null)
  977. {
  978. Lightning.Disable();
  979. DestroyImmediate(Lightning,true);
  980. if(!Application.isPlaying)
  981. {
  982. if(configuration != null)
  983. DestroyImmediate(configuration.Lightning,true);
  984. #if UNITY_EDITOR
  985. UnityEditor.EditorUtility.SetDirty(configuration);
  986. UnityEditor.AssetDatabase.SaveAssets();
  987. UnityEditor.AssetDatabase.Refresh();
  988. #endif
  989. }
  990. }
  991. else
  992. {
  993. Debug.Log("No lightning module attached!");
  994. return;
  995. }
  996. break;
  997. case ModuleType.Quality:
  998. if(Quality != null)
  999. {
  1000. Quality.Disable();
  1001. DestroyImmediate(Quality,true);
  1002. if(!Application.isPlaying)
  1003. {
  1004. if(configuration != null)
  1005. DestroyImmediate(configuration.Quality,true);
  1006. #if UNITY_EDITOR
  1007. UnityEditor.EditorUtility.SetDirty(configuration);
  1008. UnityEditor.AssetDatabase.SaveAssets();
  1009. UnityEditor.AssetDatabase.Refresh();
  1010. #endif
  1011. }
  1012. }
  1013. else
  1014. {
  1015. Debug.Log("No quality module attached!");
  1016. return;
  1017. }
  1018. break;
  1019. case ModuleType.Events:
  1020. if(Events != null)
  1021. {
  1022. Events.Disable();
  1023. DestroyImmediate(Events,true);
  1024. if(!Application.isPlaying)
  1025. {
  1026. if(configuration != null)
  1027. DestroyImmediate(configuration.Events,true);
  1028. #if UNITY_EDITOR
  1029. UnityEditor.EditorUtility.SetDirty(configuration);
  1030. UnityEditor.AssetDatabase.SaveAssets();
  1031. UnityEditor.AssetDatabase.Refresh();
  1032. #endif
  1033. }
  1034. }
  1035. else
  1036. {
  1037. Debug.Log("No events module attached!");
  1038. return;
  1039. }
  1040. break;
  1041. }
  1042. }
  1043. }
  1044. }