// Unity doesn't supporty polymorphic serialization, so we split into type safe lists. public void OnBeforeSerialize() { m_ColorGroup.Clear(); m_NumberGroup.Clear(); m_TextureGroup.Clear(); m_SpherePointGroup.Clear(); m_BoolGroup.Clear(); foreach (string key in m_Groups.Keys) { IKeyframeGroup obj = m_Groups[key]; if (obj is ColorKeyframeGroup) { m_ColorGroup[key] = obj as ColorKeyframeGroup; } else if (obj is NumberKeyframeGroup) { m_NumberGroup[key] = obj as NumberKeyframeGroup; } else if (obj is TextureKeyframeGroup) { m_TextureGroup[key] = obj as TextureKeyframeGroup; } else if (obj is SpherePointKeyframeGroup) { m_SpherePointGroup[key] = obj as SpherePointKeyframeGroup; } else if (obj is BoolKeyframeGroup) { m_BoolGroup[key] = obj as BoolKeyframeGroup; } } }
public static void SetKeyframeData(IBaseKeyframe keyframe, IKeyframeGroup group, KeyType keyType, SkyProfile profile) { KeyframeInspectorWindow.keyframe = keyframe; KeyframeInspectorWindow.@group = group; KeyframeInspectorWindow.keyType = keyType; KeyframeInspectorWindow.profile = profile; }
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(); }
public void TrimGroupToSingleKeyframe(string propertyKey) { IKeyframeGroup group = GetGroup(propertyKey); if (group == null) { return; } group.TrimToSingleKeyframe(); }
public IKeyframeGroup GetGroupWithId(string groupId) { if (groupId == null) { return(null); } foreach (string key in keyframeGroups) { IKeyframeGroup group = keyframeGroups[key]; if (group.id == groupId) { return(group); } } return(null); }
// If sphere point group is selected, we render dots in the skybox to help user position things. private void RenderSpherePointGroupDebugPointsIfSelected() { if (m_ActiveSkyProfile == null || TimelineSelection.selectedGroupUUID == null) { return; } IKeyframeGroup group = m_ActiveSkyProfile.GetGroupWithId(TimelineSelection.selectedGroupUUID); if (group is SpherePointKeyframeGroup) { ShowSpherePointKeyframesInSkybox(group as SpherePointKeyframeGroup); } else { HideDebugPoints(); } }
private bool RenderTimelineList() { bool didChangeProfile = false; RenderSectionTitle("Timeline Animated Properties", "TimelineSectionIcon"); EditorGUILayout.Space(); List <ProfileGroupDefinition> onTimeline = m_Profile.GetGroupDefinitionsManagedByTimeline(); List <ProfileGroupDefinition> offTimeline = m_Profile.GetGroupDefinitionsNotManagedByTimeline(); int deleteIndex = -1; bool didSwapRows = false; int swapIndex1 = -1; int swapIndex2 = -1; if (onTimeline.Count == 0) { // Show definition message if no items added yet. EditorGUILayout.HelpBox("You can animate properties by adding them to the timeline.", MessageType.None); } else { EditorGUI.BeginChangeCheck(); List <string> timelineTitles = GetTitlesForGroups(onTimeline); StringTableListGUI.RenderTableList( timelineTitles, out deleteIndex, out didSwapRows, out swapIndex1, out swapIndex2); // Check for table modification events (remove, reorder, etc.) if (EditorGUI.EndChangeCheck()) { didChangeProfile = true; if (deleteIndex != -1) { string deleteGroupKey = onTimeline[deleteIndex].propertyKey; IKeyframeGroup group = m_Profile.GetGroup(deleteGroupKey); if (SkyEditorUtility.IsGroupSelectedOnTimeline(group.id)) { TimelineSelection.Clear(); // If we deleted a sphere point group make sure to hide the debug dots. if (group is SpherePointKeyframeGroup && m_Profile.skyboxMaterial != null) { m_Profile.skyboxMaterial.DisableKeyword(ShaderKeywords.RenderDebugPoints); } } m_Profile.timelineManagedKeys.Remove(deleteGroupKey); m_Profile.TrimGroupToSingleKeyframe(deleteGroupKey); } else if (didSwapRows) { string tmp = m_Profile.timelineManagedKeys[swapIndex2]; m_Profile.timelineManagedKeys[swapIndex2] = m_Profile.timelineManagedKeys[swapIndex1]; m_Profile.timelineManagedKeys[swapIndex1] = tmp; } } } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Open Timeline"))) { SkyTimelineWindow.ShowWindow(); } if (GUILayout.Button(new GUIContent("Add to Timeline"))) { SkyGUITimelineMenu.ShowAddTimelinePropertyMenu(m_Profile, offTimeline); } EditorGUILayout.EndHorizontal(); return(didChangeProfile); }
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(); } }