UpgradeSkySystemController.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEditor.SceneManagement;
  6. namespace Funly.SkyStudio
  7. {
  8. public class UpgradeSkySystemController : Editor
  9. {
  10. [MenuItem("Window/Sky Studio/Upgrade Sky System Controller...")]
  11. public static void UpgradeSetupSkySystem() {
  12. TimeOfDayController oldTc = GameObject.FindObjectOfType<TimeOfDayController>();
  13. if (oldTc == null) {
  14. EditorUtility.DisplayDialog("Sky Upgrade Failed", "There is no SkySystemController in your current scene to upgrade. Try using the Setup Sky tool to create a sky system instead.", "OK");
  15. return;
  16. }
  17. GameObject skySystemPrefab = SkyEditorUtility.LoadEditorPrefab(SkySetupWindow.SKY_CONTROLLER_PREFAB);
  18. if (skySystemPrefab == null) {
  19. Debug.LogError("Failed to locate sky controller prefab");
  20. EditorUtility.DisplayDialog("Sky Upgrade Failed", "Failed to locate SkySystemController prefab. Did you move the prefab or rename any Sky Studio folders? Delete FunlySkyStudio and reinstall the asset package.", "OK");
  21. return;
  22. }
  23. TimeOfDayController tc = Instantiate(skySystemPrefab).GetComponent<TimeOfDayController>();
  24. tc.name = SkySetupWindow.SKY_CONTROLLER_PREFAB;
  25. tc.skyProfile = oldTc.skyProfile;
  26. tc.skyTime = oldTc.skyTime;
  27. tc.automaticIncrementSpeed = oldTc.automaticIncrementSpeed;
  28. tc.automaticTimeIncrement = oldTc.automaticTimeIncrement;
  29. DestroyImmediate(oldTc.gameObject);
  30. EditorUtility.SetDirty(tc);
  31. EditorUtility.SetDirty(tc.gameObject);
  32. EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  33. EditorUtility.DisplayDialog("Sky Upgrade Complete", "The SkySystemController in your current scene has been upgraded, and is using the latest Sky Studio prefab.", "OK");
  34. }
  35. }
  36. }