private void AddNumericGroup(string propKey, string groupName, float min, float max, float value) { NumberKeyframeGroup group = new NumberKeyframeGroup( groupName, min, max, new NumberKeyframe(0, value)); keyframeGroups[propKey] = group; }
private bool RenderNumericGUI() { NumberKeyframe numberKeyframe = keyframe as NumberKeyframe; if (numberKeyframe == null) { return(false); } NumberKeyframeGroup numberGroup = @group as NumberKeyframeGroup; if (numberGroup == null) { return(false); } bool didModify = false; EditorGUI.BeginChangeCheck(); float value = EditorGUILayout.FloatField(new GUIContent("Value"), numberKeyframe.value); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(profile, "Keyframe numeric value changed."); numberKeyframe.value = Mathf.Clamp(value, numberGroup.minValue, numberGroup.maxValue); didModify = true; } return(didModify); }
private void InsertKeyframeInNumericGroup(float time, NumberKeyframeGroup group) { NumberKeyframe previousKeyframe = group.GetPreviousKeyFrame(time); NumberKeyframe newKeyFrame = new NumberKeyframe(previousKeyframe); newKeyFrame.time = time; group.AddKeyFrame(newKeyFrame); KeyframeInspectorWindow.SetKeyframeData( newKeyFrame, group, KeyframeInspectorWindow.KeyType.Numeric, m_ActiveSkyProfile); }
// Access a numeric value from the sky profile (cloud density, horizon position, star size, etc.). public float GetNumberPropertyValue(string propertyKey, float timeOfDay) { NumberKeyframeGroup group = GetGroup <NumberKeyframeGroup>(propertyKey); if (group == null) { Debug.LogError("Can't find number group with property key: " + propertyKey); return(-1); } return(group.NumericValueAtTime(timeOfDay)); }
// Use vertex shader to fix aspect ratio. public static void RenderNumberGroup(Rect rect, SkyProfile profile, NumberKeyframeGroup group) { lock (profile) { bool sortKeyFrames = false; RenderLinePath(rect, group); for (int i = 0; i < group.keyframes.Count; i++) { NumberKeyframe currentKey = group.GetKeyframe(i); int nextIndex = (i + 1) % group.keyframes.Count; NumberKeyframe nextKey = group.GetKeyframe(nextIndex); // Clamp time if we're wrapping around. float nextTime = nextKey.time; if (nextTime <= currentKey.time) { nextTime = 1.0f; } bool didSingleClick = false; bool isDragging = false; bool keyframeUpdated = false; SkyEditorUtility.DrawNumericKeyMarker(rect, currentKey, group, profile, out didSingleClick, out isDragging, out keyframeUpdated); if (keyframeUpdated) { sortKeyFrames = true; } if (didSingleClick || isDragging) { KeyframeInspectorWindow.SetKeyframeData( currentKey, group, KeyframeInspectorWindow.KeyType.Numeric, profile); if (didSingleClick && KeyframeInspectorWindow.inspectorEnabled == false) { KeyframeInspectorWindow.ShowWindow(); } } } if (sortKeyFrames) { group.SortKeyframes(); } } }
private float GetMaxValueForGroup(NumberKeyframeGroup group) { float maxValue = 0; for (int i = 0; i < group.keyframes.Count; i++) { if (i == 0 || group.keyframes[i].value > maxValue) { maxValue = group.keyframes[i].value; } } return(maxValue); }
// Render a timeline of numeric keyframe positions. private void RenderNumericRowAndAdvance(ref Rect rect, SkyProfile profile, NumberKeyframeGroup group, ProfileGroupDefinition groupDefinition) { rect.height = NUMBER_ROW_HEIGHT; UpdateActiveSelectedRow(rect, group.id, groupDefinition.propertyKey); Rect valueRowRect; Rect nameRowRect; bool isActive; LoadRowInformation(ref rect, group.id, NUMBER_ROW_HEIGHT, out valueRowRect, out nameRowRect, out isActive); RenderRowTitle(nameRowRect, group.name, isActive, groupDefinition); NumberTimelineRow.RenderNumberGroup(valueRowRect, profile, group); }
// Render numeric properties with a slider. public bool RenderNumericGroupProperty(ProfileGroupDefinition def) { EditorGUILayout.BeginHorizontal(); NumberKeyframeGroup group = m_Profile.GetGroup <NumberKeyframeGroup>(def.propertyKey); EditorGUILayout.PrefixLabel(new GUIContent(group.name, def.tooltip)); bool valueChanged = false; if (m_Profile.IsManagedByTimeline(def.propertyKey)) { RenderManagedOnTimlineMessage(); } else { NumberKeyframe frame = group.GetKeyframe(0); if (def.formatStyle == ProfileGroupDefinition.FormatStyle.Integer) { EditorGUI.BeginChangeCheck(); int value = EditorGUILayout.IntField((int)frame.value); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_Profile, "Changed int keyframe value"); frame.value = (int)Mathf.Clamp(value, group.minValue, group.maxValue); valueChanged = true; } } else { EditorGUI.BeginChangeCheck(); float value = EditorGUILayout.Slider(frame.value, group.minValue, group.maxValue); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_Profile, "Changed float keyframe value"); frame.value = value; valueChanged = true; } } } EditorGUILayout.EndHorizontal(); return(valueChanged); }
public static List <Vector3> GetLinePoints(NumberKeyframeGroup group) { List <Vector3> points = new List <Vector3>(); if (group.keyframes.Count == 0) { return(points); } List <float> majorTimePoints = new List <float>(); if (group.keyframes[0].time > .00001f) { majorTimePoints.Add(0); } foreach (NumberKeyframe keyframe in group.keyframes) { majorTimePoints.Add(keyframe.time); } if (group.keyframes[group.keyframes.Count - 1].time < .99999f) { majorTimePoints.Add(1.0f); } for (int i = 0; i < (majorTimePoints.Count - 1); i++) { float currentTime = majorTimePoints[i]; float nextTime = majorTimePoints[i + 1]; float timeStep = (nextTime - currentTime) / k_LineSmoothing; for (int j = 0; j <= k_LineSmoothing; j++) { float pointTime = currentTime + (j * timeStep); points.Add(new Vector3(pointTime, group.ValuePercentAtTime(pointTime))); } } return(points); }
public static void DrawNumericKeyMarker(Rect fullSliderRect, NumberKeyframe keyFrame, NumberKeyframeGroup group, UnityEngine.Object undoObject, out bool didSingleClick, out bool isDragging, out bool keyFrameTimeChanged) { Rect markerRect = new Rect( SkyEditorUtility.GetXPositionForPercent(fullSliderRect, keyFrame.time) - (KEY_GRIP_WIDTH / 2), GetYPositionForPercent(fullSliderRect, 1 - group.ValueToPercent(keyFrame.value)), KEY_GRIP_WIDTH, KEY_GRIP_HEIGHT); bool wasDragging = TimelineSelection.selectedControlUUID != null && TimelineSelection.selectedControlUUID == keyFrame.id; bool isMouseOverControl = markerRect.Contains(Event.current.mousePosition); didSingleClick = false; keyFrameTimeChanged = false; isDragging = wasDragging; // Single Click. if (Event.current.isMouse) { // Check for single click, with no drag. if (Event.current.type == EventType.MouseUp && TimelineSelection.selectedControlUUID == null && isMouseOverControl) { didSingleClick = true; Event.current.Use(); } // Start slide. if (TimelineSelection.selectedControlUUID == null && isMouseOverControl && Event.current.type == EventType.MouseDrag) { TimelineSelection.selectedControlUUID = keyFrame.id; // Find the position of the current value and record the offset so we can drag the keygrip relative from here. Vector2 valuePosition = new Vector2( GetXPositionForPercent(fullSliderRect, keyFrame.time), GetYPositionForPercent(fullSliderRect, 1 - group.ValueToPercent(keyFrame.value))); TimelineSelection.startingMouseOffset = valuePosition - Event.current.mousePosition; isDragging = true; Event.current.Use(); } // End Slide. if (wasDragging && Event.current.type == EventType.MouseUp) { TimelineSelection.selectedControlUUID = null; isDragging = false; Event.current.Use(); } // If we're dragging this keyframe grip, move it's position. if (wasDragging || isDragging) { // Update key frame time value and reposition rectangle. Undo.RecordObject(undoObject, "Keyframe time and value changed."); Vector2 adjustedMousePosition = Event.current.mousePosition + TimelineSelection.startingMouseOffset; keyFrame.time = GetPercentForXPosition(fullSliderRect, adjustedMousePosition.x); float adjustedValuePercent = 1 - GetPercentForYPosition(fullSliderRect, adjustedMousePosition.y); keyFrame.value = group.PercentToValue(adjustedValuePercent); keyFrameTimeChanged = true; isDragging = true; // Position the marker rect. markerRect.x = SkyEditorUtility.GetXPositionForPercent(fullSliderRect, keyFrame.time) - (KEY_GRIP_WIDTH / 2); markerRect.y = GetYPositionForPercent(fullSliderRect, 1 - group.ValueToPercent(keyFrame.value)); Event.current.Use(); } } bool showAsActive = IsKeyframeActiveInInspector(keyFrame) || isDragging; // Draw the marker at this location. SkyEditorUtility.DrawKeyMarker(markerRect, showAsActive); }
private static void RenderLinePath(Rect rect, NumberKeyframeGroup group) { if ((int)rect.width <= 0 || (int)rect.height <= 0 || Event.current.type != EventType.Repaint) { return; } int squareSize = 2048; if (m_LineRenderTexture == null) { m_LineRenderTexture = new RenderTexture( squareSize, squareSize, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); m_LineRenderTexture.antiAliasing = 2; m_LineRenderTexture.filterMode = FilterMode.Bilinear; } if (!m_LineRenderTexture.IsCreated()) { m_LineRenderTexture.Create(); } if (m_LineMesh == null) { m_LineMesh = new Mesh() { hideFlags = HideFlags.HideAndDontSave }; m_LineMesh.MarkDynamic(); } List <Vector3> points = GetLinePoints(group); // Background color. Color bgColor = new Color(k_BackgroundShade, k_BackgroundShade, k_BackgroundShade); // Line shader. if (m_LineMaterial == null) { m_LineMaterial = new Material(Shader.Find("Hidden/Funly/Sky/SoftLine")) { hideFlags = HideFlags.HideInHierarchy }; } m_LineMaterial.SetColor("_LineColor", ColorHelper.ColorWithHexAlpha(0x2AFBFFFF)); m_LineMaterial.SetFloat("_EdgeFeathering", k_LineEdgeFeathering); m_LineMaterial.SetColor("_BackgroundColor", bgColor); m_LineMaterial.SetTexture("_MainTex", SkyEditorUtility.LoadEditorResourceTexture("NumberShadowLine", false)); if (m_LineShadowMaterial == null) { m_LineShadowMaterial = new Material(Shader.Find("Hidden/Funly/Sky/LineShadow")) { hideFlags = HideFlags.HideInHierarchy }; } Color shadowColor = new Color(k_ShadowShade, k_ShadowShade, k_ShadowShade, 1.0f); m_LineShadowMaterial.SetColor("_BackgroundColor", bgColor); m_LineShadowMaterial.SetColor("_ShadowColor", shadowColor); // Setup tmp texture to render into. RenderTexture oldRenderTexture = RenderTexture.active; RenderTexture.active = m_LineRenderTexture; GL.PushMatrix(); GL.LoadPixelMatrix(0, m_LineRenderTexture.width, 0, m_LineRenderTexture.height); GL.Clear(true, true, bgColor); float lineInset = 5.0f; float heightScale = rect.height / rect.width; float lineThickness = k_LineThickness * heightScale; BuildLineMesh( m_LineMesh, points, m_LineRenderTexture.width, m_LineRenderTexture.width * heightScale - (lineInset * 2), lineThickness); // Line shadow. m_LineShadowMaterial.SetPass(0); Graphics.DrawMeshNow(m_LineMesh, new Vector3(0, lineInset - 8, 0), Quaternion.identity); // Actual line. m_LineMaterial.SetPass(0); Graphics.DrawMeshNow(m_LineMesh, new Vector3(0, lineInset, 0), Quaternion.identity); GL.PopMatrix(); RenderTexture.active = oldRenderTexture; // Pull out just the snippet section we want to use. Rect textureRect = new Rect( 0, 0, 1, heightScale); GUI.DrawTextureWithTexCoords(rect, m_LineRenderTexture, textureRect); }
public void MergeGroupsWithDefinitions() { HashSet <string> validProperties = ProfilePropertyKeys.GetPropertyKeysSet(); // Build our groups from the profile definition table. foreach (ProfileGroupSection section in groupDefinitions) { foreach (ProfileGroupDefinition groupInfo in section.groups) { // Filter out old groups that are no longer valid. if (!validProperties.Contains(groupInfo.propertyKey)) { continue; } if (groupInfo.type == ProfileGroupDefinition.GroupType.Color) { if (keyframeGroups.ContainsKey(groupInfo.propertyKey) == false) { AddColorGroup(groupInfo.propertyKey, groupInfo.groupName, groupInfo.color); } else { keyframeGroups[groupInfo.propertyKey].name = groupInfo.groupName; } } else if (groupInfo.type == ProfileGroupDefinition.GroupType.Number) { if (keyframeGroups.ContainsKey(groupInfo.propertyKey) == false) { AddNumericGroup(groupInfo.propertyKey, groupInfo.groupName, groupInfo.minimumValue, groupInfo.maximumValue, groupInfo.value); } else { NumberKeyframeGroup numberGroup = keyframeGroups.GetGroup <NumberKeyframeGroup>(groupInfo.propertyKey); numberGroup.name = groupInfo.groupName; numberGroup.minValue = groupInfo.minimumValue; numberGroup.maxValue = groupInfo.maximumValue; } } else if (groupInfo.type == ProfileGroupDefinition.GroupType.Texture) { if (keyframeGroups.ContainsKey(groupInfo.propertyKey) == false) { AddTextureGroup(groupInfo.propertyKey, groupInfo.groupName, groupInfo.texture); } else { keyframeGroups[groupInfo.propertyKey].name = groupInfo.groupName; } } else if (groupInfo.type == ProfileGroupDefinition.GroupType.SpherePoint) { if (keyframeGroups.ContainsKey(groupInfo.propertyKey) == false) { AddSpherePointGroup(groupInfo.propertyKey, groupInfo.groupName, groupInfo.spherePoint); } else { keyframeGroups[groupInfo.propertyKey].name = groupInfo.groupName; } } else if (groupInfo.type == ProfileGroupDefinition.GroupType.Boolean) { if (keyframeGroups.ContainsKey(groupInfo.propertyKey) == false) { AddBooleanGroup(groupInfo.propertyKey, groupInfo.groupName, groupInfo.boolValue); } else { keyframeGroups[groupInfo.propertyKey].name = groupInfo.groupName; } } } } }