Ejemplo n.º 1
0
        /// <summary>
        /// Ensures that if a content scene is loaded, that scene is set active, rather than a lighting or manager scene.
        /// </summary>
        private void EditorUpdateContentScenes(bool activeSceneDirty)
        {
            if (!profile.UseLightingScene || !profile.EditorManageLoadedScenes)
            {   // Nothing to do here
                return;
            }

            if (!activeSceneDirty)
            {   // Nothing to do here either
                return;
            }

            bool      contentSceneIsActive    = false;
            SceneInfo firstLoadedContentScene = SceneInfo.Empty;

            foreach (SceneInfo contentScene in profile.ContentScenes)
            {
                Scene scene;
                if (EditorSceneUtils.GetSceneIfLoaded(contentScene, out scene))
                {
                    if (firstLoadedContentScene.IsEmpty)
                    {   // If this is the first loaded content scene we've found, store it for later
                        firstLoadedContentScene = contentScene;
                    }

                    Scene activeScene = EditorSceneManager.GetActiveScene();
                    if (activeScene.name == contentScene.Name)
                    {
                        contentSceneIsActive = true;
                    }
                }
            }

            if (!firstLoadedContentScene.IsEmpty)
            {     // If at least one content scene is loaded
                if (!contentSceneIsActive)
                { // And that content scene is NOT the active scene
                    // Set that content to be the active scene
                    Scene activeScene;
                    EditorSceneUtils.GetSceneIfLoaded(firstLoadedContentScene, out activeScene);
                    EditorSceneUtils.SetActiveScene(activeScene);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads all lighting scenes, extracts their lighting data, then caches that data in the profile.
        /// </summary>
        private async Task EditorUpdateCachedLighting()
        {
            // Clear out our lighting cache
            profile.ClearLightingCache();
            profile.EditorLightingCacheUpdateRequested = false;

            SceneInfo defaultLightingScene = profile.DefaultLightingScene;

            foreach (SceneInfo lightingScene in profile.LightingScenes)
            {
                // Load all our lighting scenes
                Scene scene;
                EditorSceneUtils.LoadScene(lightingScene, false, out scene);
            }

            // Wait for a moment so all loaded scenes have time to get set up
            await Task.Delay(100);

            foreach (SceneInfo lightingScene in profile.LightingScenes)
            {
                Scene scene;
                EditorSceneUtils.GetSceneIfLoaded(lightingScene, out scene);
                EditorSceneUtils.SetActiveScene(scene);

                SerializedObject lightingSettingsObject;
                SerializedObject renderSettingsObject;
                EditorSceneUtils.GetLightingAndRenderSettings(out lightingSettingsObject, out renderSettingsObject);

                // Copy the serialized objects into new structs
                RuntimeLightingSettings lightingSettings = default(RuntimeLightingSettings);
                RuntimeRenderSettings   renderSettings   = default(RuntimeRenderSettings);
                RuntimeSunlightSettings sunlightSettings = default(RuntimeSunlightSettings);

                lightingSettings = SerializedObjectUtils.CopySerializedObjectToStruct <RuntimeLightingSettings>(lightingSettingsObject, lightingSettings, "m_");
                renderSettings   = SerializedObjectUtils.CopySerializedObjectToStruct <RuntimeRenderSettings>(renderSettingsObject, renderSettings, "m_");

                // Extract sunlight settings based on sunlight object
                SerializedProperty sunProperty = renderSettingsObject.FindProperty("m_Sun");
                if (sunProperty == null)
                {
                    Debug.LogError("Sun settings may not be available in this version of Unity.");
                }
                else
                {
                    Light sunLight = (Light)sunProperty.objectReferenceValue;

                    if (sunLight != null)
                    {
                        sunlightSettings.UseSunlight = true;
                        sunlightSettings.Color       = sunLight.color;
                        sunlightSettings.Intensity   = sunLight.intensity;

                        Vector3 eulerAngles = sunLight.transform.eulerAngles;
                        sunlightSettings.XRotation = eulerAngles.x;
                        sunlightSettings.YRotation = eulerAngles.y;
                        sunlightSettings.ZRotation = eulerAngles.z;
                    }
                }

                profile.SetLightingCache(lightingScene, lightingSettings, renderSettings, sunlightSettings);
            }
        }