private void OnAddKeySelected(object keyInfo) { KeyMenuInfo keyMenuInfo = keyInfo as KeyMenuInfo; Vector3 euler = m_sunRotationConfig.Evaluate(keyMenuInfo.Time); TODSunRotation.KeyFrame keyFrame = new TODSunRotation.KeyFrame(keyMenuInfo.Time, euler); m_sunRotationConfig.Add(keyFrame); }
private void OnEditKeySelected(object keyInfo) { KeyMenuInfo keyMenuInfo = keyInfo as KeyMenuInfo; KeyInfoWindow keyWindow = EditorWindow.GetWindow <KeyInfoWindow>(); keyWindow.SetPreInfo(keyMenuInfo.SelectKey, OnEditKeyFinish, m_sunTransform.transform); Vector2 fixedSize = new Vector2(300, 150); keyWindow.titleContent = new GUIContent("KeyInfo"); keyWindow.minSize = fixedSize; keyWindow.maxSize = fixedSize; keyWindow.Show(); }
private void GenerateMenu(bool hasSelect, KeyMenuInfo keyInfo) { m_keyFrameOperationMenu = new GenericMenu(); if (!hasSelect) { m_keyFrameOperationMenu.AddItem(new GUIContent("Add Key"), false, OnAddKeySelected, keyInfo); } else { m_keyFrameOperationMenu.AddDisabledItem(new GUIContent("Add Key")); } if (hasSelect) { m_keyFrameOperationMenu.AddItem(new GUIContent("Remove Key"), false, OnRemoveKeySelected, keyInfo); m_keyFrameOperationMenu.AddItem(new GUIContent("Edit Key"), false, OnEditKeySelected, keyInfo); } else { m_keyFrameOperationMenu.AddDisabledItem(new GUIContent("Remove Key")); m_keyFrameOperationMenu.AddDisabledItem(new GUIContent("Edit Key")); } }
private void OnRemoveKeySelected(object keyInfo) { KeyMenuInfo keyMenuInfo = keyInfo as KeyMenuInfo; m_sunRotationConfig.Remove(keyMenuInfo.SelectKey); }
private void DrawKeyframe(Rect area) { switch (Event.current.type) { case EventType.MouseDown: { if (!area.Contains(Event.current.mousePosition)) { break; } float time = PositionToTime(Event.current.mousePosition, area); m_curTime = time; float diff = 8 / area.width; TODSunRotation.KeyFrame selectKeyFrame = m_sunRotationConfig.SelectKeyframe(time, diff); if (Event.current.button == 0) { m_curSelectKeyframe = selectKeyFrame; } else if (Event.current.button == 1) { KeyMenuInfo keyInfo = new KeyMenuInfo(); keyInfo.Time = time; keyInfo.SelectKey = selectKeyFrame; GenerateMenu(selectKeyFrame != null, keyInfo); m_keyFrameOperationMenu.ShowAsContext(); } Event.current.Use(); } break; case EventType.MouseDrag: { if (m_curSelectKeyframe == null) { break; } float time = Mathf.Clamp01(PositionToTime(Event.current.mousePosition, area)); m_curSelectKeyframe.Time = time; Event.current.Use(); } break; case EventType.MouseUp: { if (m_curSelectKeyframe == null) { break; } m_sunRotationConfig.ResortKeyFrame(m_curSelectKeyframe); m_curSelectKeyframe = null; } break; } //Draw All Keyframe Rect rectPosition = new Rect(); rectPosition.width = m_keyframe.fixedWidth; rectPosition.height = m_keyframe.fixedHeight; for (int i = 0; i < m_sunRotationConfig.KeyFrames.Count; ++i) { rectPosition.x = area.x + m_sunRotationConfig.KeyFrames[i].Time * area.width - rectPosition.width / 2; rectPosition.y = area.y + area.height / 2 - rectPosition.height / 2; if (m_sunRotationConfig.KeyFrames[i] == m_curSelectKeyframe) { m_fakeColor = GUI.color; GUI.color = Color.green; } GUI.Button(rectPosition, "", m_keyframe); if (m_sunRotationConfig.KeyFrames[i] == m_curSelectKeyframe) { GUI.color = m_fakeColor; } } //Check if (m_curSelectKeyframe != null) { return; } for (int i = 0; i < m_sunRotationConfig.KeyFrames.Count - 1; ++i) { if (m_sunRotationConfig.KeyFrames[i].Time > m_sunRotationConfig.KeyFrames[i + 1].Time) { Debug.LogError("帧顺序出错!-联系引擎解决"); } } }