public override void previewFrame(AMITarget itarget, float frame, int frameRate, bool play, float playSpeed) { Transform t = GetTarget(itarget) as Transform; if (keys == null || keys.Count <= 0) { return; } // if before or equal to first frame, or is the only frame AMOrientationKey firstKey = keys[0] as AMOrientationKey; if (firstKey.endFrame == -1 || (frame <= (float)firstKey.frame && !firstKey.canTween)) { Transform keyt = firstKey.GetTarget(itarget); if (keyt) { t.LookAt(keyt); } return; } for (int i = 0; i < keys.Count; i++) { AMOrientationKey key = keys[i] as AMOrientationKey; AMOrientationKey keyNext = i + 1 < keys.Count ? keys[i + 1] as AMOrientationKey : null; if (frame >= (float)key.endFrame && keyNext != null && (!keyNext.canTween || keyNext.endFrame != -1)) { continue; } Transform keyt = key.GetTarget(itarget); // if no ease if (!key.canTween || keyNext == null) { if (keyt) { t.LookAt(keyt); } return; } // else easing function Transform keyet = keyNext.GetTarget(itarget); float numFrames = (float)key.getNumberOfFrames(frameRate); float framePositionInAction = Mathf.Clamp(frame - (float)key.frame, 0f, numFrames); t.rotation = key.getQuaternionAtPercent(t, keyt, keyet, framePositionInAction / numFrames); return; } }
// draw gizmos public override void drawGizmos(AMITarget itarget, float gizmo_size, bool inPlayMode, int frame) { if (!obj) { return; } // draw line to target bool isLineDrawn = false; if (!inPlayMode) { for (int i = 0; i < keys.Count; i++) { AMOrientationKey key = keys[i] as AMOrientationKey; if (key == null) { continue; } AMOrientationKey keyNext = i + 1 < keys.Count ? keys[i + 1] as AMOrientationKey : null; Transform t = key.GetTarget(itarget); if (t) { //draw target Gizmos.color = new Color(245f / 255f, 107f / 255f, 30f / 255f, 1f); Gizmos.DrawSphere(t.position, 0.2f * (AnimatorTimeline.e_gizmoSize / 0.1f)); //draw line if (!isLineDrawn) { if (key.frame > frame) { isLineDrawn = true; } if (frame >= key.frame && frame <= key.endFrame) { if (!keyNext || t == keyNext.GetTarget(itarget)) { Gizmos.color = new Color(245f / 255f, 107f / 255f, 30f / 255f, 0.2f); Gizmos.DrawLine(obj.transform.position, t.position); } isLineDrawn = true; } } } } } // draw arrow Gizmos.color = new Color(245f / 255f, 107f / 255f, 30f / 255f, 1f); Vector3 pos = obj.transform.position; float size = (1.2f * (gizmo_size / 0.1f)); if (size < 0.1f) { size = 0.1f; } Vector3 direction = obj.forward * size; float arrowHeadAngle = 20f; float arrowHeadLength = 0.3f * size; Gizmos.DrawRay(pos, direction); Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 + arrowHeadAngle, 0) * new Vector3(0, 0, 1); Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 - arrowHeadAngle, 0) * new Vector3(0, 0, 1); Gizmos.DrawRay(pos + direction, right * arrowHeadLength); Gizmos.DrawRay(pos + direction, left * arrowHeadLength); }