public override void ProcessFrame(Playable playable, FrameData info, object playerData) { dollyCart = playerData as CinemachineDollyCart; // float finalSpeed = 0f; // float finalWeight = 0f; if (!dollyCart) { return; } CacheStartState(); int inputCount = playable.GetInputCount(); //get the number of all clips on this track for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <CMDollyCartBehaviour> inputPlayable = (ScriptPlayable <CMDollyCartBehaviour>)playable.GetInput(i); CMDollyCartBehaviour input = inputPlayable.GetBehaviour(); // finalWeight += inputWeight; // Use the above variables to process each frame of this playable. // finalSpeed += input.GetSpeed() * inputWeight; if (inputWeight == 1) { // var maxTime = Mathf.Min((float)inputPlayable.GetTime(), (float)inputPlayable.GetDuration()); dollyCart.m_Speed = 0; switch (input.positionMode) { case CMDollyCartBehaviour.PositionMode.BaseOnOriginal: dollyCart.m_Position = m_DefaultPosition + (float)(inputPlayable.GetTime() * input.speed); break; case CMDollyCartBehaviour.PositionMode.CustomStart: dollyCart.m_Position = input.customStart + (float)(inputPlayable.GetTime() * input.speed); break; case CMDollyCartBehaviour.PositionMode.DeltaTime: dollyCart.m_Position += (float)(info.deltaTime * input.speed); break; } } } // Debug.Log(finalWeight); // dollyCart.m_Speed = 0; // if (finalWeight > 0) // dollyCart.m_Position = m_DefaultPosition + (float)(playable.GetTime() * finalSpeed); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Camera trackBinding = playerData as Camera; if (trackBinding == null) { return; } if (!DefaultFOWValue.HasValue) { DefaultFOWValue = trackBinding.fieldOfView; } float totalWeight = 0f; float blendedFOW = 0f; for (int i = 0, inputCount = playable.GetInputCount(); i < inputCount; i++) { ScriptPlayable <CameraDoTweenBehaviour> playableInput = (ScriptPlayable <CameraDoTweenBehaviour>)playable.GetInput(i); float weight = playable.GetInputWeight(i); CameraDoTweenBehaviour behaviour = playableInput.GetBehaviour(); blendedFOW += behaviour.Evaluate(playableInput.GetTime(), Durations[i]).FOW *weight; totalWeight += weight; } trackBinding.fieldOfView = blendedFOW + (1f - totalWeight) * DefaultFOWValue.Value; }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { TextMesh trackBinding = playerData as TextMesh; if (!trackBinding) { return; } int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (inputWeight < 1f) { continue; } ScriptPlayable <FadeAnimationBehaviour> inputPlayable = (ScriptPlayable <FadeAnimationBehaviour>)playable.GetInput(i); FadeAnimationBehaviour input = inputPlayable.GetBehaviour(); // Use the above variables to process each frame of this playable. double w = inputPlayable.GetTime() / inputPlayable.GetDuration(); Color color = trackBinding.color; color.a = input.Alpha.Evaluate((float)w); trackBinding.color = color; } }
public void PreviewEditModePose(Playable playable, SkeletonAnimation spineComponent) { if (!Application.isPlaying && (spineComponent != null)) { int inputCount = playable.GetInputCount <Playable>(); int inputPort = -1; for (int i = 0; i < inputCount; i++) { if (playable.GetInputWeight <Playable>(i) >= 1f) { inputPort = i; } } if (inputPort != -1) { ScriptPlayable <SpineAnimationStateBehaviour> input = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput <Playable>(inputPort); SpineAnimationStateBehaviour behaviour = input.GetBehaviour(); Skeleton skeleton = spineComponent.Skeleton; if ((behaviour.animationReference != null) && (spineComponent.SkeletonDataAsset.GetSkeletonData(true) != behaviour.animationReference.SkeletonDataAsset.GetSkeletonData(true))) { object[] args = new object[] { spineComponent.SkeletonDataAsset, behaviour.animationReference.SkeletonDataAsset }; Debug.LogWarningFormat("SpineAnimationStateMixerBehaviour tried to apply an animation for the wrong skeleton. Expected {0}. Was {1}", args); } Spine.Animation from = null; float time = 0f; bool loop = false; if ((inputPort != 0) && (inputCount > 1)) { ScriptPlayable <SpineAnimationStateBehaviour> playable3 = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput <Playable>((inputPort - 1)); SpineAnimationStateBehaviour behaviour2 = playable3.GetBehaviour(); from = behaviour2.animationReference.Animation; time = (float)playable3.GetTime <ScriptPlayable <SpineAnimationStateBehaviour> >(); loop = behaviour2.loop; } Spine.Animation animation = behaviour.animationReference.Animation; float num6 = (float)input.GetTime <ScriptPlayable <SpineAnimationStateBehaviour> >(); float mixDuration = behaviour.mixDuration; if (!behaviour.customDuration && (from != null)) { mixDuration = spineComponent.AnimationState.Data.GetMix(from, animation); } if (((from != null) && (mixDuration > 0f)) && (num6 < mixDuration)) { skeleton.SetToSetupPose(); float alpha = 1f - (num6 / mixDuration); alpha = (alpha <= 0.5f) ? (alpha * 2f) : 1f; from.Apply(skeleton, 0f, time, loop, null, alpha, MixPose.Setup, MixDirection.Out); animation.Apply(skeleton, 0f, num6, behaviour.loop, null, num6 / mixDuration, MixPose.Current, MixDirection.In); } else { skeleton.SetToSetupPose(); animation.PoseSkeleton(skeleton, num6, behaviour.loop); } } } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { if (cameraObj == null) { if (playerData is GameObject) { cameraObj = ((GameObject)playerData).GetComponent <Camera>(); } else if (playerData is Camera) { cameraObj = playerData as Camera; } } if (cameraObj == null) { return; } int inputCount = playable.GetInputCount(); Vector3 blendedPosition = Vector3.zero; Quaternion blendedRotation = new Quaternion(0f, 0f, 0f, 0f); for (int i = 0; i < inputCount; i++) { ScriptPlayable <CameraEffectBehaviour> playableInput = (ScriptPlayable <CameraEffectBehaviour>)playable.GetInput(i); CameraEffectBehaviour input = playableInput.GetBehaviour(); float inputWeight = playable.GetInputWeight(i); float normalisedTime = (float)(playableInput.GetTime() * input.inverseDuration); // if (input.Effect == null && input.EffectType != null) // { // Type effectype = input.EffectType; // input.Effect = (MonoBehaviour)cameraObj.gameObject.AddComponent(effectype); // } if (input.Effect != null) { if (!effectList.Contains(input.Effect)) { effectList.Add(input.Effect); } if (inputWeight > 0) { input.Effect.enabled = true; } else { input.Effect.enabled = false; } } } }
protected override void Process(Playable playable, FrameData info, TextMeshPro component, ScriptPlayable <TextMeshProMultiWordsBehaviour> input, float weight, int inputPort) { var clip = input.GetBehaviour().Clip; if (weight > maxWeight) { maxWeight = weight; time = (float)input.GetTime(); bpm = clip.bpm; words = clip.words; } }
//Happens every frame in Edit mode. //Uses transform.position of the units to approximate what they would do in Play mode with the NavMeshAgent private void ProcessEditModeFrame(Playable playable) { previousInputFinalPositions = defaultPositions; int inputCount = playable.GetInputCount(); int unitCount = trackBinding.units.Count; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <AICommandBehaviour> inputPlayable = (ScriptPlayable <AICommandBehaviour>)playable.GetInput(i); AICommandBehaviour input = inputPlayable.GetBehaviour(); //Some actionTypes have special needs switch (input.commandType) { case AICommand.CommandType.Die: case AICommand.CommandType.Stop: //Do nothing if it's a Die or Stop action continue; //Will skip to the next input clip in the for loop above case AICommand.CommandType.AttackTarget: //Force the finalPosition to the attack target in case of an Attack action if (input.targetUnit != null) { input.targetPosition = input.targetUnit.transform.position; } break; } //Create an array of final positions for the entire Platoon finalPositions = trackBinding.GetFormationPositions(input.targetPosition); if (inputWeight > 0f) { double progress = inputPlayable.GetTime() / inputPlayable.GetDuration(); newPositions = new Vector3[unitCount]; for (int j = 0; j < unitCount; j++) { newPositions[j] = Vector3.Lerp(previousInputFinalPositions[j], finalPositions[j], (float)progress); } trackBinding.SetPositions(newPositions); continue; } else { previousInputFinalPositions = finalPositions; //cached to act as initial position for the next input } } }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { MeshRenderer trackBinding = playerData as MeshRenderer; if (!trackBinding) { return; } Material material = trackBinding.sharedMaterial; if (!material) { return; } int clipsCountOnCurrentTrack = playable.GetInputCount(); //how many clips on current track //Debug.Log(clipsCountOnCurrentTrack); float currentFrameValue = 0; int nameHash = -1; float totalWeight = 0; for (int i = 0; i < clipsCountOnCurrentTrack; i++) { float inputWeight = playable.GetInputWeight(i); totalWeight += inputWeight; ScriptPlayable <MaterialFloatControlBehaviour> inputPlayable = (ScriptPlayable <MaterialFloatControlBehaviour>)playable.GetInput(i); MaterialFloatControlBehaviour input = inputPlayable.GetBehaviour(); if (string.IsNullOrEmpty(input.attributeName)) { continue; } nameHash = Shader.PropertyToID(input.attributeName); float normalisedTime = (float)(inputPlayable.GetTime() / inputPlayable.GetDuration()); float tweenProgress = input.currentCurve.Evaluate(normalisedTime); currentFrameValue += ((1 - tweenProgress) * input.initialValue + tweenProgress * input.targetValue) * inputWeight; } if (nameHash != -1) { float originalValue = material.GetFloat(nameHash); material.SetFloat(nameHash, originalValue * (1 - totalWeight) + currentFrameValue); } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); if (MainCamera == null) { return; } int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); Texture2D overlayTexture = null; for (int i = 0; i < playable.GetInputCount(); ++i) { float weight = playable.GetInputWeight(i); ScriptPlayable <CameraFadePlayableBehaviour> clip = (ScriptPlayable <CameraFadePlayableBehaviour>)playable.GetInput(i); CameraFadePlayableBehaviour shot = clip.GetBehaviour(); if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0.0001f) { clipA = clipB; clipB.weight = weight; clipB.localTime = clip.GetTime(); clipB.duration = clip.GetDuration(); clipB.overlayTexture = shot.overlayTexture; if (++activeInputs == 2) { break; } } } overlayTexture = (clipB.overlayTexture != null) ? clipB.overlayTexture : clipA.overlayTexture; float _weight = clipB.weight; MainCamera.SetTimelineFadeOverride(overlayTexture, _weight); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { m_TrackBinding = playerData as UITweener; if (m_TrackBinding == null) { return; } if (!m_FirstFrameHappened) { m_FirstFrameHappened = true; } int inputCount = playable.GetInputCount(); float totalWeight = 0f; int currentInputs = 0; blendedFactor = 0; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <TweenerBehaviour> inputPlayable = (ScriptPlayable <TweenerBehaviour>)playable.GetInput(i); TweenerBehaviour input = inputPlayable.GetBehaviour(); float normalisedTime = (float)(inputPlayable.GetTime() * input.inverseDuration); //Debug.Log(inputWeight); blendedFactor += normalisedTime;// * inputWeight; totalWeight += inputWeight; if (!Mathf.Approximately(inputWeight, 0f)) { currentInputs++; } } blendedFactor += defaultFactor * (1f - totalWeight); m_TrackBinding.ProgressNormalized = blendedFactor; m_TrackBinding.Animate(); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { if (m_GameObject == null) { m_GameObject = (GameObject)playerData; } ; if (m_GameObject == null) { return; } int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float _weight = playable.GetInputWeight(i); ScriptPlayable <SkillShotPlayable> _shotPlayable = (ScriptPlayable <SkillShotPlayable>)playable.GetInput(i); SkillShotPlayable _shotbehaviour = _shotPlayable.GetBehaviour(); float normalizedTime = (float)(_shotPlayable.GetTime() / _shotPlayable.GetDuration()); } }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { LocalTimeComponet trackBinding = playerData as LocalTimeComponet; if (!trackBinding) { return; } int inputCount = playable.GetInputCount(); var maxWeight = 0f; var time = 0f; var duration = 0f; for (int i = 0; i < inputCount; i++) { var weight = playable.GetInputWeight(i); if (Mathf.Approximately(weight, 0)) { continue; } ScriptPlayable <LocalTimeBehaviour> inputPlayable = (ScriptPlayable <LocalTimeBehaviour>)playable.GetInput(i); LocalTimeBehaviour input = inputPlayable.GetBehaviour(); // Use the above variables to process each frame of this playable. // NOTE: gam0022 単純なブレンドが難しい値は最もウェイトが高いクリップを採用 if (weight > maxWeight) { time = (float)inputPlayable.GetTime(); duration = (float)inputPlayable.GetDuration(); maxWeight = weight; } } trackBinding.ApplyTime(time, duration); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { if (particleSystem == null) { if (playerData is GameObject) { ParticleRoot = ((GameObject)playerData).transform; } else if (playerData is ParticleSystem) { ParticleRoot = ((ParticleSystem)playerData).gameObject.transform; } } if (ParticleSys == null) { return; } int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { ScriptPlayable <ParticleSystemControlBehaviour> playableInput = (ScriptPlayable <ParticleSystemControlBehaviour>)playable.GetInput(i); ParticleSystemControlBehaviour input = playableInput.GetBehaviour(); float inputWeight = playable.GetInputWeight(i); float normalisedTime = (float)(playableInput.GetTime() * input.inverseDuration); if (ParticleSys != null) { for (int j = 0; j < ParticleSys.Length; j++) { ParticleSys[j].Simulate(normalisedTime, true, true); } } } }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { DataListener trackBinding = playerData as DataListener; if (trackBinding == null) { Debug.Log("Track without Trackbinding"); return; } int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <RecordingBehaviour> inputPlayable = (ScriptPlayable <RecordingBehaviour>)playable.GetInput(i); RecordingBehaviour input = inputPlayable.GetBehaviour(); // Use the above variables to process each frame of this playable. if (inputWeight > 0 && input.recording != null) { float timeS = (float)inputPlayable.GetTime(); float duration = input.recording.duration; if (duration > 0) { timeS = timeS % duration; //loop } IDataFrame frame = input.recording.GetDataFrame(timeS); if (frame != null) { trackBinding.ProcessData(frame); } } } }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { m_TrackBinding = playerData as MediaPlayer; if (m_TrackBinding == null) { return; } if (!m_FirstFrameHappened) { m_DefaultStartTime = 0; //m_TrackBinding.Control.GetCurrentTimeMs(); m_FirstFrameHappened = true; } int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { // use for blending between clips //float inputWeight = playable.GetInputWeight(i); ScriptPlayable <AVProVideoPlayableBehaviour> playableInput = (ScriptPlayable <AVProVideoPlayableBehaviour>)playable.GetInput(i); //AVProVideoPlayableBehaviour input = playableInput.GetBehaviour(); // Use the above variables to process each frame of this playable. //normalizedTime = (float)(playableInput.GetTime() * input.inverseDuration); normalizedTime = ((float)playableInput.GetTime()) * 1000f; if (m_TrackBinding.Control != null) { m_TrackBinding.Control.Seek(normalizedTime); } } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Text trackBinding = playerData as Text; if (!trackBinding) { return; } int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <ScrollingTextBehaviour> inputPlayable = (ScriptPlayable <ScrollingTextBehaviour>)playable.GetInput(i); ScrollingTextBehaviour input = inputPlayable.GetBehaviour(); if (Mathf.Approximately(inputWeight, 1f)) { string message = input.GetMessage((float)inputPlayable.GetTime()); trackBinding.text = message; } } }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { ScriptPlayable <TimelineAnimatorBehaviour> inputPlayable = (ScriptPlayable <TimelineAnimatorBehaviour>)playable.GetInput(i); TimelineAnimatorBehaviour input = inputPlayable.GetBehaviour(); if (!input.target || !input.target.activeSelf) { continue; } if (inputPlayable.GetPlayState() != PlayState.Playing) { continue; } // Use the above variables to process each frame of this playable. float timeNormalized = (float)(inputPlayable.GetTime() / input.duration); Animate(input, timeNormalized); } }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { int inputCount = playable.GetInputCount(); bool densityFieldCleared = false; #if !UNITY_EDITOR //check the current time of timeline /* PlayableDirector director = DFMRef_.gameObject.GetComponent<PlayableDirector>(); * int frame = -1; * * if (director != null) * { #if UNITY_PS4 * int frameRate = 60; #else * int frameRate = 90; #endif * //frame = (int)(director.time * frameRate); * } * * if (lastMixerFrame == frame) * return; * * lastMixerFrame = frame;*/ #endif for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (inputWeight > 0.0f) { ScriptPlayable <PointCloudBehaviour> inputPlayable = (ScriptPlayable <PointCloudBehaviour>)playable.GetInput(i); float time = (float)inputPlayable.GetTime(); PointCloudBehaviour input = inputPlayable.GetBehaviour(); #if UNITY_EDITOR if (input.PointCloudDirectory != input.PointCloudDirectoryInternal) { input.SetFrameFileList(); } #endif if (input.frameFiles.Length == 0) { continue; } if (!densityFieldCleared) { ClearDensityField(DFMRef_.Resolution); densityFieldCleared = true; } int newFrame = (int)(time * 30.0f); float fraction = (time * 30.0f) - (int)(time * 30.0f); Shader.SetGlobalFloat("_ArtSpaces_frame_fraction", fraction); bool forceReload = false; if (newFrame - input.frameNo != 0 && newFrame - input.frameNo != 1) { forceReload = true; #if UNITY_EDITOR UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); #endif } input.frameNo = newFrame; if (input.frameNo >= input.frameFiles.Length) { input.frameNo = input.frameFiles.Length - 1; } int nextFrameNo = newFrame + 1; if (nextFrameNo >= input.frameFiles.Length) { nextFrameNo = input.frameFiles.Length - 1; } SetParticleClipFrameName(input.GetHashCode(), input.frameFiles[input.frameNo], input.frameFiles[nextFrameNo], fraction, inputWeight * input.influence, DFMRef_.Resolution, input.scale.x, input.scale.y, input.scale.z, input.translate.x, input.translate.y, input.translate.z, forceReload); //Debug.Log("Current frame: " + input.frameNo + " Next frame: " + nextFrameNo + " fraction: " + fraction); } } DFMRef_.numPointCloudParticles_ = GenerateDensityField(GetHashCode()); if (DFMRef_.numPointCloudParticles_ >= 0) { DFMRef_.particleBuffer_.SetData(particles_, 0, 0, DFMRef_.numPointCloudParticles_); } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Transform trackBinding = playerData as Transform; if (trackBinding == null) { return; } Vector3 defaultPosition = trackBinding.position; Quaternion defaultRotation = trackBinding.rotation; int inputCount = playable.GetInputCount(); float positionTotalWeight = 0f; float rotationTotalWeight = 0f; Vector3 blendedPosition = Vector3.zero; Quaternion blendedRotation = new Quaternion(0f, 0f, 0f, 0f); for (int i = 0; i < inputCount; i++) { ScriptPlayable <TransformTweenBehaviour> playableInput = (ScriptPlayable <TransformTweenBehaviour>)playable.GetInput(i); TransformTweenBehaviour input = playableInput.GetBehaviour(); if (input.endLocation == null) { continue; } float inputWeight = playable.GetInputWeight(i); if (!m_FirstFrameHappened && !input.startLocation) { input.startingPosition = defaultPosition; input.startingRotation = defaultRotation; } float normalisedTime = (float)(playableInput.GetTime() / playableInput.GetDuration()); float tweenProgress = input.EvaluateCurrentCurve(normalisedTime); if (input.tweenPosition) { positionTotalWeight += inputWeight; blendedPosition += Vector3.Lerp(input.startingPosition, input.endLocation.position, tweenProgress) * inputWeight; } if (input.tweenRotation) { rotationTotalWeight += inputWeight; Quaternion desiredRotation = Quaternion.Lerp(input.startingRotation, input.endLocation.rotation, tweenProgress); desiredRotation = NormalizeQuaternion(desiredRotation); if (Quaternion.Dot(blendedRotation, desiredRotation) < 0f) { desiredRotation = ScaleQuaternion(desiredRotation, -1f); } desiredRotation = ScaleQuaternion(desiredRotation, inputWeight); blendedRotation = AddQuaternions(blendedRotation, desiredRotation); } } blendedPosition += defaultPosition * (1f - positionTotalWeight); Quaternion weightedDefaultRotation = ScaleQuaternion(defaultRotation, 1f - rotationTotalWeight); blendedRotation = AddQuaternions(blendedRotation, weightedDefaultRotation); trackBinding.position = blendedPosition; trackBinding.rotation = blendedRotation; m_FirstFrameHappened = true; }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { if (animator == null) { if (playerData is GameObject) { animator = ((GameObject)playerData).GetComponent <Animator>(); } else if (playerData is Animator) { animator = playerData as Animator; } } if (animator == null) { return; } Vector3 defaultPosition = animator.gameObject.transform.position; Quaternion defaultRotation = animator.gameObject.transform.rotation; int inputCount = playable.GetInputCount(); if (clips.Count <= 0) { mixer = AnimationPlayableUtilities.PlayMixer(animator, inputCount, out playableGraph); } Vector3 blendedPosition = Vector3.zero; Quaternion blendedRotation = new Quaternion(0f, 0f, 0f, 0f); RuntimeAnimatorController controller = animator ? animator.runtimeAnimatorController as RuntimeAnimatorController : null; for (int i = 0; i < inputCount; i++) { ScriptPlayable <AnimatorControlBehavior> playableInput = (ScriptPlayable <AnimatorControlBehavior>)playable.GetInput(i); AnimatorControlBehavior input = playableInput.GetBehaviour(); float inputWeight = playable.GetInputWeight(i); float normalisedTime = (float)(playableInput.GetTime() * input.inverseDuration); if (input.Clip == null || input.Clip.name != input.ClipName) { for (int j = 0; j < controller.animationClips.Length; j++) { AnimationClip clip = controller.animationClips[j]; if (clip.name == input.ClipName) { input.Clip = clip; } } } if (input.Clip) { if (clips.Count <= i) { AnimationClipPlayable clipplay = AnimationClipPlayable.Create(playableGraph, input.Clip); playableGraph.Connect(clipplay, 0, mixer, i); clips.Add(clipplay); } mixer.SetInputWeight(i, inputWeight); clips[i].SetTime((double)normalisedTime * input.Clip.length); clips[i].SetSpeed(0); } } if (!Application.isPlaying) { playableGraph.Evaluate(); } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); if (MainCamera == null) { return; } int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); float shakeIntensity = 0f; for (int i = 0; i < playable.GetInputCount(); ++i) { float weight = playable.GetInputWeight(i); ScriptPlayable <MainCameraPlayableBehaviour> clip = (ScriptPlayable <MainCameraPlayableBehaviour>)playable.GetInput(i); MainCameraPlayableBehaviour shot = clip.GetBehaviour(); if (shot != null) { callCustomEvents = shot.callCustomEvents; } if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0.0001f) { clipA = clipB; clipB.camera = shot.gameCamera; clipB.weight = weight; clipB.localTime = clip.GetTime(); clipB.duration = clip.GetDuration(); clipB.shakeIntensity = shot.shakeIntensity; if (++activeInputs == 2) { break; } } } // Figure out which clip is incoming bool incomingIsB = clipB.weight >= 1 || clipB.localTime < clipB.duration / 2; if (activeInputs == 2) { if (clipB.localTime > clipA.localTime) { incomingIsB = true; } else if (clipB.localTime < clipA.localTime) { incomingIsB = false; } else { incomingIsB = clipB.duration >= clipA.duration; } } shakeIntensity = incomingIsB ? clipB.shakeIntensity : clipA.shakeIntensity; _Camera cameraA = incomingIsB ? clipA.camera : clipB.camera; _Camera cameraB = incomingIsB ? clipB.camera : clipA.camera; float camWeightB = incomingIsB ? clipB.weight : 1 - clipB.weight; if (cameraB == null) { cameraB = cameraA; cameraA = null; camWeightB = 1f - camWeightB; } if (incomingIsB) { shakeIntensity = (clipA.shakeIntensity * (1f - camWeightB)) + (clipB.shakeIntensity * camWeightB); } else { shakeIntensity = (clipB.shakeIntensity * (1f - camWeightB)) + (clipA.shakeIntensity * camWeightB); } MainCamera.SetTimelineOverride(cameraA, cameraB, camWeightB, shakeIntensity); if (callCustomEvents) { _Camera thisFrameCamera = (incomingIsB) ? cameraB : cameraA; if (thisFrameCamera != lastFrameCamera) { KickStarter.eventManager.Call_OnSwitchCamera(lastFrameCamera, thisFrameCamera, 0f); lastFrameCamera = thisFrameCamera; } } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Transform targetTransform = playerData as Transform; if (targetTransform == null) { return; } Vector3 originalPosition = targetTransform.position; Quaternion originalRotation = targetTransform.rotation; Vector3 originalScale = targetTransform.localScale; Vector3 originalEulerAngles = targetTransform.localEulerAngles; Vector3 outputPosition = Vector3.zero; Quaternion outputRotation = new Quaternion(0f, 0f, 0f, 0f); Vector3 outputScale = Vector3.zero; Vector3 outputEulerAngles = Vector3.zero; float positionWeight = 0f; float rotationWeight = 0f; float scaleWeight = 0f; int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { ScriptPlayable <EZTransformTweenBehaviour> inputPlayable = (ScriptPlayable <EZTransformTweenBehaviour>)playable.GetInput(i); EZTransformTweenBehaviour inputBehaviour = inputPlayable.GetBehaviour(); if (inputBehaviour.endPoint == null) { continue; } float inputWeight = playable.GetInputWeight(i); if (!started && !inputBehaviour.startPoint) { inputBehaviour.startPosition = originalPosition; inputBehaviour.startRotation = originalRotation; inputBehaviour.startScale = originalScale; } float normalizedTime = (float)(inputPlayable.GetTime() / inputPlayable.GetDuration()); float process = inputBehaviour.curve.Evaluate(normalizedTime); if (inputBehaviour.tweenPosition) { positionWeight += inputWeight; outputPosition += Vector3.Lerp(inputBehaviour.startPosition, inputBehaviour.endPoint.position, process) * inputWeight; } if (inputBehaviour.tweenRotation) { rotationWeight += inputWeight; Quaternion targetRotation = Quaternion.Lerp(inputBehaviour.startRotation, inputBehaviour.endPoint.rotation, process); #if UNITY_2018_1 targetRotation = targetRotation.Normalize(); #else targetRotation.Normalize(); #endif if (Quaternion.Dot(outputRotation, targetRotation) < 0f) { targetRotation = targetRotation.Scale(-1f); } targetRotation = targetRotation.Scale(inputWeight); outputRotation = outputRotation.Add(targetRotation); outputEulerAngles += Vector3.Lerp(inputBehaviour.startEulerAngles, inputBehaviour.endEulerAngles, process) * inputWeight; } if (inputBehaviour.tweenScale) { scaleWeight += inputWeight; outputScale += Vector3.Lerp(inputBehaviour.startScale, inputBehaviour.endPoint.localScale, process) * inputWeight; } } targetTransform.position = outputPosition + originalPosition * (1f - positionWeight); if (eulerRotation) { targetTransform.localEulerAngles = outputEulerAngles + originalEulerAngles * (1f - rotationWeight); } else { targetTransform.rotation = outputRotation.Add(originalRotation.Scale(1f - rotationWeight)); } targetTransform.localScale = outputScale + originalScale * (1f - scaleWeight); started = true; }
public void PreviewEditModePose(Playable playable, SkeletonAnimation trackBinding) { if (Application.isPlaying) { return; } if (trackBinding == null) { return; } int inputCount = playable.GetInputCount(); int lastOneWeight = -1; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (inputWeight >= 1) { lastOneWeight = i; } } if (lastOneWeight != -1) { ScriptPlayable <SpineAnimationStateBehaviour> inputPlayableClip = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastOneWeight); SpineAnimationStateBehaviour clipBehaviourData = inputPlayableClip.GetBehaviour(); var skeleton = trackBinding.Skeleton; var skeletonData = trackBinding.Skeleton.Data; ScriptPlayable <SpineAnimationStateBehaviour> fromClip; Animation fromAnimation = null; float fromClipTime = 0; bool fromClipLoop = false; if (lastOneWeight != 0 && inputCount > 1) { fromClip = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastOneWeight - 1); var fromClipData = fromClip.GetBehaviour(); fromAnimation = skeletonData.FindAnimation(fromClipData.animationName); fromClipTime = (float)fromClip.GetTime(); fromClipLoop = fromClipData.loop; } Animation toAnimation = skeletonData.FindAnimation(clipBehaviourData.animationName); float toClipTime = (float)inputPlayableClip.GetTime(); float mixDuration = clipBehaviourData.mixDuration; if (!clipBehaviourData.customDuration && fromAnimation != null) { mixDuration = trackBinding.AnimationState.Data.GetMix(fromAnimation, toAnimation); } // Approximate what AnimationState might do at runtime. if (fromAnimation != null && mixDuration > 0 && toClipTime < mixDuration) { skeleton.SetToSetupPose(); float fauxFromAlpha = (1f - toClipTime / mixDuration); fauxFromAlpha = fauxFromAlpha > 0.5f ? 1f : fauxFromAlpha * 2f; // fake value, but reduce dip. fromAnimation.Apply(skeleton, 0, fromClipTime, fromClipLoop, null, fauxFromAlpha, MixPose.Setup, MixDirection.Out); //fromAnimation.PoseSkeleton(skeleton, fromClipTime, fromClipLoop); toAnimation.Apply(skeleton, 0, toClipTime, clipBehaviourData.loop, null, toClipTime / mixDuration, MixPose.Current, MixDirection.In); } else { skeleton.SetToSetupPose(); toAnimation.PoseSkeleton(skeleton, toClipTime, clipBehaviourData.loop); } } // Do nothing outside of the first clip and the last clip. }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { var skeletonAnimation = playerData as SkeletonAnimation; var skeletonGraphic = playerData as SkeletonGraphic; animationStateComponent = playerData as IAnimationStateComponent; var skeletonComponent = playerData as ISkeletonComponent; if (animationStateComponent.IsNullOrDestroyed() || skeletonComponent == null) { return; } var skeleton = skeletonComponent.Skeleton; var state = animationStateComponent.AnimationState; if (!Application.isPlaying) { #if SPINE_EDITMODEPOSE PreviewEditModePose(playable, skeletonComponent, animationStateComponent, skeletonAnimation, skeletonGraphic); #endif return; } int inputCount = playable.GetInputCount(); // Ensure correct buffer size. if (this.lastInputWeights == null || this.lastInputWeights.Length < inputCount) { this.lastInputWeights = new float[inputCount]; for (int i = 0; i < inputCount; i++) { this.lastInputWeights[i] = default(float); } } var lastInputWeights = this.lastInputWeights; int numStartingClips = 0; bool anyClipPlaying = false; // Check all clips. If a clip that was weight 0 turned into weight 1, call SetAnimation. for (int i = 0; i < inputCount; i++) { float lastInputWeight = lastInputWeights[i]; float inputWeight = playable.GetInputWeight(i); bool clipStarted = lastInputWeight == 0 && inputWeight > 0; if (inputWeight > 0) { anyClipPlaying = true; } lastInputWeights[i] = inputWeight; if (clipStarted && numStartingClips < 2) { ScriptPlayable <SpineAnimationStateBehaviour> clipPlayable = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(i); startingClips[numStartingClips++] = clipPlayable; } } // unfortunately order of clips can be wrong when two start at the same time, we have to sort clips if (numStartingClips == 2) { ScriptPlayable <SpineAnimationStateBehaviour> clipPlayable0 = startingClips[0]; ScriptPlayable <SpineAnimationStateBehaviour> clipPlayable1 = startingClips[1]; if (clipPlayable0.GetDuration() > clipPlayable1.GetDuration()) // swap, clip 0 ends after clip 1 { startingClips[0] = clipPlayable1; startingClips[1] = clipPlayable0; } } for (int j = 0; j < numStartingClips; ++j) { ScriptPlayable <SpineAnimationStateBehaviour> clipPlayable = startingClips[j]; SpineAnimationStateBehaviour clipData = clipPlayable.GetBehaviour(); pauseWithDirector = !clipData.dontPauseWithDirector; endAtClipEnd = !clipData.dontEndWithClip; endMixOutDuration = clipData.endMixOutDuration; if (clipData.animationReference == null) { float mixDuration = clipData.customDuration ? GetCustomMixDuration(clipData) : state.Data.DefaultMix; state.SetEmptyAnimation(trackIndex, mixDuration); } else { if (clipData.animationReference.Animation != null) { TrackEntry currentEntry = state.GetCurrent(trackIndex); Spine.TrackEntry trackEntry; float customMixDuration = clipData.customDuration ? GetCustomMixDuration(clipData) : 0.0f; if (currentEntry == null && customMixDuration > 0) { state.SetEmptyAnimation(trackIndex, 0); // ease in requires empty animation trackEntry = state.AddAnimation(trackIndex, clipData.animationReference.Animation, clipData.loop, 0); } else { trackEntry = state.SetAnimation(trackIndex, clipData.animationReference.Animation, clipData.loop); } trackEntry.EventThreshold = clipData.eventThreshold; trackEntry.DrawOrderThreshold = clipData.drawOrderThreshold; trackEntry.TrackTime = (float)clipPlayable.GetTime() * (float)clipPlayable.GetSpeed(); trackEntry.TimeScale = (float)clipPlayable.GetSpeed(); trackEntry.AttachmentThreshold = clipData.attachmentThreshold; trackEntry.HoldPrevious = clipData.holdPrevious; if (clipData.customDuration) { trackEntry.MixDuration = customMixDuration; } timelineStartedTrackEntry = trackEntry; } //else Debug.LogWarningFormat("Animation named '{0}' not found", clipData.animationName); } // Ensure that the first frame ends with an updated mesh. if (skeletonAnimation) { skeletonAnimation.Update(0); skeletonAnimation.LateUpdate(); } else if (skeletonGraphic) { skeletonGraphic.Update(0); skeletonGraphic.LateUpdate(); } } startingClips[0] = startingClips[1] = ScriptPlayable <SpineAnimationStateBehaviour> .Null; if (lastAnyClipPlaying && !anyClipPlaying) { HandleClipEnd(); } this.lastAnyClipPlaying = anyClipPlaying; }
public void PreviewEditModePose(Playable playable, ISkeletonComponent skeletonComponent, IAnimationStateComponent animationStateComponent, SkeletonAnimation skeletonAnimation, SkeletonGraphic skeletonGraphic) { if (Application.isPlaying) { return; } if (animationStateComponent.IsNullOrDestroyed() || skeletonComponent == null) { return; } int inputCount = playable.GetInputCount(); int lastNonZeroWeightTrack = -1; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (inputWeight > 0) { lastNonZeroWeightTrack = i; } } if (lastNonZeroWeightTrack != -1) { ScriptPlayable <SpineAnimationStateBehaviour> inputPlayableClip = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastNonZeroWeightTrack); SpineAnimationStateBehaviour clipData = inputPlayableClip.GetBehaviour(); var skeleton = skeletonComponent.Skeleton; bool skeletonDataMismatch = clipData.animationReference != null && clipData.animationReference.SkeletonDataAsset && skeletonComponent.SkeletonDataAsset.GetSkeletonData(true) != clipData.animationReference.SkeletonDataAsset.GetSkeletonData(true); if (skeletonDataMismatch) { Debug.LogWarningFormat("SpineAnimationStateMixerBehaviour tried to apply an animation for the wrong skeleton. Expected {0}. Was {1}", skeletonComponent.SkeletonDataAsset, clipData.animationReference.SkeletonDataAsset); } // Getting the from-animation here because it's required to get the mix information from AnimationStateData. Animation fromAnimation = null; float fromClipTime = 0; bool fromClipLoop = false; if (lastNonZeroWeightTrack != 0 && inputCount > 1) { var fromClip = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastNonZeroWeightTrack - 1); var fromClipData = fromClip.GetBehaviour(); fromAnimation = fromClipData.animationReference != null ? fromClipData.animationReference.Animation : null; fromClipTime = (float)fromClip.GetTime() * (float)fromClip.GetSpeed(); fromClipLoop = fromClipData.loop; } Animation toAnimation = clipData.animationReference != null ? clipData.animationReference.Animation : null; float toClipTime = (float)inputPlayableClip.GetTime() * (float)inputPlayableClip.GetSpeed(); float mixDuration = clipData.mixDuration; if (!clipData.customDuration && fromAnimation != null && toAnimation != null) { mixDuration = animationStateComponent.AnimationState.Data.GetMix(fromAnimation, toAnimation); } if (trackIndex == 0) { skeleton.SetToSetupPose(); } // Approximate what AnimationState might do at runtime. if (fromAnimation != null && mixDuration > 0 && toClipTime < mixDuration) { dummyAnimationState = dummyAnimationState ?? new AnimationState(skeletonComponent.SkeletonDataAsset.GetAnimationStateData()); var toEntry = dummyAnimationState.GetCurrent(0); var fromEntry = toEntry != null ? toEntry.MixingFrom : null; bool isAnimationTransitionMatch = (toEntry != null && toEntry.Animation == toAnimation && fromEntry != null && fromEntry.Animation == fromAnimation); if (!isAnimationTransitionMatch) { dummyAnimationState.ClearTracks(); fromEntry = dummyAnimationState.SetAnimation(0, fromAnimation, fromClipLoop); fromEntry.AllowImmediateQueue(); if (toAnimation != null) { toEntry = dummyAnimationState.SetAnimation(0, toAnimation, clipData.loop); toEntry.HoldPrevious = clipData.holdPrevious; } } // Update track times. fromEntry.TrackTime = fromClipTime; if (toEntry != null) { toEntry.TrackTime = toClipTime; toEntry.MixTime = toClipTime; } // Apply Pose dummyAnimationState.Update(0); dummyAnimationState.Apply(skeleton); } else { if (toAnimation != null) { toAnimation.Apply(skeleton, 0, toClipTime, clipData.loop, null, 1f, MixBlend.Setup, MixDirection.In); } } skeleton.UpdateWorldTransform(); if (skeletonAnimation) { skeletonAnimation.LateUpdate(); } else if (skeletonGraphic) { skeletonGraphic.LateUpdate(); } } // Do nothing outside of the first clip and the last clip. }
public void PreviewEditModePose(Playable playable, SkeletonAnimation spineComponent) { if (Application.isPlaying) { return; } if (spineComponent == null) { return; } int inputCount = playable.GetInputCount(); int lastOneWeight = -1; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (inputWeight >= 1) { lastOneWeight = i; } } if (lastOneWeight != -1) { ScriptPlayable <SpineAnimationStateBehaviour> inputPlayableClip = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastOneWeight); SpineAnimationStateBehaviour clipData = inputPlayableClip.GetBehaviour(); var skeleton = spineComponent.Skeleton; bool skeletonDataMismatch = clipData.animationReference != null && spineComponent.SkeletonDataAsset.GetSkeletonData(true) != clipData.animationReference.SkeletonDataAsset.GetSkeletonData(true); if (skeletonDataMismatch) { Debug.LogWarningFormat("SpineAnimationStateMixerBehaviour tried to apply an animation for the wrong skeleton. Expected {0}. Was {1}", spineComponent.SkeletonDataAsset, clipData.animationReference.SkeletonDataAsset); } // Getting the from-animation here because it's required to get the mix information from AnimationStateData. Animation fromAnimation = null; float fromClipTime = 0; bool fromClipLoop = false; if (lastOneWeight != 0 && inputCount > 1) { var fromClip = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastOneWeight - 1); var fromClipData = fromClip.GetBehaviour(); fromAnimation = fromClipData.animationReference.Animation; fromClipTime = (float)fromClip.GetTime(); fromClipLoop = fromClipData.loop; } Animation toAnimation = clipData.animationReference.Animation; float toClipTime = (float)inputPlayableClip.GetTime(); float mixDuration = clipData.mixDuration; if (!clipData.customDuration && fromAnimation != null) { mixDuration = spineComponent.AnimationState.Data.GetMix(fromAnimation, toAnimation); } // Approximate what AnimationState might do at runtime. if (fromAnimation != null && mixDuration > 0 && toClipTime < mixDuration) { skeleton.SetToSetupPose(); float fauxFromAlpha = (1f - toClipTime / mixDuration); fauxFromAlpha = fauxFromAlpha > 0.5f ? 1f : fauxFromAlpha * 2f; // fake value, but reduce dip. fromAnimation.Apply(skeleton, 0, fromClipTime, fromClipLoop, null, fauxFromAlpha, MixPose.Setup, MixDirection.Out); //fromAnimation.PoseSkeleton(skeleton, fromClipTime, fromClipLoop); toAnimation.Apply(skeleton, 0, toClipTime, clipData.loop, null, toClipTime / mixDuration, MixPose.Current, MixDirection.In); } else { skeleton.SetToSetupPose(); toAnimation.PoseSkeleton(skeleton, toClipTime, clipData.loop); } } // Do nothing outside of the first clip and the last clip. }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Transform targetTransform = playerData as Transform; if (targetTransform == null) { return; } Vector3 originalPosition = targetTransform.position; Quaternion originalRotation = targetTransform.rotation; Vector3 originalScale = targetTransform.localScale; Vector3 outputPosition = Vector3.zero; Quaternion outputRotation = new Quaternion(0f, 0f, 0f, 0f); Vector3 outputScale = Vector3.zero; float positionWeight = 0f; float rotationWeight = 0f; float scaleWeight = 0f; int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { ScriptPlayable <EZTransformTweenBehaviour> inputPlayable = (ScriptPlayable <EZTransformTweenBehaviour>)playable.GetInput(i); EZTransformTweenBehaviour inputBehaviour = inputPlayable.GetBehaviour(); float inputWeight = playable.GetInputWeight(i); if (!started && !inputBehaviour.startPoint) { inputBehaviour.startPosition = originalPosition; inputBehaviour.startRotation = originalRotation; inputBehaviour.startScale = originalScale; } float normalizedTime = (float)(inputPlayable.GetTime() / inputPlayable.GetDuration()); float process = inputBehaviour.curve.Evaluate(normalizedTime); if (inputBehaviour.tweenPosition && inputBehaviour.endPoint != null) { positionWeight += inputWeight; outputPosition += Vector3.Lerp(inputBehaviour.startPosition, inputBehaviour.endPoint.position, process) * inputWeight; } if (inputBehaviour.tweenRotation) { if (inputBehaviour.endPoint != null) { rotationWeight += inputWeight; Quaternion targetRotation = Quaternion.Lerp(inputBehaviour.startRotation, inputBehaviour.endPoint.rotation, process); outputRotation = QuaternionExt.Cumulate(outputRotation, targetRotation.Scale(inputWeight)); } } if (inputBehaviour.tweenScale && inputBehaviour.endPoint != null) { scaleWeight += inputWeight; outputScale += Vector3.Lerp(inputBehaviour.startScale, inputBehaviour.endPoint.localScale, process) * inputWeight; } } if (positionWeight > 1e-5) { targetTransform.position = outputPosition + originalPosition * (1f - positionWeight); } if (rotationWeight > 1e-5) { targetTransform.rotation = QuaternionExt.Cumulate(outputRotation, originalRotation.Scale(1f - rotationWeight)); } if (scaleWeight > 1e-5) { targetTransform.localScale = outputScale + originalScale * (1f - scaleWeight); } started = true; }
public void PreviewEditModePose(Playable playable, SkeletonAnimation spineComponent) { if (Application.isPlaying) { return; } if (spineComponent == null) { return; } int inputCount = playable.GetInputCount(); int lastOneWeight = -1; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (inputWeight >= 1) { lastOneWeight = i; } } if (lastOneWeight != -1) { ScriptPlayable <SpineAnimationStateBehaviour> inputPlayableClip = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastOneWeight); SpineAnimationStateBehaviour clipData = inputPlayableClip.GetBehaviour(); var skeleton = spineComponent.Skeleton; bool skeletonDataMismatch = clipData.animationReference != null && spineComponent.SkeletonDataAsset.GetSkeletonData(true) != clipData.animationReference.SkeletonDataAsset.GetSkeletonData(true); if (skeletonDataMismatch) { Debug.LogWarningFormat("SpineAnimationStateMixerBehaviour tried to apply an animation for the wrong skeleton. Expected {0}. Was {1}", spineComponent.SkeletonDataAsset, clipData.animationReference.SkeletonDataAsset); } // Getting the from-animation here because it's required to get the mix information from AnimationStateData. Animation fromAnimation = null; float fromClipTime = 0; bool fromClipLoop = false; if (lastOneWeight != 0 && inputCount > 1) { var fromClip = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastOneWeight - 1); var fromClipData = fromClip.GetBehaviour(); fromAnimation = fromClipData.animationReference != null ? fromClipData.animationReference.Animation : null; fromClipTime = (float)fromClip.GetTime(); fromClipLoop = fromClipData.loop; } Animation toAnimation = clipData.animationReference != null ? clipData.animationReference.Animation : null; float toClipTime = (float)inputPlayableClip.GetTime(); float mixDuration = clipData.mixDuration; if (!clipData.customDuration && fromAnimation != null && toAnimation != null) { mixDuration = spineComponent.AnimationState.Data.GetMix(fromAnimation, toAnimation); } // Approximate what AnimationState might do at runtime. if (fromAnimation != null && mixDuration > 0 && toClipTime < mixDuration) { dummyAnimationState = dummyAnimationState ?? new AnimationState(spineComponent.skeletonDataAsset.GetAnimationStateData()); var toTrack = dummyAnimationState.GetCurrent(0); var fromTrack = toTrack != null ? toTrack.mixingFrom : null; bool isAnimationTransitionMatch = (toTrack != null && toTrack.animation == toAnimation && fromTrack != null && fromTrack.animation == fromAnimation); if (!isAnimationTransitionMatch) { dummyAnimationState.ClearTracks(); fromTrack = dummyAnimationState.SetAnimation(0, fromAnimation, fromClipLoop); fromTrack.AllowImmediateQueue(); if (toAnimation != null) { toTrack = dummyAnimationState.SetAnimation(0, toAnimation, clipData.loop); } } // Update track times. fromTrack.trackTime = fromClipTime; if (toTrack != null) { toTrack.trackTime = toClipTime; toTrack.mixTime = toClipTime; } // Apply Pose skeleton.SetToSetupPose(); dummyAnimationState.Update(0); dummyAnimationState.Apply(skeleton); } else { skeleton.SetToSetupPose(); if (toAnimation != null) { toAnimation.PoseSkeleton(skeleton, toClipTime, clipData.loop); } } } // Do nothing outside of the first clip and the last clip. }
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame(Playable playable, FrameData info, object playerData) { var skeletonAnimation = playerData as SkeletonAnimation; var skeletonGraphic = playerData as SkeletonGraphic; var animationStateComponent = playerData as IAnimationStateComponent; var skeletonComponent = playerData as ISkeletonComponent; if (animationStateComponent == null || skeletonComponent == null) { return; } var skeleton = skeletonComponent.Skeleton; var state = animationStateComponent.AnimationState; if (!Application.isPlaying) { #if SPINE_EDITMODEPOSE PreviewEditModePose(playable, skeletonComponent, animationStateComponent, skeletonAnimation, skeletonGraphic); #endif return; } int inputCount = playable.GetInputCount(); // Ensure correct buffer size. if (this.lastInputWeights == null || this.lastInputWeights.Length < inputCount) { this.lastInputWeights = new float[inputCount]; for (int i = 0; i < inputCount; i++) { this.lastInputWeights[i] = default(float); } } var lastInputWeights = this.lastInputWeights; // Check all clips. If a clip that was weight 0 turned into weight 1, call SetAnimation. for (int i = 0; i < inputCount; i++) { float lastInputWeight = lastInputWeights[i]; float inputWeight = playable.GetInputWeight(i); bool trackStarted = lastInputWeight == 0 && inputWeight > 0; lastInputWeights[i] = inputWeight; if (trackStarted) { ScriptPlayable <SpineAnimationStateBehaviour> inputPlayable = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(i); SpineAnimationStateBehaviour clipData = inputPlayable.GetBehaviour(); if (clipData.animationReference == null) { float mixDuration = clipData.customDuration ? clipData.mixDuration : state.Data.DefaultMix; state.SetEmptyAnimation(trackIndex, mixDuration); } else { if (clipData.animationReference.Animation != null) { Spine.TrackEntry trackEntry = state.SetAnimation(trackIndex, clipData.animationReference.Animation, clipData.loop); trackEntry.EventThreshold = clipData.eventThreshold; trackEntry.DrawOrderThreshold = clipData.drawOrderThreshold; trackEntry.TrackTime = (float)inputPlayable.GetTime() * (float)inputPlayable.GetSpeed(); trackEntry.TimeScale = (float)inputPlayable.GetSpeed(); trackEntry.AttachmentThreshold = clipData.attachmentThreshold; trackEntry.HoldPrevious = clipData.holdPrevious; if (clipData.customDuration) { trackEntry.MixDuration = clipData.mixDuration; } } //else Debug.LogWarningFormat("Animation named '{0}' not found", clipData.animationName); } // Ensure that the first frame ends with an updated mesh. if (skeletonAnimation) { skeletonAnimation.Update(0); skeletonAnimation.LateUpdate(); } else if (skeletonGraphic) { skeletonGraphic.Update(0); skeletonGraphic.LateUpdate(); } } } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); if (_character == null) { GameObject characterObject = playerData as GameObject; if (characterObject) { _character = characterObject.GetComponent <AC.Char>(); } } if (_character) { int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); Transform headTurnTarget = null; Vector3 headTurnOffset = Vector3.zero; for (int i = 0; i < playable.GetInputCount(); ++i) { float weight = playable.GetInputWeight(i); ScriptPlayable <HeadTurnPlayableBehaviour> clip = (ScriptPlayable <HeadTurnPlayableBehaviour>)playable.GetInput(i); HeadTurnPlayableBehaviour shot = clip.GetBehaviour(); if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0.0001f) { clipA = clipB; clipB.weight = weight; clipB.localTime = clip.GetTime(); clipB.duration = clip.GetDuration(); clipB.headTurnTarget = shot.headTurnTarget; clipB.headTurnOffset = shot.headTurnOffset; if (++activeInputs == 2) { break; } } } headTurnTarget = (clipB.headTurnTarget) ? clipB.headTurnTarget : clipA.headTurnTarget; float _weight = clipB.weight; if (clipA.headTurnTarget) { headTurnOffset = (clipB.headTurnOffset * clipB.weight) + (clipA.headTurnOffset * clipA.weight); } else { headTurnOffset = clipB.headTurnOffset; } _character.SetTimelineHeadTurnOverride(headTurnTarget, headTurnOffset, _weight); } }