void Update() { if (isPaused || nowPlayingTake == null) { return; } CurrentTakePlayTime += Time.deltaTime; if (CurrentTakePlayTime >= takeTime) { nowPlayingTake.stopAudio(); nowPlayingTake.NotifyEnd(); if (isLooping) { Execute(nowPlayingTake); } else { nowPlayingTake = null; } } else { nowPlayingTake.NotifyUpdate(); } }
public void Execute(AMTake take, bool isFrame = true, float value = 0f /* frame or time */) { if (nowPlayingTake != null) { AMTween.Stop(); } take.rebind(rebindOption); // delete AMCameraFade float startFrame = value; float startTime = value; if (!isFrame) { startFrame *= take.frameRate; // convert time to frame } if (isFrame) { startTime /= take.frameRate; // convert frame to time } take.executeActions(startFrame); elapsedTime = startTime; takeTime = (float)take.numFrames / (float)take.frameRate; nowPlayingTake = take; take.unbind(rebindOption); }
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 void makeTakeNameUnique(AMTake take) { bool loop = false; int count = 0; do { if (loop) { loop = false; } foreach (AMTake _take in takes) { if (_take != take && _take.name == take.name) { if (count > 0) { take.name = take.name.Substring(0, take.name.Length - 3); } count++; take.name += "(" + count + ")"; loop = true; break; } } } while (loop); }
public void addAndSaveTake(string takeName, string path) { AMTake a = ScriptableObject.CreateInstance <AMTake>(); // set defaults a.name = takeName; makeTakeNameUnique(a); a.frameRate = 30; a.numFrames = 120; a.startFrame = 1; a.selectedFrame = 1; a.selectedTrack = -1; a.playbackSpeedIndex = 2; //a.lsTracks = new List<AMTrack>(); //a.dictTracks = new Dictionary<int,AMTrack>(); a.trackKeys = new List <int>(); a.trackValues = new List <AMTrack>(); takes.Add(a); #if UNITY_EDITOR AssetDatabase.CreateAsset(a, path); #endif selectTake(takes.Count - 1); }
void AnimCompleted(AnimatorData dat, AMTake _take) { if (repeat && !mStopped) { Invoke("DoPlay", repeatDelay); } }
void Start() { if (playOnStart) { Play(playOnStart.name, true, 0f, false); playOnStart = null; } }
public void Play(string take_name, bool isFrame, float value, bool loop) { nowPlayingTake = getTake(take_name); if (nowPlayingTake) { isLooping = loop; Execute(nowPlayingTake, isFrame, value); } }
public void SaveAsset(AnimatorData mb, AMTake take) { AMTakeSav.AddObjectToAsset(this, take); for (int i = 0; i < lsArray.Count; ++i) { var p = lsArray[i]; p.SaveAsset(mb, take); } }
public void importTake(AMTake take) { if (takes.Contains(take)) { return; } takes.Add(take); makeTakeNameUnique(take); selectTake(takes.Count - 1); }
public int getTakeIndex(AMTake take) { for (int i = 0; i < takes.Count; i++) { if (takes[i] == take) { return(i); } } return(-1); }
public override void SaveAsset(AnimatorData mb, AMTake take) { base.SaveAsset(mb, take); if (parameters != null) { for (int i = 0; i < parameters.Count; ++i) { var p = parameters[i]; AMTakeSav.AddObjectToAsset(p, take); } } }
/*public bool setShowWarningForLostReferences(bool showWarningForLostReferences) { * if(this.showWarningForLostReferences != showWarningForLostReferences) { * this.showWarningForLostReferences = showWarningForLostReferences; * return true; * } * return false; * }*/ public void deleteAllTakesExcept(AMTake take) { for (int index = 0; index < takes.Count; index++) { if (takes[index] == take) { continue; } deleteTake(index); index--; } }
public override void SaveAsset(AnimatorData mb, AMTake take) { base.SaveAsset(mb, take); if (parameters != null) { for (var ie = parameters.GetEnumerator(); ie.MoveNext();) { AMEventParameter p = ie.Current; AMTakeSav.AddObjectToAsset(p, take); } } }
/// <summary> /// called by AMTake.SaveAsset, /// the subclasses will override this to save into the asset /// </summary> #if UNITY_EDITOR public virtual void SaveAsset(AnimatorData mb, AMTake take) { AMTakeSav.AddObjectToAsset(this, take); foreach (var key in keys) { key.SaveAsset(mb, take); } foreach (var act in cache) { act.SaveAsset(mb, take); } }
public void StopLoop() { if (nowPlayingTake == null) { return; } nowPlayingTake.stopAudio(); nowPlayingTake.stopAnimations(); nowPlayingTake = null; isLooping = false; isPaused = false; AMTween.Stop(); }
public void updateOrientationCache(AMTake curTake, bool restoreRotation = false) { AMUtil.recordObject(this, "update cache"); // save rotation Quaternion temp = obj.rotation; // sort keys sortKeys(); destroyCache(); cache = new List <AMAction>(); AMTranslationTrack translationTrack = curTake.getTranslationTrackForTransform(obj); for (int i = 0; i < keys.Count; i++) { // create new action and add it to cache list AMOrientationAction a = ScriptableObject.CreateInstance <AMOrientationAction> (); a.startFrame = keys[i].frame; if (keys.Count > (i + 1)) { a.endFrame = keys[i + 1].frame; } else { a.endFrame = -1; } a.obj = obj; // targets a.startTarget = (keys[i] as AMOrientationKey).target; if (a.endFrame != -1) { a.endTarget = (keys[i + 1] as AMOrientationKey).target; } a.easeType = (keys[i] as AMOrientationKey).easeType; a.customEase = new List <float>(keys[i].customEase); if (translationTrack != null && !a.isLookFollow()) { a.isSetStartPosition = true; a.startPosition = translationTrack.getPositionAtFrame(a.startFrame); a.isSetEndPosition = true; a.endPosition = translationTrack.getPositionAtFrame(a.endFrame); } // add to cache cache.Add(a); } // restore rotation if (restoreRotation) { obj.rotation = temp; } }
public void deleteTake(int index) { //if(shouldCheckDependencies) shouldCheckDependencies = false; if (playOnStart == takes[index]) { playOnStart = null; } takes[index].destroy(); takes.RemoveAt(index); if ((currentTake >= index) && (currentTake > 0)) { currentTake--; } }
public List <GameObject> getDependencies(AMTake _take = null) { // if only one take if (_take != null) { return(_take.getDependencies().ToList()); } // if all takes List <GameObject> ls = new List <GameObject>(); foreach (AMTake take in takes) { ls = ls.Union(take.getDependencies()).ToList(); } return(ls); }
void OnTimeWarpAnimFinish(AnimatorData animDat, AMTake take) { if (animDat == timeWarp) { if (take.name == timeWarpStartTake) { if (!IsInvoking(timeWarpEndFunc)) { Invoke(timeWarpEndFunc, timeWarpExpireDelay); } } else if (take.name == timeWarpEndTake) { timeWarp.gameObject.SetActive(false); mLastTimeWarpEndTime = Time.fixedTime; } } }
void OnShellAnimDone(AnimatorData anim, AMTake take) { if (take.name == "close") { shellAnimDat.Play("normal"); Invoke(openFunc, openDelay); } else if (take.name == "open") { mIsOpen = true; SetClosedState(false); mLastShotTime = Time.time; mCurShotCount = 0; InvokeRepeating(orientFunc, 0, orientAcquireDelay); } }
private void _deleteTake_impl(int index) { #if UNITY_EDITOR if (EditorApplication.isPlaying) { takes[index].destroy(); takes.RemoveAt(index); } else { AMTake oneTake = takes[index]; //AMUtil.recordObject(this, "delete take"); //delete take is not undo-able takes.RemoveAt(index); oneTake.destroy(); } #else takes[index].destroy(); takes.RemoveAt(index); #endif }
void Update() { if (isPaused || nowPlayingTake == null) { return; } elapsedTime += Time.deltaTime; if (elapsedTime >= takeTime) { nowPlayingTake.stopAudio(); if (isLooping) { Execute(nowPlayingTake); } else { nowPlayingTake = null; } } }
public void addTake(string takeName) { AMTake a = ScriptableObject.CreateInstance <AMTake>(); // set defaults a.name = takeName; makeTakeNameUnique(a); a.frameRate = 30; a.numFrames = 120; a.startFrame = 1; a.selectedFrame = 1; a.selectedTrack = -1; a.playbackSpeedIndex = 2; //a.lsTracks = new List<AMTrack>(); //a.dictTracks = new Dictionary<int,AMTrack>(); a.trackKeys = new List <int>(); a.trackValues = new List <AMTrack>(); takes.Add(a); selectTake(takes.Count - 1); }
public void deleteTake(int index) { //if(shouldCheckDependencies) shouldCheckDependencies = false; // event if (currentTake == index) { var oldTake = safeGetTake(currentTake); var newTake = currentTake == 0 ? safeGetTake(1) : safeGetTake(currentTake - 1); evtBefChangeCurTake(oldTake, newTake); } if (playOnStart == takes[index]) { playOnStart = null; } _deleteTake_impl(index); if ((currentTake >= index) && (currentTake > 0)) { currentTake--; } }
void Update() { if(isPaused || nowPlayingTake == null) return; elapsedTime += Time.deltaTime; if(elapsedTime >= takeTime) { nowPlayingTake.stopAudio(); if(isLooping) Execute(nowPlayingTake); else nowPlayingTake = null; } }
public int getTakeIndex(AMTake take) { for(int i=0;i<takes.Count;i++) { if(takes[i] == take) return i; } return -1; }
/*public bool setShowWarningForLostReferences(bool showWarningForLostReferences) { if(this.showWarningForLostReferences != showWarningForLostReferences) { this.showWarningForLostReferences = showWarningForLostReferences; return true; } return false; }*/ public void deleteAllTakesExcept(AMTake take) { for(int index=0;index<takes.Count;index++) { if(takes[index] == take) continue; deleteTake(index); index--; } }
void OnTakeSequenceDone(AMTake aTake) { if(takeCompleteCallback != null) takeCompleteCallback(this, aTake); }
public List<GameObject> getDependencies(AMTake _take = null) { // if only one take if(_take != null) return _take.getDependencies().ToList(); // if all takes List<GameObject> ls = new List<GameObject>(); foreach(AMTake take in takes) { ls = ls.Union(take.getDependencies()).ToList(); } return ls; }
public void Execute(AMTake take, bool isFrame = true, float value = 0f /* frame or time */) { if(nowPlayingTake != null) AMTween.Stop(); // delete AMCameraFade float startFrame = value; float startTime = value; if(!isFrame) startFrame *= take.frameRate; // convert time to frame if(isFrame) startTime /= take.frameRate; // convert frame to time take.executeActions(startFrame); elapsedTime = startTime; takeTime = (float)take.numFrames/(float)take.frameRate; nowPlayingTake = take; }
protected override AMTrack doDuplicate(AMTake newTake) { AMEventTrack ntrack = newTake.gameObject.AddComponent<AMEventTrack>(); ntrack.enabled = false; ntrack.obj = obj; return ntrack; }
void OnShellAnimDone(AnimatorData anim, AMTake take) { if(take.name == "close") { shellAnimDat.Play("normal"); Invoke(openFunc, openDelay); } else if(take.name == "open") { mIsOpen = true; stats.isInvul = false; mLastShotTime = Time.time; mCurShotCount = 0; InvokeRepeating(orientFunc, 0, orientAcquireDelay); } }
public void updateOrientationCache(AMTake curTake, bool restoreRotation = false) { // save rotation Quaternion temp = obj.rotation; // sort keys sortKeys(); for(int i = 0; i < keys.Count; i++) { AMOrientationKey key = keys[i] as AMOrientationKey; key.version = version; if(keys.Count > (i + 1)) key.endFrame = keys[i + 1].frame; else key.endFrame = -1; key.obj = obj; // targets if(key.endFrame != -1) key.endTarget = (keys[i + 1] as AMOrientationKey).target; } // restore rotation if(restoreRotation) obj.rotation = temp; }
static void setDirtyTracks(AMTake take) { foreach(AMTrack track in take.trackValues) { EditorUtility.SetDirty(track); } }
/// <summary> /// will write the transformPath /// </summary> public override void SaveAsset(AnimatorData mb, AMTake take) { base.SaveAsset(mb, take); }
public void updateOrientationCache(AMTake curTake,bool restoreRotation = false) { // save rotation Quaternion temp = obj.rotation; // sort keys sortKeys(); destroyCache(); cache = new List<AMAction>(); AMTranslationTrack translationTrack = curTake.getTranslationTrackForTransform(obj); for(int i=0;i<keys.Count;i++) { // create new action and add it to cache list AMOrientationAction a = ScriptableObject.CreateInstance<AMOrientationAction> (); a.startFrame = keys[i].frame; if(keys.Count>(i+1)) a.endFrame = keys[i+1].frame; else a.endFrame = -1; a.obj = obj; // targets a.startTarget = (keys[i] as AMOrientationKey).target; if(a.endFrame!=-1) a.endTarget = (keys[i+1] as AMOrientationKey).target; a.easeType = (keys[i] as AMOrientationKey).easeType; a.customEase = new List<float>(keys[i].customEase); if(translationTrack != null && !a.isLookFollow()) { a.isSetStartPosition = true; a.startPosition = translationTrack.getPositionAtFrame(a.startFrame); a.isSetEndPosition = true; a.endPosition = translationTrack.getPositionAtFrame(a.endFrame); } // add to cache cache.Add (a); } // restore rotation if(restoreRotation) obj.rotation = temp; }
public void StopLoop() { if(nowPlayingTake == null) return; nowPlayingTake.stopAudio(); nowPlayingTake.stopAnimations(); nowPlayingTake = null; isLooping = false; isPaused = false; AMTween.Stop(); }
public virtual void SaveAsset(AnimatorData mb, AMTake take) { AMTakeSav.AddObjectToAsset(this, take); }
public void Play(string take_name, bool isFrame, float value, bool loop) { nowPlayingTake = getTake(take_name); if(nowPlayingTake) { isLooping = loop; Execute (nowPlayingTake, isFrame, value); } }
public AMTrack duplicate(AMTake newTake) { AMTrack ntrack = doDuplicate(newTake); if(ntrack != null) { ntrack.id = id; ntrack.parentTake = newTake; ntrack.name = name; } return ntrack; }
/// <summary> /// This will only duplicate the tracks and groups /// </summary> /// <param name="take"></param> public List<UnityEngine.Object> duplicateTake(AMTake dupTake) { List<UnityEngine.Object> ret = new List<Object>(); AMTake a = AMTake.NewInstance(dataHolder); ret.Add(a); a.name = dupTake.name; makeTakeNameUnique(a); a.numLoop = dupTake.numLoop; a.loopMode = dupTake.loopMode; a.frameRate = dupTake.frameRate; a.numFrames = dupTake.numFrames; a.startFrame = dupTake.startFrame; a.selectedFrame = 1; a.selectedTrack = dupTake.selectedTrack; a.selectedGroup = dupTake.selectedGroup; a.playbackSpeedIndex = 2; //a.lsTracks = new List<AMTrack>(); //a.dictTracks = new Dictionary<int,AMTrack>(); if(dupTake.rootGroup != null) { a.rootGroup = dupTake.rootGroup.duplicate(); } else { a.initGroups(); } a.group_count = dupTake.group_count; if(dupTake.groupValues != null) { a.groupValues = new List<AMGroup>(); foreach(AMGroup grp in dupTake.groupValues) { a.groupValues.Add(grp.duplicate()); } } a.track_count = dupTake.track_count; if(dupTake.trackValues != null) { a.trackValues = new List<AMTrack>(); foreach(AMTrack track in dupTake.trackValues) { AMTrack dupTrack = track.duplicate(a); a.trackValues.Add(dupTrack); ret.Add(dupTrack); } } a.contextSelection = new List<int>(); a.ghostSelection = new List<int>(); a.contextSelectionTracks = new List<int>(); takes.Add(a); selectTake(takes.Count - 1); return ret; }
public void destroy() { // destroy keys if(keys != null) { foreach(AMKey key in keys) { if(key) key.destroy(); } keys.Clear(); keys = null; } parentTake = null; // destroy track Object.DestroyImmediate(this); }
public void makeTakeNameUnique(AMTake take) { bool loop = false; int count = 0; do { if(loop) loop = false; foreach(AMTake _take in takes) { if(_take != take && _take.name == take.name) { if(count>0) take.name = take.name.Substring(0,take.name.Length-3); count++; take.name += "("+count+")"; loop = true; break; } } } while (loop); }
protected override AMTrack doDuplicate(AMTake newTake) { AMAudioTrack ntrack = newTake.gameObject.AddComponent<AMAudioTrack>(); ntrack.enabled = false; ntrack.audioSource = audioSource; return ntrack; }
void OnAnimationComplete(AnimatorData anim, AMTake take) { Release(); }
public void deleteTake(int index) { //if(shouldCheckDependencies) shouldCheckDependencies = false; if(playOnStart == takes[index]) playOnStart = null; takes[index].destroy(); takes.RemoveAt(index); if((currentTake>=index)&&(currentTake>0)) currentTake--; }
public override void OnInspectorGUI() { serializedObject.Update(); AnimatorData mb = target as AnimatorData; Dbg.Assert(mb != null, "AnimatorDataEditor.OnInspectorGUI: cannot get target: {0}", target.name); EditorGUILayout.HelpBox("If you want to modify the takes list, do it via the Timeline editor", MessageType.Info); if (EUtil.Button("Open Timeline Editor", Color.green)) { AMTimeline.ResetWithAnimatorData((AnimatorData)target); } string playOnStartName = (m_spPlayOnStart.objectReferenceValue != null) ? ((AMTake)m_spPlayOnStart.objectReferenceValue).name : "None"; EditorGUILayout.LabelField("Play On Start: " + playOnStartName); EUtil.DrawSplitter(); for (int i = 0; i < m_spTakes.arraySize; ++i) { var oneTake = m_spTakes.GetArrayElementAtIndex(i); GUILayout.BeginHorizontal(); { if (oneTake != null && oneTake.objectReferenceValue != null) { AMTake takeObj = oneTake.objectReferenceValue as AMTake; EditorGUILayout.LabelField(string.Format("{0}: \"{1} fr, {2} fps\"", takeObj.name, takeObj.numFrames, takeObj.frameRate)); if (GUILayout.Button(new GUIContent(ms_inspectTex, "inspect this take's content"), GUILayout.Height(20f), GUILayout.Width(30f))) { Selection.activeObject = takeObj; } //EUtil.PushGUIColor(EditorUtility.IsPersistent(takeObj) ? Color.yellow : Color.green); //if (GUILayout.Button(new GUIContent("S", "save asset to disk"), GUILayout.Width(30f))) //{ // string path = null; // if (!EditorUtility.IsPersistent(takeObj)) // path = EditorUtility.SaveFilePanelInProject("Save Take", takeObj.name, "asset", "Select asset path"); // else // path = AssetDatabase.GetAssetPath(takeObj); // if (!string.IsNullOrEmpty(path)) // { // takeObj.SaveAsset(mb, path); // EUtil.ShowNotification("Saved Take at: " + path, 3f); // } //} //EUtil.PopGUIColor(); } else { GUILayout.Label("This slot is null reference"); } } GUILayout.EndHorizontal(); } serializedObject.ApplyModifiedProperties(); }
void Play(string take_name, bool isFrame, float value, bool loop) { AMTake newPlayTake = getTake(take_name); if(!newPlayTake) { Stop(); return; } if(newPlayTake != nowPlayingTake && nowPlayingTake != null) { Pause(); } nowPlayingTake = newPlayTake; float startTime = value; if(isFrame) startTime /= nowPlayingTake.frameRate; float startFrame = 0;//isFrame ? value : nowPlayingTake.frameRate * value; if(nowPlayingTake.sequence == null) nowPlayingTake.BuildSequence(gameObject.name, sequenceKillWhenDone, updateType, startFrame); else { //TODO: make this more efficient if(value == 0.0f) nowPlayingTake.previewFrame(0, false, true); /*if(startTime > nowPlayingTake.sequence.duration) startFrame = (startTime / nowPlayingTake.sequence.duration) * nowPlayingTake.frameRate; nowPlayingTake.previewFrame(startFrame, false, true);*/ } if(nowPlayingTake.sequence != null) { if(loop) { nowPlayingTake.sequence.loops = -1; } else { nowPlayingTake.sequence.loops = nowPlayingTake.numLoop; } nowPlayingTake.sequence.GoTo(startTime); nowPlayingTake.sequence.Play(); nowPlayingTake.sequence.timeScale = mAnimScale; } //isLooping = loop; //Execute(nowPlayingTake, isFrame, value); }
protected virtual AMTrack doDuplicate(AMTake newTake) { return null; }
void OnLauncherAnimComplete(AnimatorData animDat, AMTake take) { mTarget = null; InvokeRepeating("DoActiveCheck", launcherFireDelay, activateCheckDelay); }
void Start() { if(playOnStart) { Play (playOnStart.name,true,0f,false); playOnStart = null; } }
public void Stop() { if(nowPlayingTake == null) return; nowPlayingTake.stopAudio(); nowPlayingTake.stopAnimations(); if(nowPlayingTake.sequence != null) { nowPlayingTake.sequence.Pause(); nowPlayingTake.sequence.GoTo(0); } nowPlayingTake = null; }
protected override AMTrack doDuplicate(AMTake newTake) { AMGOSetActiveTrack ntrack = newTake.gameObject.AddComponent<AMGOSetActiveTrack>(); ntrack.enabled = false; ntrack.obj = obj; ntrack.startActive = startActive; return ntrack; }
protected override AMTrack doDuplicate(AMTake newTake) { AMPropertyTrack ntrack = newTake.gameObject.AddComponent<AMPropertyTrack>(); ntrack.enabled = false; ntrack.valueType = valueType; ntrack.obj = obj; ntrack.component = component; ntrack.propertyName = propertyName; ntrack.fieldName = fieldName; ntrack.methodName = methodName; if(methodParameterTypes != null) { ntrack.methodParameterTypes = new string[methodParameterTypes.Length]; Array.Copy(methodParameterTypes, ntrack.methodParameterTypes, methodParameterTypes.Length); } return ntrack; }
void OnAnimationEnd(AnimatorData dat, AMTake take) { StartGame(); }
protected override AMTrack doDuplicate(AMTake newTake) { AMTranslationTrack ntrack = newTake.gameObject.AddComponent<AMTranslationTrack>(); ntrack.enabled = false; ntrack._obj = _obj; ntrack._isLocal = _isLocal; ntrack.cachedInitialPosition = cachedInitialPosition; return ntrack; }
public static MonoBehaviour[] getKeysAndTracks(AMTake take) { List<MonoBehaviour> behaviours = new List<MonoBehaviour>(); if(take.trackValues != null) { foreach(AMTrack track in take.trackValues) { if(track.keys != null) { foreach(AMKey key in track.keys) behaviours.Add(key); } behaviours.Add(track); } } return behaviours.ToArray(); }
void AnimCompleted(AnimatorData dat, AMTake _take) { if(repeat && !mStopped) Invoke("DoPlay", repeatDelay); }