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");
        }
Exemplo n.º 2
0
        private void DidClickAddNewKeyframe(TimeOfDayController tc)
        {
            IKeyframeGroup selectedGroup = tc.skyProfile.GetGroupWithId(TimelineSelection.selectedGroupUUID);

            if (selectedGroup == null)
            {
                Debug.LogError("Can't insert keyframe since no group was fould for selected UUID.");
                return;
            }

            Undo.RecordObject(tc.skyProfile, "Keyframe inserted into group.");

            if (selectedGroup is ColorKeyframeGroup)
            {
                InsertKeyframeInColorGroup(tc.timeOfDay, selectedGroup as ColorKeyframeGroup);
            }
            else if (selectedGroup is NumberKeyframeGroup)
            {
                InsertKeyframeInNumericGroup(tc.timeOfDay, selectedGroup as NumberKeyframeGroup);
            }
            else if (selectedGroup is SpherePointKeyframeGroup)
            {
                InsertKeyframeInSpherePointGroup(tc.timeOfDay, selectedGroup as SpherePointKeyframeGroup);
            }

            EditorUtility.SetDirty(tc.skyProfile);
            Repaint();
        }
Exemplo n.º 3
0
        // These are the buttons next to the current time of day at the top.
        private void RenderGlobalTimelineButtons(Rect rect, TimeOfDayController tc)
        {
            GUILayout.BeginArea(rect);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            float buttonSize           = 20.0f;
            Color originalContentColor = GUI.contentColor;

            GUI.contentColor = GUI.skin.label.normal.textColor;

            GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);

            buttonStyle.padding = new RectOffset(2, 2, 2, 2);


            Texture2D addTexture = SkyEditorUtility.LoadEditorResourceTexture("AddIcon");

            bool didClickAddButton = GUILayout.Button(
                new GUIContent(addTexture, "Add a sky property to the timeline."),
                buttonStyle, GUILayout.Width(buttonSize), GUILayout.Height(buttonSize));

            GUILayout.Space(LEFT_INSET);
            if (didClickAddButton)
            {
                SkyGUITimelineMenu.ShowAddTimelinePropertyMenu(m_ActiveSkyProfile);
            }

            GUI.contentColor = originalContentColor;
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
Exemplo n.º 4
0
        private void UpdateTimeControllerInScene()
        {
            TimeOfDayController timeController = FindObjectOfType <TimeOfDayController>() as TimeOfDayController;

            if (!timeController)
            {
                return;
            }

            timeController.UpdateSkyForCurrentTime();
        }
Exemplo n.º 5
0
        private void RenderTimelineCursor(Rect rect, TimeOfDayController timeController)
        {
            // Flag the start of a timeline drag.
            if (TimelineSelection.isDraggingTimeline == false &&
                (Event.current.type == EventType.MouseDrag) &&
                rect.Contains(Event.current.mousePosition))
            {
                TimelineSelection.isDraggingTimeline = true;
            }

            if (TimelineSelection.isDraggingTimeline)
            {
                float percent = Mathf.Clamp((Event.current.mousePosition.x - rect.x) / rect.width, 0, MAX_TIME_VALUE);
                timeController.skyTime = percent;
                EditorUtility.SetDirty(timeController);
            }

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            float playHeadHeight = PLAYHEAD_WIDTH / 2.0f;

            float xCursorPos = SkyEditorUtility.GetXPositionForPercent(rect, timeController.timeOfDay);

            // Draw the line that overlaps all the content rows.
            const float extensionSize = 5.0f;
            Rect        lineRect      = new Rect(
                xCursorPos - (CURSOR_LINE_WIDTH / 2.0f),
                rect.y + TIME_HEADER_HEIGHT - extensionSize,
                CURSOR_LINE_WIDTH,
                rect.height - TIME_HEADER_HEIGHT + extensionSize);

            GUI.DrawTexture(lineRect, SkyEditorUtility.LoadEditorResourceTexture("CursorLine"));

            // Draw the playhead arrow.
            if (m_PlayheadTexture == null)
            {
                m_PlayheadTexture = SkyEditorUtility.LoadEditorResourceTexture("PlayheadArrow");
            }

            Rect headRect = new Rect(
                xCursorPos - (PLAYHEAD_WIDTH / 2.0f),
                rect.y + TIME_HEADER_HEIGHT - playHeadHeight,
                PLAYHEAD_WIDTH,
                playHeadHeight);

            GUI.DrawTexture(headRect, m_PlayheadTexture, ScaleMode.StretchToFill, true);
        }
Exemplo n.º 6
0
        private void BuilderCompletion(SkyBuilder builder, bool successful)
        {
            m_Builder.completionCallback -= BuilderCompletion;
            m_Builder = null;

            if (m_Profile)
            {
                EditorUtility.SetDirty(m_Profile);
            }

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

            if (tc != null)
            {
                tc.UpdateSkyForCurrentTime();
            }
        }
