void appendGroupCode(AMGroup _grp, ref string code) { foreach (int element_id in _grp.elements) { // track if (element_id > 0) { if (!dictTracks.ContainsKey(element_id)) { dictTracks.Add(element_id, true); } if (dictTracks[element_id] == true) { AMTrack track = aData.getCurrentTake().getTrack(element_id); appendTrackCode(track, ref code); } } // group else if (element_id < 0) { AMGroup grp = aData.getCurrentTake().getGroup(element_id); //code += "\n// "+grp.group_name+"\n"; appendGroupCode(grp, ref code); } } }
public void CopyTo(AMTrack track) { track.id = id; track.name = name; track._targetPath = _targetPath; DoCopy(track); }
public WrapMode wrapMode; // animation wrap mode #endregion Fields #region Methods public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object target) { int frameRate = seq.take.frameRate; float waitTime = getWaitTime(frameRate, 0.0f); Animation anim = (target as GameObject).GetComponent<Animation>(); float duration = wrapMode == WrapMode.Once ? amClip.length : ((seq.take.getLastFrame()-frame)+1)/(float)frameRate; Holoville.HOTween.Plugins.Core.ABSTweenPlugin plug; if(crossfade) { if(index > 0) { AMAnimationKey prevKey = track.keys[index - 1] as AMAnimationKey; plug = new AMPlugAnimationCrossFade(anim, crossfadeTime, prevKey.amClip.name, prevKey.wrapMode, prevKey.getWaitTime(frameRate, 0.0f), amClip.name, wrapMode, waitTime); } else plug = new AMPlugAnimation(anim, amClip.name, wrapMode, true, crossfadeTime); } else plug = new AMPlugAnimation(anim, amClip.name, wrapMode, false, 0.0f); seq.sequence.Insert(waitTime, HOTween.To(target, duration, new TweenParms().Prop("animation", plug))); //seq.Insert(new AMActionAnimation(this, seq.take.frameRate, (target as GameObject).animation)); //seq.sequence.InsertCallback(getWaitTime(seq.take.frameRate, 0.0f), OnMethodCallbackParams, (target as GameObject).animation, (float)seq.take.frameRate); }
public void reloadAnimatorData() { aData = null; loadAnimatorData(); AMTake take = aData.getCurrentTake(); // update references for track and key bool shouldClose = true; foreach (AMTrack _track in take.trackValues) { if (track == _track) { track = _track; foreach (AMKey _key in track.keys) { if (key == _key) { key = _key; shouldClose = false; } } } } if (shouldClose) { this.Close(); } }
public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object target) { if(methodName == null) return; //get component and fill the cached method info Component comp; if(seq.target.isMeta) { if(string.IsNullOrEmpty(componentName)) return; comp = (target as GameObject).GetComponent(componentName); } else { if(component == null) return; comp = component; } if(cachedMethodInfo == null) cachedMethodInfo = comp.GetType().GetMethod(methodName, GetParamTypes()); float waitTime = getWaitTime(seq.take.frameRate, 0.0f); if(useSendMessage) { if(parameters == null || parameters.Count <= 0) seq.sequence.InsertCallback(waitTime, comp.gameObject, methodName, null, SendMessageOptions.DontRequireReceiver); else seq.sequence.InsertCallback(waitTime, comp.gameObject, methodName, parameters[0].toObject(), SendMessageOptions.DontRequireReceiver); } else { seq.sequence.InsertCallback(waitTime, OnMethodCallbackParams, comp, (object)buildParams()); } }
// preview a frame in the scene view public override void previewFrame(float frame, AMTrack extraTrack = null) { if (!obj) { return; } if (cache.Count <= 0) { return; } // if before first frame if (frame <= (float)cache[0].startFrame) { obj.position = (cache[0] as AMTranslationAction).path[0]; return; } // if beyond last frame if (frame >= (float)(cache[cache.Count - 1] as AMTranslationAction).endFrame) { obj.position = (cache[cache.Count - 1] as AMTranslationAction).path[(cache[cache.Count - 1] as AMTranslationAction).path.Length - 1]; return; } // if lies on curve foreach (AMTranslationAction action in cache) { if (((int)frame < action.startFrame) || ((int)frame > action.endFrame)) { continue; } if (action.path.Length == 1) { obj.position = action.path[0]; return; } float _value; float framePositionInPath = frame - (float)action.startFrame; if (framePositionInPath < 0f) { framePositionInPath = 0f; } AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } _value = ease(0f, 1f, framePositionInPath / action.getNumberOfFrames(), curve); AMTween.PutOnPath(obj, action.path, Mathf.Clamp(_value, 0f, 1f)); return; } }
public override AnimatorTimeline.JSONInit getJSONInit() { if (!obj || keys.Count <= 0) { return(null); } AnimatorTimeline.JSONInit init = new AnimatorTimeline.JSONInit(); init.type = "orientation"; init.go = obj.gameObject.name; Transform _target = getInitialTarget(); int start_frame = keys[0].frame; AMTrack _translation_track = null; if (start_frame > 0) { _translation_track = parentTake.getTranslationTrackForTransform(_target); } Vector3 _lookv3 = _target.transform.position; if (_translation_track) { _lookv3 = (_translation_track as AMTranslationTrack).getPositionAtFrame(start_frame); } AnimatorTimeline.JSONVector3 v = new AnimatorTimeline.JSONVector3(); v.setValue(_lookv3); init.position = v; return(init); }
public static void setValues(AMKey _key, AMTrack _track) { justSet = true; key = _key; track = _track; //aData = _aData; selectedIndex = key.easeType; }
void OnDisable() { window = null; justSet = false; key = null; track = null; aData = null; }
// preview a frame in the scene view // 1. revert all layer's cur-state to normalizedTime = 0 // 2. re-evaluate all parameters setting from head to specified frame public void previewFrame(float frame, float frameRate, AMTrack extraTrack = null) { if (!obj) { return; } if (cache.Count == 0) { return; } // 1. revert var ator = this.animator; ator.Rebind(); //revert back to default states + default parameters ator.Update(0); // 2. re-evaluate float prevFrame = 0; for (int i = 0; i <= cache.Count - 1; ++i) { AMAnimatorAction action = cache[i] as AMAnimatorAction; if (action.startFrame > frame) { //update from prevFrame to frame, over float time = (frame - prevFrame) / frameRate; prevFrame = frame; ator.Update(time); break; } else if (action.startFrame <= frame) { //update from prevFrame to startFrame, keep on float time = (action.startFrame - prevFrame) / frameRate; prevFrame = action.startFrame; ator.Update(time); // apply the action's modification to ator for (int iidx = 0; iidx < action.m_infos.Count; ++iidx) { var oneInfo = action.m_infos[iidx]; oneInfo.Apply(ator, true); } // check same if (Mathf.Approximately(action.startFrame, frame)) { break; } } } if (frame > prevFrame) { float time = (frame - prevFrame) / frameRate; prevFrame = frame; ator.Update(time); } }
// preview a frame in the scene view public override void previewFrame(float frame, AMTrack extraTrack = null) { if (!obj) { return; } if (cache.Count <= 1) { return; } // if before first frame if (frame <= (float)cache[0].startFrame) { obj.localScale = (cache[0] as AMScaleAction).startScale; return; } // if beyond last frame if (frame >= (float)(cache[cache.Count - 2] as AMScaleAction).endFrame) { obj.localScale = (cache[cache.Count - 2] as AMScaleAction).endScale; return; } // if lies on curve for (int i = 0; i <= cache.Count - 2; ++i) { AMScaleAction action = cache[i] as AMScaleAction; if (((int)frame < action.startFrame) || ((int)frame > action.endFrame)) { continue; } float _value; float framePositionInPath = frame - (float)action.startFrame; if (framePositionInPath < 0f) { framePositionInPath = 0f; } AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } _value = ease(0f, 1f, framePositionInPath / action.getNumberOfFrames(), curve); obj.localScale = Vector3.Lerp(action.startScale, action.endScale, _value); return; } }
public static void RecordUndoTrackAndKeys(AMTrack track, bool complete, string label) { if(complete) { Undo.RegisterCompleteObjectUndo(track, label); Undo.RegisterCompleteObjectUndo(track.keys.ToArray(), label); } else { Undo.RecordObject(track, label); Undo.RecordObjects(track.keys.ToArray(), label); } }
public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object obj) { Transform target = obj as Transform; int frameRate = seq.take.frameRate; //allow tracks with just one key if(track.keys.Count == 1) interp = (int)Interpolation.None; if(!canTween) { switch((track as AMRotationEulerTrack).axis) { case AMRotationEulerTrack.Axis.X: seq.Insert(new AMActionTransLocalRotEulerX(this, frameRate, target, rotation.x)); break; case AMRotationEulerTrack.Axis.Y: seq.Insert(new AMActionTransLocalRotEulerY(this, frameRate, target, rotation.y)); break; case AMRotationEulerTrack.Axis.Z: seq.Insert(new AMActionTransLocalRotEulerZ(this, frameRate, target, rotation.z)); break; default: seq.Insert(new AMActionTransLocalRotEuler(this, frameRate, target, rotation)); break; } } else if(endFrame == -1) return; else { Vector3 endRotation = (track.keys[index + 1] as AMRotationEulerKey).rotation; TweenParms tParms = new TweenParms(); switch((track as AMRotationEulerTrack).axis) { case AMRotationEulerTrack.Axis.X: tParms = tParms.Prop("rotation", new AMPlugToTransformLocalEulerX(target, endRotation.x)); break; case AMRotationEulerTrack.Axis.Y: tParms = tParms.Prop("rotation", new AMPlugToTransformLocalEulerY(target, endRotation.y)); break; case AMRotationEulerTrack.Axis.Z: tParms = tParms.Prop("rotation", new AMPlugToTransformLocalEulerZ(target, endRotation.z)); break; default: tParms = tParms.Prop("rotation", new AMPlugToTransformLocalEuler(target, endRotation)); break; } if(hasCustomEase()) tParms = tParms.Ease(easeCurve); else tParms = tParms.Ease((EaseType)easeType, amplitude, period); seq.Insert(this, HOTween.To(this, getTime(frameRate), tParms)); } }
public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object target) { // if targets are equal do nothing if(endFrame == -1 || !hasTargets(seq.target) || targetsAreEqual(seq.target)) return; Camera[] allCameras = (track as AMCameraSwitcherTrack).GetCachedCameras(seq.target); //use 'this' with property 'type' as a placeholder since AMPlugCameraSwitcher does not require any property seq.Insert(this, HOTween.To(this, getTime(seq.take.frameRate), new TweenParms().Prop("type", new AMPlugCameraSwitcher(this, seq.take.frameRate, seq.target, allCameras)))); }
void OnDisable() { window = null; justSet = false; key = null; track = null; aData = null; if (AMTimeline.window != null) { AMTimeline.window.Repaint(); } }
void showGroupElement(int id, int group_lvl) { // returns true if mouse over track if (id >= 0) { AMTrack _track = aData.getCurrentTake().getTrack(id); showTrack(_track, id, group_lvl); } else { showGroup(id, group_lvl); } }
public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object obj) { int frameRate = seq.take.frameRate; //allow tracks with just one key if(track.keys.Count == 1) interp = (int)Interpolation.None; AMTranslationTrack tTrack = track as AMTranslationTrack; bool pixelSnap = tTrack.pixelSnap; float ppu = tTrack.pixelPerUnit; if(!canTween) { //TODO: world position seq.Insert(new AMActionTransLocalPos(this, frameRate, obj as Transform, pixelSnap ? new Vector3(Mathf.Round(position.x*ppu)/ppu, Mathf.Round(position.y*ppu)/ppu, Mathf.Round(position.z*ppu)/ppu) : position)); } else { if(path.Length <= 1) return; if(getNumberOfFrames(seq.take.frameRate) <= 0) return; object tweenTarget = obj; string tweenProp = "localPosition"; Tweener ret = null; bool isRelative = false; if(hasCustomEase()) { if(path.Length == 2) ret = HOTween.To(tweenTarget, getTime(frameRate), new TweenParms().Prop(tweenProp, pixelSnap ? new PlugVector3PathSnap(path, ppu, isRelative, PathType.Linear) : new PlugVector3Path(path, isRelative, PathType.Linear)).Ease(easeCurve)); else { PlugVector3Path p = pixelSnap ? new PlugVector3PathSnap(path, ppu, isRelative) : new PlugVector3Path(path, isRelative); p.ClosePath(isClosed); ret = HOTween.To(tweenTarget, getTime(frameRate), new TweenParms().Prop(tweenProp, p).Ease(easeCurve)); } } else { if(path.Length == 2) ret = HOTween.To(tweenTarget, getTime(frameRate), new TweenParms().Prop(tweenProp, pixelSnap ? new PlugVector3PathSnap(path, ppu, isRelative, PathType.Linear) : new PlugVector3Path(path, isRelative, PathType.Linear)).Ease((EaseType)easeType, amplitude, period)); else { PlugVector3Path p = pixelSnap ? new PlugVector3PathSnap(path, ppu, isRelative) : new PlugVector3Path(path, isRelative); p.ClosePath(isClosed); ret = HOTween.To(tweenTarget, getTime(frameRate), new TweenParms().Prop(tweenProp, p).Ease((EaseType)easeType, amplitude, period)); } } seq.Insert(this, ret); } }
void ConvertTrackCommonFields(AMTrack oldTrack, Track newTrack, bool applyTarget, bool isMeta) { newTrack.id = oldTrack.id; newTrack.name = oldTrack.name; newTrack.foldout = oldTrack.foldout; if (applyTarget) { if (isMeta) { newTrack.SetTargetDirect(null, oldTrack.targetPath); } else { newTrack.SetTargetDirect(oldTrack.GetTarget(null), ""); } } }
public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object obj) { int frameRate = seq.take.frameRate; //allow tracks with just one key if(track.keys.Count == 1) interp = (int)Interpolation.None; if(!canTween) { seq.Insert(new AMActionTransLocalRot(this, frameRate, obj as Transform, rotation)); } else if(endFrame == -1) return; else { Quaternion endRotation = (track.keys[index + 1] as AMRotationKey).rotation; if(hasCustomEase()) seq.Insert(this, HOTween.To(obj, getTime(frameRate), new TweenParms().Prop("localRotation", new AMPlugQuaternionSlerp(endRotation)).Ease(easeCurve))); else seq.Insert(this, HOTween.To(obj, getTime(frameRate), new TweenParms().Prop("localRotation", new AMPlugQuaternionSlerp(endRotation)).Ease((EaseType)easeType, amplitude, period))); } }
public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object obj) { if(!obj) return; int frameRate = seq.take.frameRate; if(!canTween) { seq.Insert(this, HOTween.To(obj, getTime(frameRate), new TweenParms().Prop("rotation", new AMPlugOrientation(GetTarget(seq.target), null)))); } if(endFrame == -1) return; Transform tgt = GetTarget(seq.target), tgte = (track.keys[index+1] as AMOrientationKey).GetTarget(seq.target); if(tgt == tgte) { seq.Insert(this, HOTween.To(obj, getTime(frameRate), new TweenParms().Prop("rotation", new AMPlugOrientation(tgt, null)))); } else { if(hasCustomEase()) { seq.Insert(this, HOTween.To(obj, getTime(frameRate), new TweenParms().Prop("rotation", new AMPlugOrientation(tgt, tgte)).Ease(easeCurve))); } else { seq.Insert(this, HOTween.To(obj, getTime(frameRate), new TweenParms().Prop("rotation", new AMPlugOrientation(tgt, tgte)).Ease((EaseType)easeType, amplitude, period))); } } }
void showTrack(AMTrack _track, int id, int group_level) { if (!dictTracks.ContainsKey(id)) { dictTracks.Add(id, true); } GUILayout.BeginHorizontal(); GUILayout.Space(width_indent * group_level); bool prev = dictTracks[id]; dictTracks[id] = GUILayout.Toggle(dictTracks[id], ""); if (dictTracks[id] != prev) { // changed refreshCode(); } GUILayout.BeginVertical(); GUILayout.Space(height_label_offset); GUILayout.Label(_track.name); GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
void showFrames(AMTrack _track, ref float track_y, Event e, bool birdseye, Vector2 scrollViewBounds) { //string tooltip = ""; int t = _track.id; int selectedTrack = aData.getCurrentTake().selectedTrack; // frames start if(!_track.foldout && !oData.showFramesForCollapsedTracks) { track_y += height_track_foldin; return; } float numFrames = (aData.getCurrentTake().numFrames < numFramesToRender ? aData.getCurrentTake().numFrames : numFramesToRender); Rect rectFrames = new Rect(width_track, track_y, current_width_frame * numFrames, height_track); if(!_track.foldout) track_y += height_track_foldin; else track_y += height_track; if(track_y < scrollViewBounds.x) return; // if end y is before min y float _current_height_frame = (_track.foldout ? current_height_frame : height_track_foldin); #region frames GUI.BeginGroup(rectFrames); // draw frames bool selected; bool ghost = isDragging && aData.getCurrentTake().hasGhostSelection(); bool isTrackSelected = t == selectedTrack || aData.getCurrentTake().contextSelectionTracks.Contains(t); Rect rectFramesBirdsEye = new Rect(0f, 0f, rectFrames.width, _current_height_frame); float width_birdseye = current_height_frame * 0.5f; if(birdseye) { GUI.color = colBirdsEyeFrames; GUI.DrawTexture(rectFramesBirdsEye, EditorGUIUtility.whiteTexture); } else { texFrSet.wrapMode = TextureWrapMode.Repeat; float startPos = aData.getCurrentTake().startFrame % 5f; GUI.DrawTextureWithTexCoords(rectFramesBirdsEye, texFrSet, new Rect(startPos / 5f, 0f, numFrames / 5f, 1f)); float birdsEyeFadeAlpha = (1f - (current_width_frame - width_frame_birdseye_min)) / 1.2f; if(birdsEyeFadeAlpha > 0f) { GUI.color = new Color(colBirdsEyeFrames.r, colBirdsEyeFrames.g, colBirdsEyeFrames.b, birdsEyeFadeAlpha); GUI.DrawTexture(rectFramesBirdsEye, EditorGUIUtility.whiteTexture); } } GUI.color = new Color(72f / 255f, 72f / 255f, 72f / 255f, 1f); GUI.DrawTexture(new Rect(rectFramesBirdsEye.x, rectFramesBirdsEye.y, rectFramesBirdsEye.width, 1f), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(rectFramesBirdsEye.x, rectFramesBirdsEye.y + rectFramesBirdsEye.height - 1f, rectFramesBirdsEye.width, 1f), EditorGUIUtility.whiteTexture); GUI.color = Color.white; // draw birds eye selection if(isTrackSelected) { if(ghost) { // dragging only one frame that has a key. do not show ghost selection if(birdseye && aData.getCurrentTake().contextSelection.Count == 2 && aData.getCurrentTake().contextSelection[0] == aData.getCurrentTake().contextSelection[1] && _track.hasKeyOnFrame(aData.getCurrentTake().contextSelection[0])) { GUI.color = new Color(0f, 0f, 1f, .5f); GUI.DrawTexture(new Rect(current_width_frame * (aData.getCurrentTake().ghostSelection[0] - aData.getCurrentTake().startFrame) - width_birdseye / 2f + current_width_frame / 2f, 0f, width_birdseye, _current_height_frame), texKeyBirdsEye); GUI.color = Color.white; } else if(aData.getCurrentTake().ghostSelection != null) { // birds eye ghost selection GUI.color = new Color(156f / 255f, 162f / 255f, 216f / 255f, .9f); for(int i = 0; i < aData.getCurrentTake().ghostSelection.Count; i += 2) { int contextFrameStart = aData.getCurrentTake().ghostSelection[i]; int contextFrameEnd = aData.getCurrentTake().ghostSelection[i + 1]; if(contextFrameStart < (int)aData.getCurrentTake().startFrame) contextFrameStart = (int)aData.getCurrentTake().startFrame; if(contextFrameEnd > (int)aData.getCurrentTake().endFrame) contextFrameEnd = (int)aData.getCurrentTake().endFrame; float contextWidth = (contextFrameEnd - contextFrameStart + 1) * current_width_frame; GUI.DrawTexture(new Rect(rectFramesBirdsEye.x + (contextFrameStart - aData.getCurrentTake().startFrame) * current_width_frame, rectFramesBirdsEye.y + 1f, contextWidth, rectFramesBirdsEye.height - 2f), EditorGUIUtility.whiteTexture); } // draw birds eye ghost key frames GUI.color = new Color(0f, 0f, 1f, .5f); foreach(int _key_frame in aData.getCurrentTake().getKeyFramesInGhostSelection((int)aData.getCurrentTake().startFrame, (int)aData.getCurrentTake().endFrame, t)) { if(birdseye) GUI.DrawTexture(new Rect(current_width_frame * (_key_frame - aData.getCurrentTake().startFrame) - width_birdseye / 2f + current_width_frame / 2f, 0f, width_birdseye, _current_height_frame), texKeyBirdsEye); else { Rect rectFrame = new Rect(current_width_frame * (_key_frame - aData.getCurrentTake().startFrame), 0f, current_width_frame, _current_height_frame); GUI.DrawTexture(new Rect(rectFrame.x + 2f, rectFrame.y + rectFrame.height - (rectFrame.width - 4f) - 2f, rectFrame.width - 4f, rectFrame.width - 4f), texFrKey); } } GUI.color = Color.white; } } else if(aData.getCurrentTake().contextSelection.Count > 0 && /*do not show single frame selection in birdseye*/!(birdseye && aData.getCurrentTake().contextSelection.Count == 2 && aData.getCurrentTake().contextSelection[0] == aData.getCurrentTake().contextSelection[1])) { // birds eye context selection for(int i = 0; i < aData.getCurrentTake().contextSelection.Count; i += 2) { //GUI.color = new Color(121f/255f,127f/255f,184f/255f,(birdseye ? 1f : .9f)); GUI.color = new Color(86f / 255f, 95f / 255f, 178f / 255f, .8f); int contextFrameStart = aData.getCurrentTake().contextSelection[i]; int contextFrameEnd = aData.getCurrentTake().contextSelection[i + 1]; if(contextFrameStart < (int)aData.getCurrentTake().startFrame) contextFrameStart = (int)aData.getCurrentTake().startFrame; if(contextFrameEnd > (int)aData.getCurrentTake().endFrame) contextFrameEnd = (int)aData.getCurrentTake().endFrame; float contextWidth = (contextFrameEnd - contextFrameStart + 1) * current_width_frame; Rect rectContextSelection = new Rect(rectFramesBirdsEye.x + (contextFrameStart - aData.getCurrentTake().startFrame) * current_width_frame, rectFramesBirdsEye.y + 1f, contextWidth, rectFramesBirdsEye.height - 2f); GUI.DrawTexture(rectContextSelection, EditorGUIUtility.whiteTexture); if(dragType != (int)DragType.ContextSelection) EditorGUIUtility.AddCursorRect(rectContextSelection, MouseCursor.SlideArrow); } GUI.color = Color.white; } } // birds eye keyframe information, used to draw buttons in proper order List<int> birdseyeKeyFrames = new List<int>(); List<Rect> birdseyeKeyRects = new List<Rect>(); if(birdseye) { // draw birds eye keyframe textures, prepare button rects foreach(AMKey key in _track.keys) { if(!key) continue; selected = ((isTrackSelected) && aData.getCurrentTake().isFrameSelected(key.frame)); //_track.sortKeys(); if(key.frame < aData.getCurrentTake().startFrame) continue; if(key.frame > aData.getCurrentTake().endFrame) break; Rect rectKeyBirdsEye = new Rect(current_width_frame * (key.frame - aData.getCurrentTake().startFrame) - width_birdseye / 2f + current_width_frame / 2f, 0f, width_birdseye, _current_height_frame); if(selected) GUI.color = Color.blue; GUI.DrawTexture(rectKeyBirdsEye, texKeyBirdsEye); GUI.color = Color.white; birdseyeKeyFrames.Add(key.frame); birdseyeKeyRects.Add(rectKeyBirdsEye); } // birds eye buttons if(birdseyeKeyFrames.Count > 0) { for(int i = birdseyeKeyFrames.Count - 1; i >= 0; i--) { selected = ((isTrackSelected) && aData.getCurrentTake().isFrameSelected(birdseyeKeyFrames[i])); if(dragType != (int)DragType.MoveSelection && dragType != (int)DragType.ContextSelection && !isRenamingTake && isRenamingTrack == -1 && mouseOverFrame == 0 && birdseyeKeyRects[i].Contains(e.mousePosition) && mouseOverElement == (int)ElementType.None) { mouseOverFrame = birdseyeKeyFrames[i]; mouseOverTrack = t; mouseOverSelectedFrame = (selected); } if(selected && dragType != (int)DragType.ContextSelection) EditorGUIUtility.AddCursorRect(birdseyeKeyRects[i], MouseCursor.SlideArrow); } } } else { selected = (isTrackSelected); foreach(AMKey key in _track.keys) { if(!key) continue; //_track.sortKeys(); if(key.frame < aData.getCurrentTake().startFrame) continue; if(key.frame > aData.getCurrentTake().endFrame) break; Rect rectFrame = new Rect(current_width_frame * (key.frame - aData.getCurrentTake().startFrame), 0f, current_width_frame, _current_height_frame); GUI.DrawTexture(new Rect(rectFrame.x + 2f, rectFrame.y + rectFrame.height - (rectFrame.width - 4f) - 2f, rectFrame.width - 4f, rectFrame.width - 4f), texFrKey); } } // click on empty frames if(GUI.Button(rectFramesBirdsEye, "", "label") && dragType == (int)DragType.None) { int prevFrame = aData.getCurrentTake().selectedFrame; bool clickedOnBirdsEyeKey = false; for(int i = birdseyeKeyFrames.Count - 1; i >= 0; i--) { if(birdseyeKeyFrames[i] > (int)aData.getCurrentTake().endFrame) continue; if(birdseyeKeyFrames[i] < (int)aData.getCurrentTake().startFrame) break; if(birdseyeKeyRects[i].Contains(e.mousePosition)) { clickedOnBirdsEyeKey = true; // left click if(e.button == 0) { // select the frame timelineSelectFrame(t, birdseyeKeyFrames[i]); // add frame to context selection contextSelectFrame(birdseyeKeyFrames[i], prevFrame); // right click } else if(e.button == 1) { // select track timelineSelectTrack(t); // if context selection is empty, select frame buildContextMenu(birdseyeKeyFrames[i]); // show context menu contextMenu.ShowAsContext(); } break; } } if(!clickedOnBirdsEyeKey) { int _frame_num_birdseye = (int)aData.getCurrentTake().startFrame + Mathf.CeilToInt(e.mousePosition.x / current_width_frame) - 1; // left click if(e.button == 0) { // select the frame timelineSelectFrame(t, _frame_num_birdseye); // add frame to context selection contextSelectFrame(_frame_num_birdseye, prevFrame); // right click } else if(e.button == 1) { timelineSelectTrack(t); // if context selection is empty, select frame buildContextMenu(_frame_num_birdseye); // show context menu contextMenu.ShowAsContext(); } } } if(!isRenamingTake && isRenamingTrack == -1 && mouseOverFrame == 0 && e.mousePosition.x >= rectFramesBirdsEye.x && e.mousePosition.x <= (rectFramesBirdsEye.x + rectFramesBirdsEye.width)) { if(rectFramesBirdsEye.Contains(e.mousePosition) && mouseOverElement == (int)ElementType.None) { mouseOverFrame = mouseXOverFrame; mouseOverTrack = t; } mouseOverSelectedFrame = ((isTrackSelected) && aData.getCurrentTake().isFrameSelected(mouseXOverFrame)); } #endregion if(!oData.disableTimelineActions && _track.foldout) { #region timeline actions //AudioClip audioClip = null; bool drawEachAction = false; if(_track is AMAnimationTrack || _track is AMAudioTrack) drawEachAction = true; // draw each action with seperate textures and buttons for these tracks int _startFrame = (int)aData.getCurrentTake().startFrame; int _endFrame = (int)(_startFrame + numFrames - 1); int action_startFrame, action_endFrame, renderFrameStart, renderFrameEnd; int cached_action_startFrame = -1, cached_action_endFrame = -1; Texture texBox = texBoxBorder; #region group textures / buttons (performance increase) Rect rectTimelineActions = new Rect(0f, _current_height_frame, 0f, height_track - current_height_frame); // used to group textures into one draw call if(!drawEachAction) { if(_track.keys.Count > 0) { if(_track is AMTranslationTrack && _track.keys.Count > 1 && _track.keys[0] && _track.keys[_track.keys.Count - 1]) { // translation track, from first action frame to end action frame cached_action_startFrame = _track.keys[0].getStartFrame(); cached_action_endFrame = (_track.keys[_track.keys.Count - 1] as AMTranslationKey).endFrame; texBox = texBoxGreen; } else if(_track is AMRotationTrack && _track.keys.Count > 1 && _track.keys[0] && _track.keys[_track.keys.Count - 1]) { // rotation track, from first action start frame to last action start frame cached_action_startFrame = _track.keys[0].getStartFrame(); cached_action_endFrame = _track.keys[_track.keys.Count - 1].getStartFrame(); texBox = texBoxYellow; } else if(_track is AMOrientationTrack && _track.keys.Count > 1 && _track.keys[0] && _track.keys[_track.keys.Count - 1]) { // orientation track, from first action start frame to last action start frame cached_action_startFrame = _track.keys[0].getStartFrame(); cached_action_endFrame = _track.keys[_track.keys.Count - 1].getStartFrame(); texBox = texBoxOrange; } else if(_track is AMPropertyTrack) { // property track, full track width cached_action_startFrame = _startFrame; cached_action_endFrame = _endFrame; texBox = texBoxLightBlue; } else if(_track is AMEventTrack && _track.keys[0]) { // event track, from first action start frame to end frame cached_action_startFrame = _track.keys[0].getStartFrame(); cached_action_endFrame = _endFrame; texBox = texBoxDarkBlue; } else if(_track is AMGOSetActiveTrack && _track.keys[0]) { // go set active track, from first action start frame to end frame cached_action_startFrame = _track.keys[0].getStartFrame(); cached_action_endFrame = _endFrame; texBox = texBoxDarkBlue; } } if(cached_action_startFrame > 0 && cached_action_endFrame > 0) { if(cached_action_startFrame <= _startFrame) { rectTimelineActions.x = 0f; } else { rectTimelineActions.x = (cached_action_startFrame - _startFrame) * current_width_frame; } if(cached_action_endFrame >= _endFrame) { rectTimelineActions.width = rectFramesBirdsEye.width; } else { rectTimelineActions.width = (cached_action_endFrame - (_startFrame >= cached_action_startFrame ? _startFrame : cached_action_startFrame) + 1) * current_width_frame; } // draw timeline action texture if(rectTimelineActions.width > 0f) GUI.DrawTexture(rectTimelineActions, texBox); } } #endregion string txtInfo; Rect rectBox; // draw box for each action in track bool didClampBackwards = false; // whether or not clamped backwards, used to break infinite loop int last_action_startFrame = -1; for(int i = 0; i < _track.keys.Count; i++) { if(_track.keys[i] == null) continue; #region calculate dimensions int clamped = 0; // 0 = no clamp, -1 = backwards clamp, 1 = forwards clamp if(_track.keys[i].version != _track.version) { // if cache is null, recheck for component and update caches //aData = (AnimatorData)GameObject.Find("AnimatorData").GetComponent("AnimatorData"); aData.getCurrentTake().maintainCaches(); } if((_track is AMAudioTrack) && ((_track.keys[i] as AMAudioKey).getNumberOfFrames(aData.getCurrentTake().frameRate)) > -1 && (_track.keys[i].getStartFrame() + (_track.keys[i] as AMAudioKey).getNumberOfFrames(aData.getCurrentTake().frameRate) <= aData.getCurrentTake().numFrames)) { // based on audio clip length action_startFrame = _track.keys[i].getStartFrame(); action_endFrame = _track.keys[i].getStartFrame() + (_track.keys[i] as AMAudioKey).getNumberOfFrames(aData.getCurrentTake().frameRate); //audioClip = (_track.cache[i] as AMAudioAction).audioClip; // if intersects new audio clip, then cut if(i < _track.keys.Count - 1) { if(action_endFrame > _track.keys[i + 1].getStartFrame()) action_endFrame = _track.keys[i + 1].getStartFrame(); } } else if((_track is AMAnimationTrack) && ((_track.keys[i] as AMAnimationKey).getNumberOfFrames(aData.getCurrentTake().frameRate)) > -1 && (_track.keys[i].getStartFrame() + (_track.keys[i] as AMAnimationKey).getNumberOfFrames(aData.getCurrentTake().frameRate) <= aData.getCurrentTake().numFrames)) { // based on animation clip length action_startFrame = _track.keys[i].getStartFrame(); action_endFrame = _track.keys[i].getStartFrame() + (_track.keys[i] as AMAnimationKey).getNumberOfFrames(aData.getCurrentTake().frameRate); // if intersects new animation clip, then cut if(i < _track.keys.Count - 1) { if(action_endFrame > _track.keys[i + 1].getStartFrame()) action_endFrame = _track.keys[i + 1].getStartFrame(); } } else if((i == 0) && (!didClampBackwards) && (_track is AMPropertyTrack || _track is AMGOSetActiveTrack)) { // clamp behind if first action action_startFrame = 1; action_endFrame = _track.keys[0].getStartFrame(); i--; didClampBackwards = true; clamped = -1; } else if((_track is AMAnimationTrack) || (_track is AMAudioTrack) || (_track is AMPropertyTrack) || (_track is AMEventTrack) || (_track is AMGOSetActiveTrack)) { // single frame tracks (clamp box to last frame) (if audio track not set, clamp) action_startFrame = _track.keys[i].getStartFrame(); if(i < _track.keys.Count - 1) { action_endFrame = _track.keys[i + 1].getStartFrame(); } else { clamped = 1; action_endFrame = _endFrame; if(action_endFrame > aData.getCurrentTake().numFrames) action_endFrame = aData.getCurrentTake().numFrames + 1; } } else { // tracks with start frame and end frame (do not clamp box, stop before last key) if(_track.keys[i].getNumberOfFrames() <= 0) continue; action_startFrame = _track.keys[i].getStartFrame(); action_endFrame = _track.keys[i].getStartFrame() + _track.keys[i].getNumberOfFrames(); } if(action_startFrame > _endFrame) { last_action_startFrame = action_startFrame; continue; } if(action_endFrame < _startFrame) { last_action_startFrame = action_startFrame; continue; } if(i >= 0) txtInfo = getInfoTextForAction(_track, _track.keys[i], false, clamped); else txtInfo = getInfoTextForAction(_track, _track.keys[0], true, clamped); float rectLeft, rectWidth; ; float rectTop = current_height_frame; float rectHeight = height_track - current_height_frame; // set info box position and dimensions bool showLeftAnchor = true; bool showRightAnchor = true; if(action_startFrame < _startFrame) { rectLeft = 0f; renderFrameStart = _startFrame; showLeftAnchor = false; } else { rectLeft = (action_startFrame - _startFrame) * current_width_frame; renderFrameStart = action_startFrame; } if(action_endFrame > _endFrame) { renderFrameEnd = _endFrame; showRightAnchor = false; } else { renderFrameEnd = action_endFrame; } rectWidth = (renderFrameEnd - renderFrameStart + 1) * current_width_frame; rectBox = new Rect(rectLeft, rectTop, rectWidth, rectHeight); #endregion #region draw action if(_track is AMAnimationTrack) texBox = texBoxRed; else if(_track is AMPropertyTrack) texBox = texBoxLightBlue; else if(_track is AMTranslationTrack) texBox = texBoxGreen; else if(_track is AMAudioTrack) texBox = texBoxPink; else if(_track is AMRotationTrack) texBox = texBoxYellow; else if(_track is AMOrientationTrack) texBox = texBoxOrange; else if(_track is AMEventTrack) texBox = texBoxDarkBlue; else if(_track is AMGOSetActiveTrack) texBox = texBoxDarkBlue; else texBox = texBoxBorder; if(drawEachAction) { GUI.DrawTexture(rectBox, texBox); //if(audioClip) GUI.DrawTexture(rectBox,AssetPreview.GetAssetPreview(audioClip)); } // info tex label bool hideTxtInfo = (GUI.skin.label.CalcSize(new GUIContent(txtInfo)).x > rectBox.width); GUIStyle styleTxtInfo = new GUIStyle(GUI.skin.label); styleTxtInfo.normal.textColor = Color.white; styleTxtInfo.alignment = (hideTxtInfo ? TextAnchor.MiddleLeft : TextAnchor.MiddleCenter); bool isLastAction; if(_track is AMPropertyTrack || _track is AMEventTrack || _track is AMGOSetActiveTrack) isLastAction = (i == _track.keys.Count - 1); else if(_track is AMAudioTrack || _track is AMAnimationTrack) isLastAction = false; else isLastAction = (i == _track.keys.Count - 2); if(rectBox.width > 5f) EditorGUI.DropShadowLabel(new Rect(rectBox.x, rectBox.y, rectBox.width - (!isLastAction ? current_width_frame : 0f), rectBox.height), txtInfo, styleTxtInfo); // if clicked on info box, select the starting frame for action. show tooltip if text does not fit if(drawEachAction && GUI.Button(rectBox, /*(hideTxtInfo ? new GUIContent("",txtInfo) : new GUIContent(""))*/"", "label") && dragType != (int)DragType.ResizeAction) { int prevFrame = aData.getCurrentTake().selectedFrame; // timeline select timelineSelectFrame(t, (clamped == -1 ? action_endFrame : action_startFrame)); // clear and add frame to context selection contextSelectFrame((clamped == -1 ? action_endFrame : action_startFrame), prevFrame); } if(rectBox.Contains(e.mousePosition) && mouseOverElement == (int)ElementType.None) { mouseOverElement = (int)ElementType.TimelineAction; mouseOverTrack = t; if(hideTxtInfo) tooltip = txtInfo; } #endregion #region draw anchors if(showLeftAnchor) { Rect rectBoxAnchorLeft = new Rect(rectBox.x - 1f, rectBox.y, 2f, rectBox.height); GUI.DrawTexture(rectBoxAnchorLeft, texBoxBorder); Rect rectBoxAnchorLeftOffset = new Rect(rectBoxAnchorLeft); rectBoxAnchorLeftOffset.width += 6f; rectBoxAnchorLeftOffset.x -= 3f; // info box anchor cursor if(i >= 0) { EditorGUIUtility.AddCursorRect(new Rect(rectBoxAnchorLeftOffset.x + 1f, rectBoxAnchorLeftOffset.y, rectBoxAnchorLeftOffset.width - 2f, rectBoxAnchorLeftOffset.height), MouseCursor.ResizeHorizontal); if(rectBoxAnchorLeftOffset.Contains(e.mousePosition) && (mouseOverElement == (int)ElementType.None || mouseOverElement == (int)ElementType.TimelineAction)) { mouseOverElement = (int)ElementType.ResizeAction; if(dragType == (int)DragType.None) { if(_track.hasKeyOnFrame(last_action_startFrame)) startResizeActionFrame = last_action_startFrame; else startResizeActionFrame = -1; resizeActionFrame = action_startFrame; if(_track is AMAnimationTrack || _track is AMAudioTrack) { endResizeActionFrame = _track.getKeyFrameAfterFrame(action_startFrame, false); } else endResizeActionFrame = action_endFrame; mouseOverTrack = t; arrKeyRatiosLeft = _track.getKeyFrameRatiosInBetween(startResizeActionFrame, resizeActionFrame); arrKeyRatiosRight = _track.getKeyFrameRatiosInBetween(resizeActionFrame, endResizeActionFrame); arrKeysLeft = _track.getKeyFramesInBetween(startResizeActionFrame, resizeActionFrame); arrKeysRight = _track.getKeyFramesInBetween(resizeActionFrame, endResizeActionFrame); } } } } // draw right anchor if last timeline action if(showRightAnchor && isLastAction) { Rect rectBoxAnchorRight = new Rect(rectBox.x + rectBox.width - 1f, rectBox.y, 2f, rectBox.height); GUI.DrawTexture(rectBoxAnchorRight, texBoxBorder); Rect rectBoxAnchorRightOffset = new Rect(rectBoxAnchorRight); rectBoxAnchorRightOffset.width += 6f; rectBoxAnchorRightOffset.x -= 3f; EditorGUIUtility.AddCursorRect(new Rect(rectBoxAnchorRightOffset.x + 1f, rectBoxAnchorRightOffset.y, rectBoxAnchorRightOffset.width - 2f, rectBoxAnchorRightOffset.height), MouseCursor.ResizeHorizontal); if(rectBoxAnchorRightOffset.Contains(e.mousePosition) && (mouseOverElement == (int)ElementType.None || mouseOverElement == (int)ElementType.TimelineAction)) { mouseOverElement = (int)ElementType.ResizeAction; if(dragType == (int)DragType.None) { startResizeActionFrame = action_startFrame; resizeActionFrame = action_endFrame; endResizeActionFrame = -1; mouseOverTrack = t; arrKeyRatiosLeft = _track.getKeyFrameRatiosInBetween(startResizeActionFrame, resizeActionFrame); arrKeyRatiosRight = _track.getKeyFrameRatiosInBetween(resizeActionFrame, endResizeActionFrame); arrKeysLeft = _track.getKeyFramesInBetween(startResizeActionFrame, resizeActionFrame); arrKeysRight = _track.getKeyFramesInBetween(resizeActionFrame, endResizeActionFrame); } } } #endregion last_action_startFrame = action_startFrame; } if(!drawEachAction) { // timeline action button if(GUI.Button(rectTimelineActions,/*new GUIContent("",tooltip)*/"", "label") && dragType == (int)DragType.None) { int _frame_num_action = (int)aData.getCurrentTake().startFrame + Mathf.CeilToInt(e.mousePosition.x / current_width_frame) - 1; AMKey _action = _track.getKeyContainingFrame(_frame_num_action); int prevFrame = aData.getCurrentTake().selectedFrame; // timeline select timelineSelectFrame(t, _action.getStartFrame()); // clear and add frame to context selection contextSelectFrame(_action.getStartFrame(), prevFrame); } } #endregion } GUI.EndGroup(); }
// preview a frame in the scene view public override void previewFrame(float frame, AMTrack extraTrack = null) { if(keys == null || keys.Count <= 0) { return; } if(!obj) return; // if before the first frame if(frame < (float)keys[0].frame) { //obj.rotation = (cache[0] as AMPropertyAction).getStartQuaternion(); obj.SetActive(startActive); return; } // if beyond or equal to last frame if(frame >= (float)(keys[keys.Count - 1] as AMGOSetActiveKey).frame) { obj.SetActive((keys[keys.Count - 1] as AMGOSetActiveKey).setActive); return; } // if lies on property action foreach(AMGOSetActiveKey key in keys) { if((frame < (float)key.frame) || (frame > (float)key.endFrame)) continue; obj.SetActive(key.setActive); return; } }
public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object obj) { seq.sequence.InsertCallback(getWaitTime(seq.take.frameRate, 0.0f), seq.triggerCallback, this, new AMTriggerData() { valueString=this.valueString, valueInt=this.valueInt, valueFloat=this.valueFloat }); }
public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object target) { float sTime = getWaitTime(seq.take.frameRate, 0.0f); seq.sequence.InsertCallback(sTime, OnMethodCallbackParams, target as AudioSource); }
public override void previewFrame(float frame, AMTrack extraTrack = null) { // do nothing }
public override void previewFrame(float frame, AMTrack extraTrack = null) { if (cache == null || cache.Count <= 0) { return; } for (int i = 0; i < cache.Count; i++) { // before first frame if (frame <= (cache[i] as AMOrientationAction).startFrame) { if (!(cache[i] as AMOrientationAction).startTarget) { return; } Vector3 startPos; if (cachedTranslationTrackStartTarget == null) { startPos = (cache[i] as AMOrientationAction).startTarget.position; } else { startPos = (cachedTranslationTrackStartTarget as AMTranslationTrack).getPositionAtFrame((cache[i] as AMOrientationAction).startFrame); } obj.LookAt(startPos); return; // between first and last frame } else if (frame <= (cache[i] as AMOrientationAction).endFrame) { if (!(cache[i] as AMOrientationAction).startTarget || !(cache[i] as AMOrientationAction).endTarget) { return; } float framePositionInPath = frame - (float)cache[i].startFrame; if (framePositionInPath < 0f) { framePositionInPath = 0f; } float percentage = framePositionInPath / cache[i].getNumberOfFrames(); if ((cache[i] as AMOrientationAction).isLookFollow()) { obj.rotation = (cache[i] as AMOrientationAction).getQuaternionAtPercent(percentage); } else { Vector3?startPos = (cachedTranslationTrackStartTarget == null ? null : (Vector3?)(cachedTranslationTrackStartTarget as AMTranslationTrack).getPositionAtFrame((cache[i] as AMOrientationAction).startFrame)); Vector3?endPos = (cachedTranslationTrackEndTarget == null ? null : (Vector3?)(cachedTranslationTrackEndTarget as AMTranslationTrack).getPositionAtFrame((cache[i] as AMOrientationAction).endFrame)); obj.rotation = (cache[i] as AMOrientationAction).getQuaternionAtPercent(percentage, startPos, endPos); } return; // after last frame } else if (i == cache.Count - 2) { if (!(cache[i] as AMOrientationAction).endTarget) { return; } Vector3 endPos; if (cachedTranslationTrackEndTarget == null) { endPos = (cache[i] as AMOrientationAction).endTarget.position; } else { endPos = (cachedTranslationTrackEndTarget as AMTranslationTrack).getPositionAtFrame((cache[i] as AMOrientationAction).endFrame); } obj.LookAt(endPos); return; } } }
public void reloadAnimatorData() { aData = null; loadAnimatorData(); AMTake take = aData.getCurrentTake(); // update references for track and key bool shouldClose = true; foreach(AMTrack _track in take.trackValues) { if(track == _track) { track = _track; foreach(AMKey _key in track.keys) { if(key == _key) { key = _key; shouldClose = false; } } } } if(shouldClose) this.Close(); }
// preview a frame in the scene view public override void previewFrame(float frame, AMTrack extraTrack = null) { if(!_obj) return; if(keys == null || keys.Count <= 0) return; // if before first frame if(frame <= (float)(keys[0] as AMTranslationKey).startFrame) { AMTranslationKey key = keys[0] as AMTranslationKey; position = key.path.Length == 0 ? key.position : key.path[0]; return; } // if beyond last frame if(frame >= (float)(keys[keys.Count - 1] as AMTranslationKey).endFrame) { AMTranslationKey key = keys[keys.Count - 1] as AMTranslationKey; position = key.path.Length == 0 ? key.position : key.path[key.path.Length - 1]; return; } // if lies on curve foreach(AMTranslationKey key in keys) { if(key.path.Length == 0 || ((int)frame < key.startFrame) || ((int)frame > key.endFrame)) continue; if(key.path.Length == 1) { position = key.path[0]; return; } float _value; float framePositionInPath = frame - (float)key.startFrame; if(framePositionInPath < 0f) framePositionInPath = 0f; if(key.hasCustomEase()) { _value = AMUtil.EaseCustom(0.0f, 1.0f, framePositionInPath / key.getNumberOfFrames(), key.easeCurve); } else { TweenDelegate.EaseFunc ease = AMUtil.GetEasingFunction((EaseType)key.easeType); _value = ease(framePositionInPath, 0.0f, 1.0f, key.getNumberOfFrames(), key.amplitude, key.period); if(float.IsNaN(_value)) { //this really shouldn't happen... return; } } AMUtil.PutOnPath(_obj, key.path, Mathf.Clamp(_value, 0f, 1f), _isLocal); return; } }
protected override void DoCopy(AMTrack track) { AMMaterialTrack ntrack = track as AMMaterialTrack; ntrack.obj = obj; ntrack._matOverride = _matOverride; ntrack._matInd = _matInd; ntrack._property = _property; ntrack._propertyType = _propertyType; }
public Texture getTrackIconTexture(AMTrack _track) { if(_track is AMAnimationTrack) return texIconAnimation; else if(_track is AMEventTrack) return texIconEvent; else if(_track is AMPropertyTrack) return texIconProperty; else if(_track is AMTranslationTrack) return texIconTranslation; else if(_track is AMAudioTrack) return texIconAudio; else if(_track is AMRotationTrack) return texIconRotation; else if(_track is AMOrientationTrack) return texIconOrientation; else if(_track is AMGOSetActiveTrack) return texIconProperty; Debug.LogWarning("Animator: Icon texture not found for track " + _track.getTrackType()); return null; }
void appendTrackCode(AMTrack track, ref string code) { string s_init = ""; string s_init_suffix = ""; string s = ""; string objName = "track" + (track.id + 1) + "OBJ"; List <string> init_cameras = new List <string>(); List <string> init_textures = new List <string>(); code += "\n// " + track.name; #region translation if ((track is AMTranslationTrack) && (track as AMTranslationTrack).obj) { code += " (Translation)\n"; if (track.cache.Count <= 0) { return; } // initialize object code += getObjectInitialization("GameObject", objName, (track as AMTranslationTrack).obj.name, aData.codeLanguage, null, null); // set initial position code += getInitialPropertiesFor(aData.codeLanguage, track, objName); #endregion #region rotation } else if ((track is AMRotationTrack) && (track as AMRotationTrack).obj) { code += " (Rotation)\n"; if (track.cache.Count <= 0) { return; } // initialize object code += getObjectInitialization("GameObject", objName, (track as AMRotationTrack).obj.name, aData.codeLanguage, null, null); // set initial rotation code += getInitialPropertiesFor(aData.codeLanguage, track, objName); #endregion #region orientation } else if ((track is AMOrientationTrack) && (track as AMOrientationTrack).obj) { code += " (Orientation)\n"; if (track.cache.Count <= 0) { return; } // initialize object code += getObjectInitialization("GameObject", objName, (track as AMOrientationTrack).obj.name, aData.codeLanguage, null, null); // set initial orientation code += getInitialPropertiesFor(aData.codeLanguage, track, objName); #endregion #region animation } else if ((track is AMAnimationTrack) && (track as AMAnimationTrack).obj) { code += " (Animation)\n"; if (track.cache.Count <= 0) { return; } // initialize object code += getObjectInitialization("GameObject", objName, (track as AMAnimationTrack).obj.name, aData.codeLanguage, null, null); #endregion #region audio } else if ((track is AMAudioTrack) && (track as AMAudioTrack).audioSource) { code += " (Audio)\n"; if (track.cache.Count <= 0) { return; } // initialize object code += getObjectInitialization("AudioSource", objName, (track as AMAudioTrack).audioSource.gameObject.name, aData.codeLanguage, null, null); #endregion #region property } else if ((track is AMPropertyTrack) && (track as AMPropertyTrack).component) { code += " (Property)\n"; if (track.cache.Count <= 0) { return; } // initialize component and MemberInfo (Property or Field) code += getObjectInitialization("Component", objName, (track as AMPropertyTrack).component.gameObject.name, aData.codeLanguage, null, (track as AMPropertyTrack).component.GetType().Name); code += getObjectInitialization((track as AMPropertyTrack).getMemberInfoTypeName(), objName, (track as AMPropertyTrack).component.gameObject.name, aData.codeLanguage, (track as AMPropertyTrack).getTrackType(), (track as AMPropertyTrack).component.GetType().Name); // set initial value code += getInitialPropertiesFor(aData.codeLanguage, track, objName); #endregion #region event } else if ((track is AMEventTrack) && (track as AMEventTrack).obj) { code += " (Event)\n"; if (track.cache.Count <= 0) { return; } // initialize object code += getObjectInitialization("GameObject", objName, (track as AMEventTrack).obj.name, aData.codeLanguage, null, null); #endregion #region camera switcher } else if ((track is AMCameraSwitcherTrack)) { code += " (Camera Switcher)\n"; // all cameras Camera[] csCameras = (track as AMCameraSwitcherTrack).getAllCameras(); if (csCameras.Length > 0) { if (aData.codeLanguage == 0) { code += "Camera[] csCameras = new Camera[]{"; } else { code += "var csCameras = ["; } for (int i = 0; i < csCameras.Length; i++) { init_cameras.Add(getDictionaryValue("GameObject.Find(\"" + csCameras[i].gameObject.name + "\").camera", "csCameras[" + i + "]", null)); code += init_cameras[init_cameras.Count - 1]; //code += "GameObject.Find(\""+csCameras[i].gameObject.name+"\").camera"; if (i <= csCameras.Length - 2) { code += ", "; } } if (aData.codeLanguage == 0) { code += "}"; } else { code += "]"; } code += ";\n"; } // all textures Texture[] csTextures = (track as AMCameraSwitcherTrack).getAllTextures(); if (csTextures.Length > 0) { if (aData.codeLanguage == 0) { code += "Texture[] csTextures = new Texture[]{"; } else { code += "var csTextures = ["; } for (int i = 0; i < csTextures.Length; i++) { init_textures.Add(getDictionaryValue("AMTween.LoadTexture2D(\"" + csTextures[i].name + "\")", "csTextures[" + i + "]", null)); code += init_textures[init_textures.Count - 1]; //code += "GameObject.Find(\""+csCameras[i].gameObject.name+"\").camera"; if (i <= csTextures.Length - 2) { code += ", "; } } if (aData.codeLanguage == 0) { code += "}"; } else { code += "]"; } //code += ";\n"; code += "; // Put Textures in Resources Folder\n"; } // set initial top camera or show color if (track.keys.Count > 0) { AMCameraSwitcherKey cKey = (track.keys[0] as AMCameraSwitcherKey); if (cKey.type == 0) { string strCam = "null /* Missing Camera */"; if (cKey.camera) { strCam = "GameObject.Find(\"" + cKey.camera.gameObject.name + "\").camera"; strCam = getDictionaryValue(strCam, null, null); } code += "AMTween.SetTopCamera(" + strCam + ", csCameras); // Set Initial Camera\n"; } else { if (aData.codeLanguage == 0) { code += "AMTween.ShowColor(new Color(" + cKey.color.r + "f, " + cKey.color.g + "f, " + cKey.color.b + "f, " + cKey.color.a + "f));"; } else { code += "AMTween.ShowColor(Color(" + cKey.color.r + ", " + cKey.color.g + ", " + cKey.color.b + ", " + cKey.color.a + "));"; } code += " // Set Initial Color\n"; } } } else { code += "\n// Missing Track Object\n"; if (track.cache.Count <= 0) { return; } } #endregion #region action foreach (AMAction action in track.cache) { string actionString; // if audioclip resource, use variable name in ToString if (action is AMAudioAction) { actionString = (action as AMAudioAction).ToString(aData.codeLanguage, aData.getCurrentTake().frameRate, objName + "Frame" + action.startFrame); } else if (action is AMEventAction) { actionString = (action as AMEventAction).ToString(aData.codeLanguage, aData.getCurrentTake().frameRate, objName + "Frame" + action.startFrame); } else { actionString = action.ToString(aData.codeLanguage, aData.getCurrentTake().frameRate); } if (action is AMCameraSwitcherAction && actionString != null) { // textures foreach (string _st in init_textures) { //if(numCameras <= 0) break; string prev = actionString; actionString = actionString.Replace(_st, getDictionaryValue(_st, null, null)); if (prev != actionString) { break; // found one texture, break. Change if a single CameraSwitcherAction can have more than one texture } } // cameras int numCameras = 0; if ((action as AMCameraSwitcherAction).startTargetType == 0) { numCameras++; } if ((action as AMCameraSwitcherAction).endTargetType == 0) { numCameras++; } foreach (string _sc in init_cameras) { if (numCameras <= 0) { break; } string prev = actionString; actionString = actionString.Replace(_sc, getDictionaryValue(_sc, null, null)); if (prev != actionString) { numCameras--; } } } if (actionString != null) { s += actionString; s += "\n"; // resource if (action is AMAudioAction) { s_init += getObjectInitialization("AudioClip", objName + "Frame" + action.startFrame, (action as AMAudioAction).audioClip.name, aData.codeLanguage, null, null); } // method info if ((action is AMEventAction) && !(action as AMEventAction).useSendMessage) { string[] event_init = getMethodInfoInitialization((action as AMEventAction).component, (action as AMEventAction).methodName, objName + "Frame" + action.startFrame, aData.codeLanguage); s_init += event_init[0] + "\n"; // add component init s_init_suffix += event_init[1] + "\n"; // add methodinfo init to suffix } } } #endregion s = s_init + s_init_suffix + s; code += s; code = code.Replace("obj.gameObject", objName); code = code.Replace("obj.memberinfo", objName + "Property"); }
public void shiftOutOfBoundsKeysOnTrack(AMTrack _track) { int offset = _track.shiftOutOfBoundsKeys(); if(contextSelection.Count<=0) return; for(int i=0;i<contextSelection.Count;i++) { contextSelection[i] += offset; } // shift all keys on all tracks foreach(AMTrack track in trackValues) { if(track.id==_track.id) continue; track.offsetKeysFromBy(0,offset); } }
void OnAutoKey(AMTrack track, AMKey key) { if(key != null) { Undo.RegisterCreatedObjectUndo(key, "Auto Key"); } }
// timeline action info string getInfoTextForAction(AMTrack _track, AMKey _key, bool brief, int clamped) { // get text for track type #region translation if(_key is AMTranslationKey) { return easeTypeNames[(_key as AMTranslationKey).easeType]; #endregion #region rotation } else if(_key is AMRotationKey) { return easeTypeNames[(_key as AMRotationKey).easeType]; #endregion #region animation } else if(_key is AMAnimationKey) { if(!(_key as AMAnimationKey).amClip) return "Not Set"; return (_key as AMAnimationKey).amClip.name + "\n" + ((WrapMode)(_key as AMAnimationKey).wrapMode).ToString(); #endregion #region audio } else if(_key is AMAudioKey) { if(!(_key as AMAudioKey).audioClip) return "Not Set"; return (_key as AMAudioKey).audioClip.name; #endregion #region property } else if(_key is AMPropertyKey) { string info = (_key as AMPropertyKey).getName() + "\n"; if((_key as AMPropertyKey).targetsAreEqual()) brief = true; if(!brief && (_key as AMPropertyKey).endFrame != -1) { info += easeTypeNames[(_key as AMPropertyKey).easeType] + ": "; } string detail = (_key as AMPropertyKey).getValueString(brief); // extra details such as integer values ex. 1 -> 12 if(detail != null) info += detail; return info; #endregion #region event } else if(_key is AMEventKey) { if((_key as AMEventKey).methodInfo == null) { return "Not Set"; } string txtInfoEvent = (_key as AMEventKey).methodName; // include parameters if((_key as AMEventKey).parameters != null) { txtInfoEvent += "("; for(int i = 0; i < (_key as AMEventKey).parameters.Count; i++) { if((_key as AMEventKey).parameters[i] == null) txtInfoEvent += ""; else txtInfoEvent += (_key as AMEventKey).parameters[i].getStringValue(); if(i < (_key as AMEventKey).parameters.Count - 1) txtInfoEvent += ", "; } txtInfoEvent += ")"; return txtInfoEvent; } return (_key as AMEventKey).methodName; #endregion #region orientation } else if(_key is AMOrientationKey) { if(!(_key as AMOrientationKey).target) return "No Target"; string txtInfoOrientation = null; if((_key as AMOrientationKey).isLookFollow()) { txtInfoOrientation = (_key as AMOrientationKey).target.gameObject.name; return txtInfoOrientation; } txtInfoOrientation = (_key as AMOrientationKey).target.gameObject.name + " -> " + ((_key as AMOrientationKey).endTarget ? (_key as AMOrientationKey).endTarget.gameObject.name : "No Target"); txtInfoOrientation += "\n" + easeTypeNames[(_key as AMOrientationKey).easeType]; return txtInfoOrientation; #endregion #region goactive } else if(_key is AMGOSetActiveKey) { AMGOSetActiveKey act = _key as AMGOSetActiveKey; if(!act.go) return "No GameObject"; if(brief) return string.Format("{0}.SetActive({1})", act.go.name, (_track as AMGOSetActiveTrack).startActive); else return string.Format("{0}.SetActive({1})", act.go.name, act.setActive); #endregion } return "Unknown"; }
// preview a frame in the scene view public override void previewFrame(float frame, AMTrack extraTrack = null) { if (!obj) { return; } if (cache.Count <= 0) { return; } if (cache[0] == null) { updateCache(); } // if before or equal to first frame, or is the only frame if ((frame <= (float)cache[0].startFrame) || ((cache[0] as AMRotationAction).endFrame == -1)) { obj.rotation = (cache[0] as AMRotationAction).getStartQuaternion(); return; } // if beyond or equal to last frame if (frame >= (float)(cache[cache.Count - 2] as AMRotationAction).endFrame) { obj.rotation = (cache[cache.Count - 2] as AMRotationAction).getEndQuaternion(); return; } // if lies on rotation action foreach (AMRotationAction action in cache) { if ((frame < (float)action.startFrame) || (frame > (float)action.endFrame)) { continue; } // if on startFrame if (frame == (float)action.startFrame) { obj.rotation = action.getStartQuaternion(); return; } // if on endFrame if (frame == (float)action.endFrame) { obj.rotation = action.getEndQuaternion(); return; } // else find Quaternion using easing function AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } float framePositionInAction = frame - (float)action.startFrame; if (framePositionInAction < 0f) { framePositionInAction = 0f; } float percentage = framePositionInAction / action.getNumberOfFrames(); Quaternion qStart = action.getStartQuaternion(); Quaternion qEnd = action.getEndQuaternion(); Quaternion qCurrent = new Quaternion(); qCurrent.x = ease(qStart.x, qEnd.x, percentage, curve); qCurrent.y = ease(qStart.y, qEnd.y, percentage, curve); qCurrent.z = ease(qStart.z, qEnd.z, percentage, curve); qCurrent.w = ease(qStart.w, qEnd.w, percentage, curve); obj.rotation = qCurrent; return; } }
public static bool showEasePicker(AMTrack track, AMKey key, AnimatorData aData, float x = -1f, float y = -1f, float width = -1f) { bool didUpdate = false; if(x >= 0f && y >= 0f && width >= 0f) { width--; float height = 22f; Rect rectLabel = new Rect(x, y - 1f, 40f, height); GUI.Label(rectLabel, "Ease"); Rect rectPopup = new Rect(rectLabel.x + rectLabel.width + 2f, y + 3f, width - rectLabel.width - width_button_delete - 3f, height); int nease = EditorGUI.Popup(rectPopup, key.easeType, easeTypeNames); if(key.easeType != nease) { recordUndoTrackAndKeys(track, false, "Change Ease"); key.setEaseType(nease); // update cache when modifying varaibles track.updateCache(); AMCodeView.refresh(); // preview new position aData.getCurrentTake().previewFrame(aData.getCurrentTake().selectedFrame); // save data EditorUtility.SetDirty(track); setDirtyKeys(track); // refresh component didUpdate = true; // refresh values AMEasePicker.refreshValues(); } Rect rectButton = new Rect(width - width_button_delete + 1f, y, width_button_delete, width_button_delete); if(GUI.Button(rectButton, getSkinTextureStyleState("popup").background, GUI.skin.GetStyle("ButtonImage"))) { AMEasePicker.setValues(/*aData,*/key, track); EditorWindow.GetWindow(typeof(AMEasePicker)); } //display specific variable for certain tweens //TODO: only show this for specific tweens if(!key.hasCustomEase()) { y += rectButton.height + 4; Rect rectAmp = new Rect(x, y, 200f, height); key.amplitude = EditorGUI.FloatField(rectAmp, "Amplitude", key.amplitude); y += rectAmp.height + 4; Rect rectPer = new Rect(x, y, 200f, height); key.period = EditorGUI.FloatField(rectPer, "Period", key.period); } } else { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Space(1f); GUILayout.Label("Ease"); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Space(3f); int nease = EditorGUILayout.Popup(key.easeType, easeTypeNames); if(key.easeType != nease) { recordUndoTrackAndKeys(track, false, "Change Ease"); key.setEaseType(nease); // update cache when modifying varaibles track.updateCache(); AMCodeView.refresh(); // preview new position aData.getCurrentTake().previewFrame(aData.getCurrentTake().selectedFrame); // save data EditorUtility.SetDirty(track); setDirtyKeys(track); // refresh component didUpdate = true; // refresh values AMEasePicker.refreshValues(); } GUILayout.EndVertical(); if(GUILayout.Button(getSkinTextureStyleState("popup").background, GUI.skin.GetStyle("ButtonImage"), GUILayout.Width(width_button_delete), GUILayout.Height(width_button_delete))) { AMEasePicker.setValues(/*aData,*/key, track); EditorWindow.GetWindow(typeof(AMEasePicker)); } GUILayout.Space(1f); GUILayout.EndHorizontal(); //display specific variable for certain tweens //TODO: only show this for specific tweens if(!key.hasCustomEase()) { key.amplitude = EditorGUILayout.FloatField("Amplitude", key.amplitude); key.period = EditorGUILayout.FloatField("Period", key.period); } } return didUpdate; }
public static void SetDirtyKeys(AMTrack track) { foreach(AMKey key in track.keys) EditorUtility.SetDirty(key); }
void timelineSelectObjectFor(AMTrack track) { // translation obj if(track.GetType() == typeof(AMTranslationTrack)) Selection.activeObject = track.genericObj; // rotation obj else if(track.GetType() == typeof(AMRotationTrack)) Selection.activeObject = track.genericObj; else if(track.GetType() == typeof(AMAnimationTrack)) Selection.activeObject = (track as AMAnimationTrack).obj; }
// preview frame public virtual void previewFrame(float frame, AMTrack extraTrack = null) { }
bool showTrack(AMTrack _track, int t, int group_level, ref float track_y, ref bool isAnyTrackFoldedOut, ref float height_group_elements, Event e, Vector2 scrollViewBounds) { // track is beyond bounds if(track_y + (_track.foldout ? height_track : height_track_foldin) < scrollViewBounds.x || track_y > scrollViewBounds.y) { if(_track.foldout) { track_y += height_track; isAnyTrackFoldedOut = true; } else { track_y += height_track_foldin; } return false; } // returns true if mouse over track bool mouseOverTrack = false; float track_x = width_subtrack_space * group_level; bool inGroup = group_level > 0; bool isTrackSelected = aData.getCurrentTake().selectedTrack == t; bool isTrackContextSelected = aData.getCurrentTake().contextSelectionTracks.Contains(t); Rect rectTrack; string strStyle; if(isTrackSelected) { if(aData.getCurrentTake().contextSelectionTracks.Count <= 1) strStyle = "GroupElementActive"; else strStyle = "GroupElementSelectedActive"; } else if(isTrackContextSelected) strStyle = "GroupElementSelected"; else strStyle = "GroupElementNormal"; rectTrack = new Rect(track_x, track_y, width_track - track_x, height_track_foldin); // renaming track if(isRenamingTrack != t) { Rect rectTrackFoldin = new Rect(rectTrack.x, rectTrack.y, rectTrack.width, rectTrack.height); // used to toggle track foldout if(_track.foldout) { rectTrackFoldin.width -= 55f; } if(GUI.Button(new Rect(rectTrack.x, rectTrack.y, 15f, rectTrack.height), "", "label")) { _track.foldout = !_track.foldout; timelineSelectTrack(t); } if(GUI.Button(new Rect(rectTrack.x + 15f, rectTrack.y, rectTrack.width - 15f, rectTrack.height), "", "label")) { timelineSelectTrack(t); if(didDoubleClick("track" + t + "foldout")) { cancelTextEditting(); //_track.foldout = !_track.foldout; isRenamingTrack = t; if(!_track.foldout) _track.foldout = true; } } } // set track icon texture Texture texIcon = getTrackIconTexture(_track); // track start, foldin if(!_track.foldout) { if(rectTrack.width > 4f) { if(rectTrack.Contains(e.mousePosition) && mouseOverElement == (int)ElementType.None) { mouseOverTrack = true; mouseOverElement = (int)ElementType.Track; mouseOverGroupElement = new Vector2((inGroup ? aData.getCurrentTake().getTrackGroup(t) : 0), t); } GUI.BeginGroup(rectTrack, GUI.skin.GetStyle(strStyle)); GUI.DrawTexture(new Rect(17f, (height_track_foldin - 12f) / 2f, 12f, 12f), texIcon); GUI.Label(new Rect(17f + 12f + 2f, 0f, rectTrack.width - (12f + 15f + 2f), height_track_foldin), _track.name); GUI.EndGroup(); // draw foldout if(rectTrack.width >= 10f) GUI.DrawTexture(new Rect(track_x, track_y + (height_group - 16f) / 2f, 16f, 16f), (_track.foldout ? GUI.skin.GetStyle("GroupElementFoldout").normal.background : GUI.skin.GetStyle("GroupElementFoldout").active.background)); } else { // tooltip hidden track, foldin GUI.enabled = false; GUI.Button(new Rect(width_track - 80f, track_y, 80f, height_group), trimString(_track.name, 8)); GUI.enabled = !isPlaying; } track_y += height_track_foldin; } else { // track start, foldout // track rect rectTrack = new Rect(track_x, track_y, width_track - track_x, height_track); if(rectTrack.width > 4f) { // select track texture if(rectTrack.Contains(e.mousePosition) && mouseOverElement == (int)ElementType.None) { mouseOverTrack = true; mouseOverElement = (int)ElementType.Track; mouseOverGroupElement = new Vector2((inGroup ? aData.getCurrentTake().getTrackGroup(t) : 0), t); } // draw track texture GUI.BeginGroup(rectTrack, GUI.skin.GetStyle(strStyle)); // track name if(isRenamingTrack == t) { GUI.SetNextControlName("RenameTrack" + t); _track.name = GUI.TextField(new Rect(15f, 2f, rectTrack.width - 15f, 20f), _track.name, 20); GUI.FocusControl("RenameTrack" + t); } else { GUI.Label(new Rect(15f, 0f, rectTrack.width - 15f, 20f), _track.name); } // track type Rect rectTrackIcon = new Rect(4f, 20f, 12f, 12f); GUI.Box(rectTrackIcon, texIcon); string trackType = _track.getTrackType(); Rect rectTrackType = new Rect(rectTrackIcon.x + rectTrackIcon.width + 2f, height_track - 39f, rectTrack.width - 20f, 15f); if((_track is AMPropertyTrack) && (trackType == "Not Set")) rectTrackType.width -= 48f; GUI.Label(rectTrackType, trackType); // if property track, show set property button if(_track is AMPropertyTrack) { if(!(_track as AMPropertyTrack).obj) GUI.enabled = false; GUIStyle styleButtonSet = new GUIStyle(GUI.skin.button); styleButtonSet.clipping = TextClipping.Overflow; if(GUI.Button(new Rect(width_track - 48f - width_subtrack_space * group_level - 4f, height_track - 38f, 48f, 15f), "Set", styleButtonSet)) { // show property select window AMPropertySelect.setValues((_track as AMPropertyTrack)); EditorWindow.GetWindow(typeof(AMPropertySelect)); } GUI.enabled = !isPlaying; } // track object float width_object_field = width_track - track_x; showObjectFieldFor(_track, width_object_field, new Rect(padding_track, 39f, width_track - width_subtrack_space * group_level - padding_track * 2, 16f)); GUI.EndGroup(); } else { // tooltip hidden track, foldout GUI.enabled = false; GUI.Button(new Rect(width_track - 80f, track_y, 80f, height_group), trimString(_track.name, 8)); GUI.enabled = !isPlaying; } // track button if(GUI.Button(rectTrack, "", "label")) { timelineSelectTrack(t); } // draw foldout if(rectTrack.width >= 15f) GUI.DrawTexture(new Rect(track_x, track_y + (height_group - 16f) / 2f, 16f, 16f), (_track.foldout ? GUI.skin.GetStyle("GroupElementFoldout").normal.background : GUI.skin.GetStyle("GroupElementFoldout").active.background)); track_y += height_track; isAnyTrackFoldedOut = true; // track end } // draw element position texture after track if(dragType == (int)DragType.GroupElement) { if(mouseOverElement == (int)ElementType.Track && mouseOverGroupElement.y == t) { GUI.DrawTexture(new Rect(rectTrack.x, rectTrack.y + rectTrack.height - height_element_position, rectTrack.width, height_element_position), tex_element_position); } } height_group_elements += rectTrack.height; return mouseOverTrack; }
public override void previewFrame(float frame, AMTrack extraTrack = null) { if (cache == null || cache.Count <= 0) { return; } bool isPreview = !Application.isPlaying; //GameObject go = GameObject.Find ("AMCameraFade"); //AMCameraFade cf = null; //if(go) cf = (AMCameraFade) go.GetComponent(typeof(AMCameraFade)); for (int i = 0; i < cache.Count; i++) { // before first frame if (frame <= (cache[i] as AMCameraSwitcherAction).startFrame) { //if(cf) DestroyImmediate(cf.gameObject); AMCameraFade.reset(); if (!(cache[i] as AMCameraSwitcherAction).hasStartTarget()) { return; } if ((cache[i] as AMCameraSwitcherAction).startTargetType == 0) { //(cache[i] as AMCameraSwitcherAction).startCamera.targetTexture = null; AMTween.SetTopCamera((cache[i] as AMCameraSwitcherAction).startCamera, cachedAllCameras); } else { showColor((cache[i] as AMCameraSwitcherAction).startColor, isPreview); // or color # TO DO # } return; // between first and last frame } else if (frame <= (cache[i] as AMCameraSwitcherAction).endFrame) { if (!(cache[i] as AMCameraSwitcherAction).hasStartTarget() || !(cache[i] as AMCameraSwitcherAction).hasEndTarget()) { return; } // targets are equal if ((cache[i] as AMCameraSwitcherAction).targetsAreEqual()) { //if(cf) DestroyImmediate(cf.gameObject); AMCameraFade.reset(); if ((cache[i] as AMCameraSwitcherAction).startTargetType == 0) { // use camera (cache[i] as AMCameraSwitcherAction) startTarget //(cache[i] as AMCameraSwitcherAction).startCamera.targetTexture = null; // if not first frame, set top camera AMTween.SetTopCamera((cache[i] as AMCameraSwitcherAction).startCamera, cachedAllCameras); } else { showColor((cache[i] as AMCameraSwitcherAction).startColor, isPreview); // or color # TO DO # } } else { //if((cache[i] as AMCameraSwitcherAction).endTargetType == 0) (cache[i] as AMCameraSwitcherAction).endCamera.targetTexture = null; AMCameraFade.clearRenderTexture(); // preview transition: (cache[i] as AMCameraSwitcherAction).cameraFadeType previewCameraFade(frame, (cache[i] as AMCameraSwitcherAction), isPreview); } return; // after last frame } else if (i == cache.Count - 2) { //if(cf) DestroyImmediate(cf.gameObject); AMCameraFade.reset(); if (!(cache[i] as AMCameraSwitcherAction).hasEndTarget()) { return; } // use camera (cache[i] as AMCameraSwitcherAction) endTarget if ((cache[i] as AMCameraSwitcherAction).endTargetType == 0) { // use camera (cache[i] as AMCameraSwitcherAction) startTarget //(cache[i] as AMCameraSwitcherAction).endCamera.targetTexture = null; AMTween.SetTopCamera((cache[i] as AMCameraSwitcherAction).endCamera, cachedAllCameras); } else { showColor((cache[i] as AMCameraSwitcherAction).endColor, isPreview); // or color # TO DO # } return; } } }
void showObjectFieldFor(AMTrack amTrack, float width_track, Rect rect) { if(rect.width < 22f) return; // show object field for track, used in OnGUI. Needs to be updated for every track type. GUI.skin = null; EditorGUIUtility.LookLikeControls(); // add objectfield for every track type // translation if(amTrack is AMTranslationTrack) { (amTrack as AMTranslationTrack).obj = (Transform)EditorGUI.ObjectField(rect, amTrack.genericObj, typeof(Transform), true/*,GUILayout.Width (width_track-padding_track*2)*/); } // rotation else if(amTrack is AMRotationTrack) { (amTrack as AMRotationTrack).obj = (Transform)EditorGUI.ObjectField(rect, amTrack.genericObj, typeof(Transform), true); } // rotation else if(amTrack is AMOrientationTrack) { if((amTrack as AMOrientationTrack).setObject((Transform)EditorGUI.ObjectField(rect, (amTrack as AMOrientationTrack).obj, typeof(Transform), true))) { amTrack.updateCache(); AMCodeView.refresh(); } } // animation else if(amTrack is AMAnimationTrack) { //GameObject _old = (amTrack as AMAnimationTrack).obj; if((amTrack as AMAnimationTrack).setObject((GameObject)EditorGUI.ObjectField(rect, (amTrack as AMAnimationTrack).obj, typeof(GameObject), true))) { //Animation _temp = (Animation)(amTrack as AMAnimationTrack).obj.GetComponent("Animation"); if((amTrack as AMAnimationTrack).obj != null) { if((amTrack as AMAnimationTrack).obj.animation == null) { (amTrack as AMAnimationTrack).obj = null; EditorUtility.DisplayDialog("No Animation Component", "You must add an Animation component to the GameObject before you can use it in an Animation Track.", "Okay"); } } } } // audio else if(amTrack is AMAudioTrack) { if((amTrack as AMAudioTrack).setAudioSource((AudioSource)EditorGUI.ObjectField(rect, (amTrack as AMAudioTrack).audioSource, typeof(AudioSource), true))) { if((amTrack as AMAudioTrack).audioSource != null) { (amTrack as AMAudioTrack).audioSource.playOnAwake = false; } } } // property else if(amTrack is AMPropertyTrack) { GameObject propertyGameObject = (GameObject)EditorGUI.ObjectField(rect, (amTrack as AMPropertyTrack).obj, typeof(GameObject), true); if((amTrack as AMPropertyTrack).isObjectUnique(propertyGameObject)) { bool changePropertyGameObject = true; if((amTrack.keys.Count > 0) && (!EditorUtility.DisplayDialog("Data Will Be Lost", "You will lose all of the keyframes on track '" + amTrack.name + "' if you continue.", "Continue Anway", "Cancel"))) { changePropertyGameObject = false; } if(changePropertyGameObject) { Undo.RecordObject(amTrack, "Set GameObject"); // delete all keys if(amTrack.keys.Count > 0) { foreach(AMKey key in amTrack.keys) Undo.DestroyObjectImmediate(key); amTrack.keys = new List<AMKey>(); amTrack.updateCache(); AMCodeView.refresh(); } (amTrack as AMPropertyTrack).setObject(propertyGameObject); EditorUtility.SetDirty(amTrack); } } } // event else if(amTrack is AMEventTrack) { GameObject eventGameObject = (GameObject)EditorGUI.ObjectField(rect, (amTrack as AMEventTrack).obj, typeof(GameObject), true); if((amTrack as AMEventTrack).isObjectUnique(eventGameObject)) { bool changeEventGameObject = true; if((amTrack.keys.Count > 0) && (!EditorUtility.DisplayDialog("Data Will Be Lost", "You will lose all of the keyframes on track '" + amTrack.name + "' if you continue.", "Continue Anway", "Cancel"))) { changeEventGameObject = false; } if(changeEventGameObject) { Undo.RecordObject(amTrack, "Set GameObject"); // delete all keys if(amTrack.keys.Count > 0) { foreach(AMKey key in amTrack.keys) Undo.DestroyObjectImmediate(key); amTrack.keys = new List<AMKey>(); amTrack.updateCache(); AMCodeView.refresh(); } (amTrack as AMEventTrack).setObject(eventGameObject); EditorUtility.SetDirty(amTrack); } } } // set go active else if(amTrack is AMGOSetActiveTrack) { AMGOSetActiveTrack goActiveTrack = amTrack as AMGOSetActiveTrack; goActiveTrack.setObject((GameObject)EditorGUI.ObjectField(rect, goActiveTrack.genericObj, typeof(GameObject), true/*,GUILayout.Width (width_track-padding_track*2)*/)); } GUI.skin = skin; EditorGUIUtility.LookLikeControls(); }
public void addTrack(AMTrack track) { trackKeys.Add(track.id); trackValues.Add(track); addToGroup(track.id,selectedGroup); track.parentTake = this; }
// preview a frame in the scene view public override void previewFrame(float frame, AMTrack extraTrack = null) { if(!_obj) return; if(keys == null || keys.Count <= 0) return; // if before or equal to first frame, or is the only frame if((frame <= (float)keys[0].frame) || ((keys[0] as AMRotationKey).endFrame == -1)) { rotation = (keys[0] as AMRotationKey).getStartQuaternion(); return; } // if beyond or equal to last frame if(frame >= (float)(keys[keys.Count - 2] as AMRotationKey).endFrame) { rotation = (keys[keys.Count - 2] as AMRotationKey).getEndQuaternion(); return; } // if lies on rotation action foreach(AMRotationKey key in keys) { if((frame < (float)key.frame) || (frame > (float)key.endFrame)) continue; // if on startFrame if(frame == (float)key.frame) { rotation = key.getStartQuaternion(); return; } // if on endFrame if(frame == (float)key.endFrame) { rotation = key.getEndQuaternion(); return; } // else find Quaternion using easing function float framePositionInAction = frame - (float)key.frame; if(framePositionInAction < 0f) framePositionInAction = 0f; Quaternion qStart = key.getStartQuaternion(); Quaternion qEnd = key.getEndQuaternion(); if(key.hasCustomEase()) { rotation = Quaternion.Slerp(qStart, qEnd, AMUtil.EaseCustom(0.0f, 1.0f, framePositionInAction / key.getNumberOfFrames(), key.easeCurve)); } else { TweenDelegate.EaseFunc ease = AMUtil.GetEasingFunction((EaseType)key.easeType); rotation = Quaternion.Slerp(qStart, qEnd, ease(framePositionInAction, 0.0f, 1.0f, key.getNumberOfFrames(), key.amplitude, key.period)); } return; } }
string getInitialPropertiesFor(int codeLanguage, AMTrack _track, string varName) { // initialize the starting variables (such as initial position and rotation), codeLanguage 0=C#, 1=JS if (_track is AMTranslationTrack) { // translation, set initial position Vector3 _position = (_track as AMTranslationTrack).getInitialPosition(); if (codeLanguage == 0) { return(varName + ".transform.position = new Vector3(" + _position.x + "f, " + _position.y + "f, " + _position.z + "f); // Set Initial Position\n"); } else { return(varName + ".transform.position = Vector3(" + _position.x + ", " + _position.y + ", " + _position.z + "); // Set Initial Position\n"); } } else if (_track is AMRotationTrack) { // rotation, set initial rotation Vector4 _rotation = (_track as AMRotationTrack).getInitialRotation(); if (codeLanguage == 0) { return(varName + ".transform.rotation = new Quaternion(" + _rotation.x + "f, " + _rotation.y + "f, " + _rotation.z + "f, " + _rotation.w + "f); // Set Initial Rotation\n"); } else { return(varName + ".transform.rotation = Quaternion(" + _rotation.x + ", " + _rotation.y + ", " + _rotation.z + ", " + _rotation.w + "); // Set Initial Rotation\n"); } } else if (_track is AMOrientationTrack && (_track as AMOrientationTrack).getInitialTarget()) { // orientation, set initial look Transform _target = (_track as AMOrientationTrack).getInitialTarget(); int start_frame = 0; AMTrack _translation_track = null; if ((_track as AMOrientationTrack).keys.Count > 0) { start_frame = (_track as AMOrientationTrack).keys[0].frame; } if (start_frame > 0) { _translation_track = aData.getCurrentTake().getTranslationTrackForTransform(_target); } Vector3 _lookv3 = _target.transform.position; if (_translation_track) { _lookv3 = (_translation_track as AMTranslationTrack).getPositionAtFrame(start_frame); } if (codeLanguage == 0) { return(varName + ".transform.LookAt (new Vector3(" + _lookv3.x + "f, " + _lookv3.y + "f, " + _lookv3.z + "f)); // Set Initial Orientation\n"); } else { return(varName + ".transform.LookAt (Vector3(" + _lookv3.x + ", " + _lookv3.y + ", " + _lookv3.z + ")); // Set Initial Orientation\n"); } } else if (_track is AMPropertyTrack) { // property, set initial value return((_track as AMPropertyTrack).getValueInitialization(codeLanguage, varName) + " // Set Initial Value\n"); } return(null); }
public AMKey[] getContextSelectionKeysForTrack(AMTrack track) { List<AMKey> keys = new List<AMKey>(); foreach(AMKey key in track.keys) { for(int i=0;i<contextSelection.Count;i+=2) { // if selection start frame > frame, break out of sorted list if(contextSelection[i] > key.frame) break; if(contextSelection[i] <= key.frame && contextSelection[i+1] >= key.frame) keys.Add(key); } } return keys.ToArray(); }