public override void OnInspectorGUI()
        {
            serializedObject.Update();

            m_Profile = (SkyProfile)target;

            // For new profiles we'll automatically build them.
            if (forceRebuildProfileId != -1 && forceRebuildProfileId == m_Profile.GetInstanceID())
            {
                RebuildSkySystem();
                forceRebuildProfileId = -1;
            }

            if (RenderSkyboxMaterial() == false)
            {
                serializedObject.ApplyModifiedProperties();
                return;
            }

            if (m_Sections == null)
            {
                m_Sections = new Dictionary <string, ProfileFeatureSection>();
            }

            foreach (ProfileFeatureSection section in m_Profile.featureDefinitions)
            {
                m_Sections[section.sectionKey] = section;
            }

            bool didChangeProfile = false;

            // Features.
            if (RenderFeatureSection())
            {
                didChangeProfile = true;
            }

            // Timeline.
            if (RenderTimelineList())
            {
                didChangeProfile = true;
            }

            // Properties.
            if (RenderProfileDefinitions())
            {
                didChangeProfile = true;
            }

            TimeOfDayController tc = GameObject.FindObjectOfType <TimeOfDayController>();

            if (tc != null)
            {
                tc.UpdateSkyForCurrentTime();
            }

            serializedObject.ApplyModifiedProperties();

            if (didChangeProfile)
            {
                EditorUtility.SetDirty(m_Profile);
            }
        }
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;
        }