Exemplo n.º 7
0
        private void RenderHeaderButtons(Rect rect, TimeOfDayController tc)
        {
            RenderTimeLabel(tc.timeOfDay);

            Rect buttonsRect = new Rect(
                rect.x, rect.y + ICON_BUTTON_SIZE,
                rect.width, rect.height - ICON_BUTTON_SIZE);

            RenderGlobalTimelineButtons(buttonsRect, tc);

            // Divider.
            Rect dividerRect = new Rect(
                rect.x,
                rect.y + TIME_HEADER_HEIGHT - HORIZONTAL_DIVIDER_HEIGHT,
                rect.width,
                HORIZONTAL_DIVIDER_HEIGHT);

            RenderHorizontalDivider(dividerRect);
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
0
 void Start()
 {
     skycontroller = GetComponent <TimeOfDayController>();
 }
Exemplo n.º 11
0
        private void OnGUI()
        {
            LoadStyles();

            TimeOfDayController timeController = FindObjectOfType <TimeOfDayController>() as TimeOfDayController;

            // Render a setup helper UI.
            if (timeController == null)
            {
                RenderNeedsSkySetupLayout();
                return;
            }

            // Render a profile help message UI.
            if (timeController.skyProfile == null)
            {
                RenderNeedsProfileLayout();
                return;
            }

            m_ActiveTimeController = timeController;
            m_ActiveSkyProfile     = timeController ? timeController.skyProfile : null;

            RebuildTimelineDefinitions(timeController.skyProfile);
            float contentHeight  = CalculateWindowContentHeight(timeController.skyProfile);
            float scrollbarInset = 0;

            // Select the first colorGroup if one isn't selected.
            if (TimelineSelection.selectedGroupUUID == null &&
                timeController.skyProfile.timelineManagedKeys.Count > 0)
            {
                IKeyframeGroup group = timeController.skyProfile.GetGroup(timeController.skyProfile.timelineManagedKeys[0]);
                if (group != null)
                {
                    TimelineSelection.selectedGroupUUID = group.id;
                }
            }

            // Inset content on the right to make room for scroll bar.
            if (contentHeight > position.height)
            {
                scrollbarInset = CONTENT_INSET;
            }

            // Timeline rect.
            Rect contentRect = new Rect(
                0,
                0,
                position.width - scrollbarInset,
                position.height);

            // Check if mouse left the window, and cancel drag operations.
            if (Event.current.type == EventType.MouseLeaveWindow ||
                contentRect.Contains(Event.current.mousePosition) == false)
            {
                SkyEditorUtility.CancelTimelineDrags();
            }

            // Loads the list of timeline groups to render.
            RenderTimelineEditor(contentRect, timeController, contentHeight);

            // Save the edits to the profile object.
            if (timeController != null)
            {
                EditorUtility.SetDirty(timeController.skyProfile);

                // Keep the scene view rendering in sync for live editing.
                timeController.UpdateSkyForCurrentTime();
            }
        }
Exemplo n.º 12
0
        private void RenderTimelineEditor(Rect rect, TimeOfDayController timeController, float contentHeight)
        {
            float nameColMinX   = rect.x;
            float valueColMinX  = nameColMinX + NAME_COLUMN_WIDTH;
            float valueColMaxX  = rect.xMax;
            float valueColWidth = rect.width - NAME_COLUMN_WIDTH;

            // Check for the end of a timeline drag.
            if (TimelineSelection.isDraggingTimeline && Event.current.type == EventType.MouseUp)
            {
                TimelineSelection.isDraggingTimeline = false;
            }

            // If we're busy dragging the timeline, consume the events so child views don't see them.
            if (Event.current.type == EventType.MouseDrag && TimelineSelection.isDraggingTimeline)
            {
                Event.current.Use();
            }

            // Check if user dragged in the time ruler so we don't click things behind it.
            if (DidDragTimeRuler())
            {
                SkyEditorUtility.CancelTimelineDrags();
                TimelineSelection.isDraggingTimeline = true;
                Event.current.Use();
            }

            float fullContentHeight = Mathf.Max(position.height, contentHeight);

            // Background style.
            RenderBackground();

            // Render timeline buttons at header.
            Rect toolbarRect = new Rect(nameColMinX,
                                        rect.y, NAME_COLUMN_WIDTH, TIME_HEADER_HEIGHT);

            RenderHeaderButtons(toolbarRect, timeController);

            // Render Scrubber.
            Rect timeScrubberRect = new Rect(valueColMinX, rect.y,
                                             valueColWidth - VALUE_COLUMN_INSET, TIME_HEADER_HEIGHT);

            RenderTimeRuler(timeScrubberRect, timeController.timeOfDay);

            // Show an empty content help message.
            if (timeController.skyProfile.timelineManagedKeys.Count == 0)
            {
                RenderEmptyTimelineMessage();
            }

            Rect innerScrollViewContent = new Rect(
                0,
                0,
                rect.width,
                contentHeight - TIME_HEADER_HEIGHT);

            Rect scrollWindowPosition = new Rect(0, TIME_HEADER_HEIGHT, position.width, rect.height - TIME_HEADER_HEIGHT);

            m_ScrollPosition = GUI.BeginScrollView(scrollWindowPosition, m_ScrollPosition, innerScrollViewContent, false, false);

            // Render all the content rows.
            Rect rowsRect = new Rect(rect.x, 0, rect.width, 0);

            RenderAllRows(rowsRect, timeController.skyProfile);
            RenderSpherePointGroupDebugPointsIfSelected();

            GUI.EndScrollView();

            // Draw the cursor, which overlaps the other content.
            Rect cursorRect = new Rect(
                valueColMinX, rect.y, valueColWidth - VALUE_COLUMN_INSET, fullContentHeight);

            RenderTimelineCursor(cursorRect, timeController);
        }