public static void UpgradeSetupSkySystem()
        {
            TimeOfDayController oldTc = GameObject.FindObjectOfType <TimeOfDayController>();

            if (oldTc == null)
            {
                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");
                return;
            }

            GameObject skySystemPrefab = SkyEditorUtility.LoadEditorPrefab(SkySetupWindow.SKY_CONTROLLER_PREFAB);

            if (skySystemPrefab == null)
            {
                Debug.LogError("Failed to locate sky controller prefab");
                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");
                return;
            }

            TimeOfDayController tc = Instantiate(skySystemPrefab).GetComponent <TimeOfDayController>();

            tc.name       = SkySetupWindow.SKY_CONTROLLER_PREFAB;
            tc.skyProfile = oldTc.skyProfile;
            tc.skyTime    = oldTc.skyTime;
            tc.automaticIncrementSpeed = oldTc.automaticIncrementSpeed;
            tc.automaticTimeIncrement  = oldTc.automaticTimeIncrement;

            DestroyImmediate(oldTc.gameObject);

            EditorUtility.SetDirty(tc);
            EditorUtility.SetDirty(tc.gameObject);
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());

            EditorUtility.DisplayDialog("Sky Upgrade Complete", "The SkySystemController in your current scene has been upgraded, and is using the latest Sky Studio prefab.", "OK");
        }
Esempio n. 2
0
        private void SetupSceneWithPreset(ProfilePreset preset)
        {
            ClearSkyControllers();

            Scene  currentScene         = SceneManager.GetActiveScene();
            string sceneDir             = Path.GetDirectoryName(currentScene.path);
            string profileContainerName = currentScene.name + " - Sky Data";
            string profileContainerDir  = SkyEditorUtility.GenerateUniqueFolder(sceneDir, profileContainerName, true);

            // Create new sky controller.
            GameObject skySystemPrefab = SkyEditorUtility.LoadEditorPrefab(SKY_CONTROLLER_PREFAB);

            if (skySystemPrefab == null)
            {
                Debug.LogError("Failed to locate sky controller prefab");
                return;
            }

            TimeOfDayController tc = Instantiate(skySystemPrefab).GetComponent <TimeOfDayController>();

            tc.name = SKY_CONTROLLER_PREFAB;

            // Create a new sky profile.
            string profileAssetPath = SkyEditorUtility.GenerateUniqueFilename(profileContainerDir, "SkyProfile", ".asset");

            AssetDatabase.CopyAsset(preset.assetPath, profileAssetPath);

            // Load the new SKy Profile.
            SkyProfile profile = AssetDatabase.LoadAssetAtPath(profileAssetPath, typeof(SkyProfile)) as SkyProfile;

            if (profile == null)
            {
                Debug.LogError("Failed to duplicate profile");
                return;
            }

            // Create the skybox material.
            Material skyboxMaterial = new Material(GetBestShaderForSkyProfile(profile));
            string   skyboxPath     = SkyEditorUtility.GenerateUniqueFilename(profileContainerDir, "SkyboxMaterial", ".mat");

            AssetDatabase.CreateAsset(skyboxMaterial, skyboxPath);
            profile.skyboxMaterial = skyboxMaterial;

            // Link things together.
            tc.skyProfile = profile;
            tc.skyProfile.skyboxMaterial = skyboxMaterial;
            tc.skyTime = .22f;

            // Configure the profile a bit and setup in the current scene.
            SkyProfileEditor.ApplyKeywordsToMaterial(tc.skyProfile, skyboxMaterial);
            SkyProfileEditor.forceRebuildProfileId = profile.GetInstanceID();

            RenderSettings.skybox = skyboxMaterial;

            ApplyDefaultSettings(profile);

            // Drop a lightning spawn area into the scene in case user enables the feature.
            if (!ContainsLightningSpawnArea())
            {
                CreateLightningSpawnArea();
            }

            EditorUtility.SetDirty(skyboxMaterial);
            EditorUtility.SetDirty(tc.skyProfile);
            EditorUtility.SetDirty(tc);
            EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());

            Selection.activeObject = tc.skyProfile;
        }