/// <summary> /// Get the two clips that need to be mixed together for the current frame. /// </summary> /// <param name="playable">The track's playable.</param> /// <param name="clipIndexA">The output index for the first clip. Use with /// TimelineTools.GetPlayableBehaviour to get the corresponding clip.</param> /// <param name="clipIndexB">The output index for the second clip. Use with /// TimelineTools.GetPlayableBehaviour to get the corresponding clip.</param> public static void FindClipsToMix(Playable playable, out int clipIndexA, out int clipIndexB) { for (int i = 0; i < playable.GetInputCount(); i++) { float weight = playable.GetInputWeight(i); if (weight > 0 && weight < 1f) { clipIndexA = i; clipIndexB = i + 1; return; } } clipIndexA = -1; clipIndexB = -1; }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { var playableInput = (ScriptPlayable <PostProcessBehaviour>)playable.GetInput(i); PostProcessBehaviour input = playableInput.GetBehaviour(); float inputWeight = playable.GetInputWeight(i); if (Mathf.Approximately(inputWeight, 0f)) { continue; } float normalizedTime = (float)(playableInput.GetTime() / playableInput.GetDuration()); input.ChangeWeight(normalizedTime); } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { if (!(this.boundGameObject == null)) { int inputCount = playable.GetInputCount <Playable>(); bool active = false; for (int i = 0; i < inputCount; i++) { if (playable.GetInputWeight(i) > 0f) { active = true; break; } } this.boundGameObject.SetActive(active); } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { m_TrackBinding = playerData as Text; if (m_TrackBinding == null) { return; } if (!m_FirstFrameHappened) { m_DefaultText = m_TrackBinding.text; m_FirstFrameHappened = true; } int inputCount = playable.GetInputCount(); float totalWeight = 0f; float greatestWeight = 0f; int currentInputs = 0; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <TextSwitcherBehaviour> inputPlayable = (ScriptPlayable <TextSwitcherBehaviour>)playable.GetInput(i); TextSwitcherBehaviour input = inputPlayable.GetBehaviour(); totalWeight += inputWeight; if (inputWeight > greatestWeight) { m_TrackBinding.text = input.text; greatestWeight = inputWeight; } if (!Mathf.Approximately(inputWeight, 0f)) { currentInputs++; } } if (currentInputs != 1 && 1f - totalWeight > greatestWeight) { m_TrackBinding.text = m_DefaultText; } }
// 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) { GameObject trackBinding = playerData as GameObject; if (!trackBinding) { return; } int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (inputWeight > 0.001f && !played.Contains(i)) { played.Add(i); ScriptPlayable <BarkBehaviour> inputPlayable = (ScriptPlayable <BarkBehaviour>)playable.GetInput(i); BarkBehaviour input = inputPlayable.GetBehaviour(); if (Application.isPlaying) { if (input.useConversation) { DialogueManager.Bark(input.conversation, trackBinding.transform, input.listener); } else { DialogueManager.BarkString(input.text, trackBinding.transform, input.listener); } } else { var message = DialogueActor.GetActorName(trackBinding.transform) + " bark: " + input.GetEditorBarkText(); if (input.useConversation) { message += " (may vary)"; } PreviewUI.ShowMessage(message, 2, 1); } } else if (inputWeight <= 0.001f && played.Contains(i)) { played.Remove(i); } } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { this.m_TrackBinding = (playerData as Text); if (this.m_TrackBinding == null) { return; } if (!this.m_FirstFrameHappened) { this.m_DefaultColor = this.m_TrackBinding.color; this.m_DefaultFontSize = this.m_TrackBinding.fontSize; this.m_DefaultText = this.m_TrackBinding.text; this.m_FirstFrameHappened = true; } int inputCount = playable.GetInputCount <Playable>(); Color a = Color.clear; float num = 0f; float num2 = 0f; float num3 = 0f; int num4 = 0; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); TextSwitcherBehaviour behaviour = ((ScriptPlayable <T>)playable.GetInput(i)).GetBehaviour(); a += behaviour.color * inputWeight; num += (float)behaviour.fontSize * inputWeight; num2 += inputWeight; if (inputWeight > num3) { this.m_TrackBinding.text = behaviour.text; num3 = inputWeight; } if (!Mathf.Approximately(inputWeight, 0f)) { num4++; } } this.m_TrackBinding.color = a + this.m_DefaultColor * (1f - num2); this.m_TrackBinding.fontSize = Mathf.RoundToInt(num + (float)this.m_DefaultFontSize * (1f - num2)); if (num4 != 1 && 1f - num2 > num3) { this.m_TrackBinding.text = this.m_DefaultText; } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Color finalColor = Color.black; int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <AmbientLightControlBehaviour> inputPlayable = (ScriptPlayable <AmbientLightControlBehaviour>)playable.GetInput(i); AmbientLightControlBehaviour input = inputPlayable.GetBehaviour(); // Use the above variables to process each frame of this playable. finalColor += input.color * inputWeight; } RenderSettings.ambientLight = finalColor; }
public override void PrepareFrame(Playable playable, FrameData info) { int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <GfxAnimatorBehaviour> inputPlayable = (ScriptPlayable <GfxAnimatorBehaviour>)playable.GetInput(i); GfxAnimatorBehaviour input = inputPlayable.GetBehaviour(); if (inputWeight == 1.0f && animationName != input.animationName) { animationName = input.animationName; } } base.PrepareFrame(playable, info); }
private void SyncWeight(float weight) { if (director.playableGraph.IsValid()) { int rootPlayableCount = director.playableGraph.GetRootPlayableCount(); for (int i = 0; i < rootPlayableCount; i++) { Playable rootPlayable = director.playableGraph.GetRootPlayable(i); if (rootPlayable.IsValid() && rootPlayable.CanSetWeights()) { for (int j = 0; j < rootPlayable.GetInputCount(); j++) { rootPlayable.SetInputWeight(j, weight); } } } } }
//============================================================================================ /** * @brief Recursive function which destroys a playable and any child playables * *********************************************************************************************/ private void ClearPlayable(ref Playable a_playable) { if (!a_playable.IsValid()) return; int inputCount = a_playable.GetInputCount(); for(int i=0; i < inputCount; ++i) { var playable = a_playable.GetInput(i); ClearPlayable(ref playable); playable.Destroy(); } a_playable.Destroy(); }
//---------------------------------------------------------------------------------------------------------------------- // Called each frame while the state is set to Play public override void ProcessFrame(Playable playable, FrameData info, object playerData) { int inputCount = playable.GetInputCount<Playable>(); if (inputCount == 0 ) { return; // it doesn't work as mixer. } if (m_boundGameObject== null ) { return; } GetActiveTimelineClipInto(m_clipAssets, m_playableDirector.time, out TimelineClip clip, out T activePlayableAsset); if (null == clip) return; ProcessActiveClipV(activePlayableAsset, m_playableDirector.time, clip); m_boundGameObject.SetActive(true); }
//Happens in Play mode //Uses the NavMeshAgent to control the units, delegating their movement and animations to the AI private void ProcessPlayModeFrame(Playable playable) { int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (inputWeight > 0f) { ScriptPlayable <EnemyControlBehaviour> inputPlayable; inputPlayable = (ScriptPlayable <EnemyControlBehaviour>)playable.GetInput(i); EnemyControlBehaviour input = inputPlayable.GetBehaviour(); NavMeshAgent agent = enemy.GetComponent <NavMeshAgent>(); agent.SetDestination(input.targetPosition); } } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { m_TrackBinding = playerData as Image; if (m_TrackBinding == null) { return; } if (!m_FirstFrameHappened) { m_DefaultColor = m_TrackBinding.color; m_FirstFrameHappened = true; } int inputCount = playable.GetInputCount(); Color blendedColor = Color.clear; float totalWeight = 0f; float greatestWeight = 0f; int currentInputs = 0; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <FadeInImageBehaviour> inputPlayable = (ScriptPlayable <FadeInImageBehaviour>)playable.GetInput(i); FadeInImageBehaviour input = inputPlayable.GetBehaviour(); blendedColor += input.color * inputWeight; totalWeight += inputWeight; if (inputWeight > greatestWeight) { greatestWeight = inputWeight; } if (!Mathf.Approximately(inputWeight, 0f)) { currentInputs++; } } m_TrackBinding.color = blendedColor + m_DefaultColor * (1f - totalWeight); }
// 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 trackBinding = playerData as BattleCharacterBehaviour; var finalPosition = Vector3.zero; if (!trackBinding) { return; } int inputCount = playable.GetInputCount(); //get the number of all clips on this track BattleTransformBehaviour input = null; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (inputWeight == 0) { continue; } ScriptPlayable <BattleTransformBehaviour> inputPlayable = (ScriptPlayable <BattleTransformBehaviour>)playable.GetInput(i); input = inputPlayable.GetBehaviour(); var position = ResolveRelativeVector(input.position, input.relative, trackBinding, input.targetIndex); // Use the above variables to process each frame of this playable. finalPosition += position * inputWeight; } //assign the result to the bound object trackBinding.transform.position = finalPosition; if (input != null) { if (input.flip) { trackBinding.transform.eulerAngles = trackBinding.FormationPosition.x < 0 ? new Vector3(0, -90, 0) : new Vector3(0, 90, 0); } else { trackBinding.transform.eulerAngles = trackBinding.FormationPosition.x < 0 ? new Vector3(0, 90, 0) : new Vector3(0, -90, 0); } } }
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) { Transform binding = playerData as Transform; if (binding == null) { return; } int inputCount = playable.GetInputCount(); if (inputCount == 0) { return; } float totalWeight = 0; Vector3 lookAtDirection = new Vector3(); for (int i = 0; i < inputCount; i++) { var inputPlayable = (ScriptPlayable <EZTransformConstraintBehaviour>)playable.GetInput(i); var inputBehaviour = inputPlayable.GetBehaviour(); if (inputBehaviour.target == null || inputBehaviour.target.position == binding.position) { continue; } float inputWeight = playable.GetInputWeight(i); if (inputWeight == 0) { continue; } totalWeight += inputWeight; lookAtDirection += (inputBehaviour.target.position - binding.position).normalized * inputWeight; } if (totalWeight < 1e-5) { return; } binding.rotation = Quaternion.LookRotation(lookAtDirection, binding.up); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { if (transform == null) { return; } int inputCount = playable.GetInputCount(); float scaleTotalWeight = 0f; Vector3 blendedPosition = Vector3.zero; Vector3 blendedRotation = Vector3.zero; Vector3 blendedScale = Vector3.zero; for (int i = 0; i < inputCount; i++) { var playableInput = (ScriptPlayable <TweenBehaviour>)playable.GetInput(i); TweenBehaviour input = playableInput.GetBehaviour(); float inputWeight = playable.GetInputWeight(i); double duration = playableInput.GetDuration(); float inverseDuration = 1f / (float)duration; float normalisedTime = (float)(playableInput.GetTime() * inverseDuration); float tweenPosProgress = input.position.currentCurve.Evaluate(normalisedTime); float tweenRotateProgress = input.rotation.currentCurve.Evaluate(normalisedTime); float tweenScaleProgress = input.scale.currentCurve.Evaluate(normalisedTime); scaleTotalWeight += inputWeight; blendedPosition += Vector3.Lerp(input.position.startOffSet, input.position.endOffSet, tweenPosProgress) * inputWeight; blendedRotation += Vector3.Lerp(input.rotation.startOffSet, input.rotation.endOffSet, tweenRotateProgress) * inputWeight; blendedScale += Vector3.Lerp(input.scale.startOffSet, input.scale.endOffSet, tweenScaleProgress) * inputWeight; } transform.localPosition = defaultPosition + blendedPosition; transform.rotation = defaultRotation * Quaternion.Euler(blendedRotation); transform.localScale = defaultScale + blendedScale; }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { var trackBinding = playerData as LaserPerformance; if (!trackBinding) { return; } var clipTime = Director.time; var gradient = new Gradient(); for (var i = 0; i < playable.GetInputCount(); i++) { var inputWeight = playable.GetInputWeight(i); var inputPlayable = (ScriptPlayable <LaserPerformanceBehaviour>)playable.GetInput(i); var inputBehaviour = inputPlayable.GetBehaviour(); if (inputWeight > 0.5f) { trackBinding.ChangeState(inputBehaviour.color, inputBehaviour.dimmer, inputBehaviour.motion); trackBinding.IntensityMultiplier = inputBehaviour.intensityMultiplier; trackBinding.Speed = inputBehaviour.speed; trackBinding.OffsetStrength = inputBehaviour.offsetStrength; trackBinding.panRange = new Range(inputBehaviour.panRange.min, inputBehaviour.panRange.max); trackBinding.tiltRange = new Range(inputBehaviour.tiltRange.min, inputBehaviour.tiltRange.max); var clip = Clips[i]; clipTime = Director.time - clip.start; } if (inputWeight > 0) { gradient = GradientExtensions.Lerp(gradient, inputBehaviour.laserGradient, inputWeight); } } trackBinding.LaserGradient = gradient; trackBinding.ProcessFrame(Director.time, clipTime); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { if (trackBindingImage == null) { trackBindingImage = playerData as Image; initialAlphaValue = trackBindingImage.color.a; } int inputCount = playable.GetInputCount(); float alpha = 0f; for (int i = 0; i < inputCount; ++i) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <ImageAlphaBehaviour> inputPlayable = (ScriptPlayable <ImageAlphaBehaviour>)playable.GetInput(i); ImageAlphaBehaviour input = inputPlayable.GetBehaviour(); alpha += input.Alpha * inputWeight; } trackBindingImage.color = new Color(trackBindingImage.color.r, trackBindingImage.color.g, trackBindingImage.color.b, alpha); }
// Called each frame while the state is set to Play public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Debug.Log("MoveMixer.PrepareFrame"); int inputCount = playable.GetInputCount(); if (inputCount > 0) { GameObject role = playerData as GameObject; float inputWeight = playable.GetInputWeight(0); ScriptPlayable <PosBehaviour> inputPlayable = (ScriptPlayable <PosBehaviour>)playable.GetInput(0); PosBehaviour input = inputPlayable.GetBehaviour(); Vector3 blendedPosition = input.result; role.transform.position = blendedPosition; } }
public void Initialize(AnimationClip[] clipsToPlay, Playable owner, PlayableGraph graph) { owner.SetInputCount(1); mixer = AnimationMixerPlayable.Create(graph, clipsToPlay.Length); graph.Connect(mixer, 0, owner, 0); owner.SetInputWeight(0, 1); for (int clipIndex = 0; clipIndex < mixer.GetInputCount(); ++clipIndex) { graph.Connect(AnimationClipPlayable.Create(graph, clipsToPlay[clipIndex]), 0, mixer, clipIndex); mixer.SetInputWeight(clipIndex, 1.0f); } }
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 PrepareFrame(Playable playable, FrameData info) { Reset(); var inputCount = playable.GetInputCount(); var weightSum = 0f; if (NormalizeInputs) { for (var i = 0; i < inputCount; i++) { if (GetIkFromInput(playable, i).IsValid()) { weightSum += playable.GetInputWeight(i); } } } else { weightSum = 1; } if (weightSum > 0) { for (var i = 0; i < inputCount; i++) { var weight = playable.GetInputWeight(i); if (weight > 0) { var ikPlayable = GetIkFromInput(playable, i); if (ikPlayable.IsValid()) { var behavior = ikPlayable.GetBehaviour(); // TODO: Need to investigate, how to prepare frames in input before evaluating mixer behavior.PrepareFrame(ikPlayable, info); Add(behavior, weight / weightSum); } } } } }
protected override float Mix(Playable playable, FrameData info, WetDecal trackBinding) { var inputCount = playable.GetInputCount(); var totalWeight = 0f; var blendedSaturation = 0f; for (var i = 0; i < inputCount; i++) { var inputWeight = playable.GetInputWeight(i); var inputPlayable = (ScriptPlayable <Data>)playable.GetInput(i); var input = inputPlayable.GetBehaviour(); blendedSaturation += input.Saturation * inputWeight; totalWeight += inputWeight; } return(blendedSaturation + Default * (1f - totalWeight)); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Transform binding = playerData as Transform; if (binding == null) { return; } int inputCount = playable.GetInputCount(); if (inputCount == 0) { return; } float totalWeight = 0; Vector3 outputScale = new Vector3(); for (int i = 0; i < inputCount; i++) { var inputPlayable = (ScriptPlayable <EZTransformConstraintBehaviour>)playable.GetInput(i); var inputBehaviour = inputPlayable.GetBehaviour(); if (inputBehaviour.target == null) { continue; } float inputWeight = playable.GetInputWeight(i); if (inputWeight == 0) { continue; } totalWeight += inputWeight; outputScale += inputBehaviour.target.localScale * inputWeight; } if (totalWeight < 1e-5) { return; } binding.localScale = outputScale / totalWeight; }
// 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) { ActorManager trackBinding = playerData as ActorManager; if (!trackBinding) return; int inputCount = playable.GetInputCount (); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable<CustomStabBehaviour> inputPlayable = (ScriptPlayable<CustomStabBehaviour>)playable.GetInput(i); CustomStabBehaviour input = inputPlayable.GetBehaviour (); // Use the above variables to process each frame of this playable. } }
private List <Node> GetInputsFromPlayableNode(Playable h) { var inputs = new List <Node>(); if (h.IsValid()) { for (int port = 0; port < h.GetInputCount(); ++port) { Playable playable = h.GetInput(port); if (playable.IsValid()) { float weight = h.GetInputWeight(port); Node node = CreateNodeFromPlayable(playable, weight); inputs.Add(node); } } } return(inputs); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Transform binding = playerData as Transform; if (binding == null) { return; } int inputCount = playable.GetInputCount(); if (inputCount == 0) { return; } float totalWeight = 0; Quaternion outputRotation = new Quaternion(); for (int i = 0; i < inputCount; i++) { var inputPlayable = (ScriptPlayable <EZTransformConstraintBehaviour>)playable.GetInput(i); var inputBehaviour = inputPlayable.GetBehaviour(); if (inputBehaviour.target == null) { continue; } float inputWeight = playable.GetInputWeight(i); if (inputWeight == 0) { continue; } totalWeight += inputWeight; outputRotation = QuaternionExt.Cumulate(outputRotation, inputBehaviour.target.rotation.Scale(inputWeight)); } if (totalWeight < 1e-5) { return; } binding.rotation = outputRotation; }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Renderer renderer = playerData as Renderer; if (renderer == null) { return; } if (lastRenderer != null && (lastRenderer != renderer || lastIndex != materialIndex || lastPropertyName != propertyName)) { lastRenderer.SetPropertyBlock(null, lastIndex); } lastRenderer = renderer; lastIndex = materialIndex; lastPropertyName = propertyName; if (propertyName == null) { return; } int inputCount = playable.GetInputCount(); float totalWeight = 0; Vector4 outputValue = Vector4.zero; for (int i = 0; i < inputCount; i++) { var inputPlayable = (ScriptPlayable <EZMaterialVectorPlayableBehaviour>)playable.GetInput(i); var inputBehaviour = inputPlayable.GetBehaviour(); float inputWeight = playable.GetInputWeight(i); totalWeight += inputWeight; outputValue += inputBehaviour.value * inputWeight; } renderer.GetPropertyBlock(propertyBlock, materialIndex); outputValue = Vector4.Lerp(value, outputValue, totalWeight); propertyBlock.SetVector(propertyName, outputValue); renderer.SetPropertyBlock(propertyBlock, materialIndex); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); if (!Mathf.Approximately(inputWeight, 1f)) { continue; } ScriptPlayable <CutsceneScriptControlBehaviour> inputPlayable = (ScriptPlayable <CutsceneScriptControlBehaviour>)playable.GetInput(i); CutsceneScriptControlBehaviour input = inputPlayable.GetBehaviour(); input.playerInput.enabled = input.playerInputEnabled; } }