public static void OpenSceneTool(GameObject go) { enabled = false; activeGameObject = go; selectedPointIndex = -1; CloseSceneTool(); activeAnimationClip = AnimationWindowUtil.GetActiveAnimationClip(); if (activeAnimationClip == null) { Type type = foundation.ObjectFactory.Locate("UnityEditor.AnimationWindow"); EditorWindow.GetWindow(type); activeAnimationClip = AnimationWindowUtil.GetActiveAnimationClip(); if (activeAnimationClip == null) { return; } } InitPointsInfo(); AnimationWindowUtil.SetOnClipSelectionChanged(onClipSelectionChanged); AnimationUtility.onCurveWasModified += OnCurveWasModified; if (keepShow) { SceneView.duringSceneGui += OnSceneViewGUI; } enabled = true; SceneView.RepaintAll(); }
private static void CloseSceneTool() { selectedPointIndex = -1; enabled = false; AnimationWindowUtil.SetOnClipSelectionChanged(onClipSelectionChanged, true); AnimationUtility.onCurveWasModified -= OnCurveWasModified; SceneView.onSceneGUIDelegate = (SceneView.OnSceneFunc)Delegate.RemoveAll(SceneView.onSceneGUIDelegate, new SceneView.OnSceneFunc(OnSceneViewGUI)); SceneView.RepaintAll(); }
private static void CloseSceneTool() { selectedPointIndex = -1; enabled = false; AnimationWindowUtil.SetOnClipSelectionChanged(onClipSelectionChanged, true); AnimationUtility.onCurveWasModified -= OnCurveWasModified; SceneView.duringSceneGui -= OnSceneViewGUI; SceneView.RepaintAll(); }
private static bool SetPointTangent(int pointIndex, Vector3 worldTangent, bool isInTangent) { List <AnimationPathPoint> points = animationPoints; AnimationPathPoint pathPoint = null; AnimationPathPoint nextPathPoint = null; Vector3 offset = Vector3.zero; if (isInTangent) { pathPoint = points[pointIndex - 1]; nextPathPoint = points[pointIndex]; offset = GetLocalPosition(worldTangent) - GetLocalPosition(nextPathPoint.worldInTangent); } else { pathPoint = points[pointIndex]; nextPathPoint = points[pointIndex + 1]; offset = GetLocalPosition(worldTangent) - GetLocalPosition(pathPoint.worldOutTangent); } string inPath = AnimationUtility.CalculateTransformPath(activeGameObject.transform, activeRootGameObject.transform); Type inType = typeof(Transform); EditorCurveBinding bindingX = EditorCurveBinding.FloatCurve(inPath, inType, "m_LocalPosition.x"); EditorCurveBinding bindingY = EditorCurveBinding.FloatCurve(inPath, inType, "m_LocalPosition.y"); EditorCurveBinding bindingZ = EditorCurveBinding.FloatCurve(inPath, inType, "m_LocalPosition.z"); AnimationCurve curveX = AnimationUtility.GetEditorCurve(activeAnimationClip, bindingX); AnimationCurve curveY = AnimationUtility.GetEditorCurve(activeAnimationClip, bindingY); AnimationCurve curveZ = AnimationUtility.GetEditorCurve(activeAnimationClip, bindingZ); if (curveX == null || curveY == null || curveZ == null) { return(false); } AnimationPathPoint.ModifyPointTangent(pathPoint, nextPathPoint, offset, isInTangent, curveX, curveY, curveZ); Undo.RegisterCompleteObjectUndo(activeAnimationClip, "Edit Curve"); AnimationUtility.SetEditorCurve(activeAnimationClip, bindingX, curveX); AnimationUtility.SetEditorCurve(activeAnimationClip, bindingY, curveY); AnimationUtility.SetEditorCurve(activeAnimationClip, bindingZ, curveZ); AnimationWindowUtil.Repaint(); return(true); }
private static void onClipSelectionChanged() { if (enabled && !keepShow) { activeAnimationClip = AnimationWindowUtil.GetActiveAnimationClip(); AnimationClip[] clips = AnimationUtility.GetAnimationClips(activeRootGameObject); for (int i = 0; i < clips.Length; i++) { if (clips[i] == activeAnimationClip) { reloadPointsInfo = true; SceneView.RepaintAll(); return; } } CloseSceneTool(); } }
public static void OpenSceneTool(GameObject go) { enabled = false; activeGameObject = go; selectedPointIndex = -1; CloseSceneTool(); activeAnimationClip = AnimationWindowUtil.GetActiveAnimationClip(); if (activeAnimationClip == null) { return; } InitPointsInfo(); AnimationWindowUtil.SetOnClipSelectionChanged(onClipSelectionChanged); AnimationUtility.onCurveWasModified += OnCurveWasModified; if (keepShow) { SceneView.onSceneGUIDelegate = (SceneView.OnSceneFunc)Delegate.Combine(SceneView.onSceneGUIDelegate, new SceneView.OnSceneFunc(OnSceneViewGUI)); } enabled = true; SceneView.RepaintAll(); }
private void DoKeyframeTangentToConstant() { AnimationWindowReflect animationWindowReflect = AnimationWindowUtil.GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { SimpleDisplayDialog("Animation 窗口没有打开"); return; } AnimationClip activeAnimationClip = animationWindowReflect.activeAnimationClip; if (activeAnimationClip == null) { SimpleDisplayDialog("Animation 窗口没有任何动画片段"); return; } float currentTime = animationWindowReflect.currentTime; if ((activeAnimationClip.hideFlags & HideFlags.NotEditable) != HideFlags.None) { // FBX 动画则自动执行拷贝 AnimationClip oldClip = activeAnimationClip; activeAnimationClip = CopyAnimationClipAsset(activeAnimationClip); animationWindowReflect.activeAnimationClip = activeAnimationClip; animationWindowReflect.currentTime = currentTime; if (onClipCopyModify != null) { onClipCopyModify(oldClip, activeAnimationClip); } } KeyframeTangentToConstant(activeAnimationClip, currentTime); animationWindowReflect.firstAnimationWindow.Repaint(); }
private static void DrawSceneViewGUI() { if (reloadPointsInfo) { reloadPointsInfo = false; int num = animationPoints.Count; InitPointsInfo(); if (pointShow && animationPoints.Count > num) { // FIXME 这是为了修复新增点的时候,方向杆ID被改变了,所以操作无效 // 不完美,需要第二次点击的时候,才会获取新控件ID GUIUtility.hotControl = 0; Event.current.Use(); } } if (activeGameObject == null) { return; } List <AnimationPathPoint> points = animationPoints; int numPos = points.Count; for (int i = 0; i < numPos; i++) { AnimationPathPoint pathPoint = points[i]; pathPoint.worldPosition = GetWorldPosition(pathPoint.position); } for (int i = 0; i < numPos - 1; i++) { AnimationPathPoint pathPoint = points[i]; AnimationPathPoint nextPathPoint = points[i + 1]; Vector3 startTangent; Vector3 endTangent; AnimationPathPoint.CalcTangents(pathPoint, nextPathPoint, out startTangent, out endTangent); Vector3 p0 = pathPoint.worldPosition; Vector3 p1 = GetWorldPosition(startTangent); Vector3 p2 = GetWorldPosition(endTangent); Vector3 p3 = nextPathPoint.worldPosition; Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f); pathPoint.worldOutTangent = p1; nextPathPoint.worldInTangent = p2; } if (!pointShow) { return; } Quaternion handleRotation = activeParentTransform != null ? activeParentTransform.rotation : Quaternion.identity; for (int i = 0; i < numPos; i++) { int pointIndex = i * 3; Handles.color = Color.green; AnimationPathPoint pathPoint = points[i]; Vector3 position = pathPoint.worldPosition; float pointHandleSize = HandleUtility.GetHandleSize(position) * 0.04f; float pointPickSize = pointHandleSize * 0.7f; Handles.Label(position, " Point " + i); if (Handles.Button(position, handleRotation, pointHandleSize, pointPickSize, Handles.DotCap)) { selectedPointIndex = pointIndex; if (Selection.activeGameObject != activeGameObject) { Selection.activeGameObject = activeGameObject; } AnimationWindowUtil.SetCurrentTime(pathPoint.time); } Handles.color = Color.grey; int inIndex = pointIndex - 1; int outIndex = pointIndex + 1; if (selectedPointIndex < 0 || selectedPointIndex < inIndex || selectedPointIndex > outIndex) { continue; } if (i != 0) { Handles.DrawLine(position, pathPoint.worldInTangent); if (Handles.Button(pathPoint.worldInTangent, handleRotation, pointHandleSize, pointPickSize, Handles.DotCap)) { selectedPointIndex = inIndex; } if (selectedPointIndex == inIndex) { EditorGUI.BeginChangeCheck(); Vector3 pos = Handles.PositionHandle(pathPoint.worldInTangent, handleRotation); if (EditorGUI.EndChangeCheck() && SetPointTangent(i, pos, true)) { return; } } } if (i != numPos - 1) { Handles.DrawLine(position, pathPoint.worldOutTangent); if (Handles.Button(pathPoint.worldOutTangent, handleRotation, pointHandleSize, pointPickSize, Handles.DotCap)) { selectedPointIndex = outIndex; } if (selectedPointIndex == outIndex) { EditorGUI.BeginChangeCheck(); Vector3 pos = Handles.PositionHandle(pathPoint.worldOutTangent, handleRotation); if (EditorGUI.EndChangeCheck() && SetPointTangent(i, pos, false)) { return; } } } } }