private void Start() { animator = GetComponent <Animator>(); AnimationPlayableUtilities.PlayClip(animator, clip, out playableGraph); //PlayAnimationWordy(); }
private void Initialize() { if (m_IsInitialized) { return; } m_Animator = GetComponent <Animator>(); if (m_Animator != null) { Destroy(m_Animator); } m_Animator = gameObject.AddComponent <Animator>(); m_Graph = PlayableGraph.Create(); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.Manual); m_StateController = new PlayableStateController(m_Graph); var template = new PlayableAmimatorDriver(); template.Initialize(m_Graph, m_StateController); m_OutputPlayable = ScriptPlayable <PlayableAmimatorDriver> .Create(m_Graph, template, 1); AnimationPlayableUtilities.Play(m_Animator, m_OutputPlayable, m_Graph); m_Graph.Stop(); updateObject = new UpdateObject(this, UpdateGraph, mode); PlayableUpdateManager.Reg(updateObject); m_IsInitialized = true; }
public static PlayableGraph PlayAnim(AnimationClip clip, GameObject obj) { PlayableGraph playableGraph; AnimationPlayableUtilities.PlayClip(obj.GetComponent <Animator>(), clip, out playableGraph); return(playableGraph); }
/************************************************************************************************************************/ #endif /************************************************************************************************************************/ /// <summary> /// Called by Unity when this component is first created. /// <para></para> /// Initialises everything needed to play the <see cref="Clip"/>. /// </summary> private void Awake() { if (_Clip == null || _Animator == null) { return; } if (_Graph.IsValid()) { _Graph.Destroy(); } _Playable = AnimationPlayableUtilities.PlayClip(_Animator, _Clip, out _Graph); _Playable.SetSpeed(_Speed); if (!_FootIK) { _Playable.SetApplyFootIK(false); } if (!_Clip.isLooping) { _Playable.SetDuration(_Clip.length); } }
public void Start() { graph = PlayableGraph.Create(name); layerMixer = AnimationLayerMixerPlayable.Create(graph, 0); AnimationPlayableUtilities.Play(animator, layerMixer, graph); }
// 初始化 private void Initialize() { if (m_Initialized) { return; } // 设置Animator m_Animator = GetComponent <Animator>(); m_Animator.updateMode = m_AnimatePhysics ? AnimatorUpdateMode.AnimatePhysics : AnimatorUpdateMode.Normal; m_Animator.cullingMode = m_CullingMode; // 创建PlayableGraph m_Graph = PlayableGraph.Create(); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); // 创建ScriptPlayable<SimpleAnimationPlayable> SimpleAnimationPlayable template = new SimpleAnimationPlayable(); var playable = ScriptPlayable <SimpleAnimationPlayable> .Create(m_Graph, template, 1); m_Playable = playable.GetBehaviour(); m_Playable.onDone += OnPlayableDone; // 如果没有EditorState // 设置一个 if (m_States == null) { m_States = new EditorState[1]; m_States[0] = new EditorState(); m_States[0].defaultState = true; m_States[0].name = "Default"; } // 根据编辑器上设置 // 在SimpleAnimationPlayable上 // 添加Clip if (m_States != null) { foreach (var state in m_States) { if (state.clip) { m_Playable.AddClip(state.clip, state.name); } } } // 创建默认的播放状态Default EnsureDefaultStateExists(); // Q: ?? AnimationPlayableUtilities.Play(m_Animator, m_Playable.playable, m_Graph); Play(); Kick(); m_Initialized = true; }
void OnEnable() { var animator = GetComponent <Animator>(); if (animator == null) { animator = gameObject.AddComponent <Animator>(); } AnimationPlayableUtilities.PlayClip(animator, Clip, out _playableGraph); }
public void Play() { if (!_graphConnected) { AnimationPlayableUtilities.Play(Animator, _playable.Playable, _playable.Graph); _graphConnected = true; } else { _graph.Play(); } }
/// <summary>Plays the Animation Clip with the given index.</summary> /// <param name="index">The Animation Clip index.</param> public void PlayAnimation(int index) { if (_animator == null || AnimationClips == null || index < 0 || index >= AnimationClips.Count) { return; } var animationClip = AnimationClips[index]; if (_clipPlayable.IsValid()) { _clipPlayable.Destroy(); } _clipPlayable = AnimationPlayableUtilities.PlayClip(_animator, animationClip, out _playableGraph); _clipPlayable.SetApplyFootIK(false); _clipPlayable.SetApplyPlayableIK(false); }
private void Initialize() { if (m_Initialized) { return; } m_Animator = GetComponent <Animator>(); m_Animator.updateMode = m_AnimatePhysics ? AnimatorUpdateMode.AnimatePhysics : AnimatorUpdateMode.Normal; m_Animator.cullingMode = m_CullingMode; m_Graph = PlayableGraph.Create(); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); // 先自行new一個出來再當作template塞進Create方法(應該是為了確保Constructor執行) SimpleAnimationPlayable template = new SimpleAnimationPlayable(); var playable = ScriptPlayable <SimpleAnimationPlayable> .Create(m_Graph, template, 1); m_Playable = playable.GetBehaviour(); m_Playable.onDone += OnPlayableDone; if (m_States == null) { m_States = new EditorState[1]; m_States[0] = new EditorState(); m_States[0].defaultState = true; m_States[0].name = "Default"; } if (m_States != null) { foreach (var state in m_States) { if (state.clip) { m_Playable.AddClip(state.clip, state.name); } } } EnsureDefaultStateExists(); // 綁定m_Aniamtor採用起點為m_Playable的graph(懶人寫法不需要再自行處理PlayableOutput) AnimationPlayableUtilities.Play(m_Animator, m_Playable.playable, m_Graph); Play(); Kick(); m_Initialized = true; }
private void Initialize() { if (m_Initialized) { return; } m_Animator = GetComponent <Animator>(); m_Animator.updateMode = m_AnimatePhysics ? AnimatorUpdateMode.AnimatePhysics : AnimatorUpdateMode.Normal; m_Animator.cullingMode = m_CullingMode; m_Graph = PlayableGraph.Create(); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); SimpleAnimationPlayable template = new SimpleAnimationPlayable(); Debug.Log(m_Graph.GetPlayableCount()); var playable = ScriptPlayable <SimpleAnimationPlayable> .Create(m_Graph, template, 1); m_Playable = playable.GetBehaviour(); m_Playable.onDone += OnPlayableDone; if (m_States == null) { m_States = new EditorState[1]; m_States[0] = new EditorState(); m_States[0].defaultState = true; m_States[0].name = "Default"; } if (m_States != null) { foreach (var state in m_States) { if (state.clip) { m_Playable.AddClip(state.clip, state.name); } } } EnsureDefaultStateExists(); AnimationPlayableUtilities.Play(m_Animator, m_Playable.playable, m_Graph); Play(); Kick(); m_Initialized = true; }
private void Start() { m_Animator = GetComponent <Animator>(); m_Graph = PlayableGraph.Create(); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); MyPlayable template = new MyPlayable(); var playable = ScriptPlayable <MyPlayable> .Create(m_Graph, template, 1); m_Playable = playable.GetBehaviour(); // m_Playable.onDone += OnPlayableDone; // AnimationPlayableUtilities.PlayMixer() m_Playable.Setup(Clip); AnimationPlayableUtilities.Play(m_Animator, m_Playable.Playable, m_Graph); }
public void ForceInitialize() { _isInitialized = true; _animator = GetComponent <Animator>(); _playableGraph = PlayableGraph.Create(); _playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); var template = new EasyAnimationPlayable(); var playable = ScriptPlayable <EasyAnimationPlayable> .Create(_playableGraph, template, 1); _playable = playable.GetBehaviour(); foreach (var animationClip in _animationClips) { _playable.Add(animationClip, animationClip.name); } foreach (var blendTree in _blendTrees) { _playable.Add(blendTree); } foreach (var blendTree in _blendTrees) { foreach (var blendMotion in blendTree.BlendMotions) { var animationClip = blendMotion.Motion as AnimationClip; if (!_animationClips.Contains(animationClip)) { _animationClips.Add(animationClip); } } } AnimationPlayableUtilities.Play(_animator, _playable.Self, _playableGraph); if (_playAutomaticallyOnInitialize) { _playable.Play(0); } }
public void PlayAnimation(AnimationClip clip, bool AutoPlay) { if (clip != null) { if (AnimStarted) { playableGraph.Destroy(); } Anim.speed = 1; AnimationPlayableUtilities.PlayClip(Anim, clip, out playableGraph); AnimStarted = true; } else { if (AnimStarted) { playableGraph.Destroy(); } } }
private void Initialize() { if (m_IsInitialized) { return; } m_Animator = GetComponent <Animator>(); m_Graph = PlayableGraph.Create(); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); m_StateController = new PlayableStateController(m_Graph); var template = new PlayableAmimatorDriver(); template.Initialize(m_Graph, m_StateController); m_OutputPlayable = ScriptPlayable <PlayableAmimatorDriver> .Create(m_Graph, template, 1); AnimationPlayableUtilities.Play(m_Animator, m_OutputPlayable, m_Graph); m_IsInitialized = true; }
public void PlayAnimation(AnimationClip clip, bool AutoPlay, float Speed) { if (clip != null) { if (AnimStarted) { playableGraph.Destroy(); } AnimationClipPlayable pp = AnimationPlayableUtilities.PlayClip(Anim, clip, out playableGraph); pp.SetSpeed(Speed); AnimStarted = true; } else { if (AnimStarted) { playableGraph.Destroy(); } } }
private void advanceSlide() { if (currentSlideIndex < currentSlideshow.Count) { currentSlideIndex++; if (currentSlideshow[currentSlideIndex] != null) { clipToPlay = currentSlideshow[currentSlideIndex]; AnimationPlayableUtilities.PlayClip(currentAnimation, clipToPlay, out pg); } if (currentAudioSource.isPlaying) { currentAudioSource.Stop(); } if (currentAudio[currentSlideIndex] != null) { currentAudioSource.clip = currentAudio[currentSlideIndex]; currentAudioSource.Play(); } } }
public static int Play_s(IntPtr l) { int result; try { Animator animator; LuaObject.checkType <Animator>(l, 1, out animator); Playable playable; LuaObject.checkValueType <Playable>(l, 2, out playable); PlayableGraph graph; LuaObject.checkValueType <PlayableGraph>(l, 3, out graph); AnimationPlayableUtilities.Play(animator, playable, graph); LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public static int PlayClip_s(IntPtr l) { int result; try { Animator animator; LuaObject.checkType <Animator>(l, 1, out animator); AnimationClip clip; LuaObject.checkType <AnimationClip>(l, 2, out clip); PlayableGraph playableGraph; AnimationClipPlayable animationClipPlayable = AnimationPlayableUtilities.PlayClip(animator, clip, out playableGraph); LuaObject.pushValue(l, true); LuaObject.pushValue(l, animationClipPlayable); LuaObject.pushValue(l, playableGraph); result = 3; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public static int PlayLayerMixer_s(IntPtr l) { int result; try { Animator animator; LuaObject.checkType <Animator>(l, 1, out animator); int inputCount; LuaObject.checkType(l, 2, out inputCount); PlayableGraph playableGraph; AnimationLayerMixerPlayable animationLayerMixerPlayable = AnimationPlayableUtilities.PlayLayerMixer(animator, inputCount, out playableGraph); LuaObject.pushValue(l, true); LuaObject.pushValue(l, animationLayerMixerPlayable); LuaObject.pushValue(l, playableGraph); result = 3; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public static int PlayAnimatorController_s(IntPtr l) { int result; try { Animator animator; LuaObject.checkType <Animator>(l, 1, out animator); RuntimeAnimatorController controller; LuaObject.checkType <RuntimeAnimatorController>(l, 2, out controller); PlayableGraph playableGraph; AnimatorControllerPlayable animatorControllerPlayable = AnimationPlayableUtilities.PlayAnimatorController(animator, controller, out playableGraph); LuaObject.pushValue(l, true); LuaObject.pushValue(l, animatorControllerPlayable); LuaObject.pushValue(l, playableGraph); result = 3; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
IEnumerator PlayQueue() { if (clips.Count == 0) { yield break; } for (int i = 0; i <= clips.Count; i++) { print("Queue size is: " + clips.Count.ToString()); //print("starting queue"); // if(player.GetButtonDown("Light")) anim.SetTrigger("VSlash_01"); // if(player.GetButtonDown("Medium")) anim.SetTrigger("VSlash2HSlash"); // if(player.GetButtonDown("Heavy")) anim.SetTrigger("FireSwd01"); //yield return new WaitForSeconds(tick); clipPlayables[i] = AnimationPlayableUtilities.PlayClip(anim, clips.Dequeue(), out playGraph); print("playing animation"); clipArray = clips.ToArray(); movement.isPaused = true; yield return(new WaitForSeconds(clipPlayables[i].GetAnimationClip().length)); print("animation has finished"); movement.isPaused = false; clipPlayables[i].Destroy(); playGraph.Play(); yield return(null); } // if(clips.Count > 0 ) // { // blending = true; // //clipPlayable = AnimationClipPlayable.Create(playGraph, clips.Dequeue()); // //playGraph.Connect(clipPlayable, 0, mixPlayer, index+1); // index++; // }else // { // mixPlayer.SetInputWeight(0, 1); // index = 0; // //clipPlayable.Destroy(); // } // if(clipPlayable.IsValid() && clipPlayable.IsDone()) // { // mixPlayer.SetInputWeight(0, 1); // playGraph.Disconnect(clipPlayable,index+1); // clipPlayable.Destroy(); // } // //if(blending == false) return; // blendTime += Time.deltaTime; // weight = blendTime / blendDuration; // weight = Mathf.Clamp01(weight); // if(index == 0) return; // mixPlayer.SetInputWeight(index-1, 1.0f-weight); // mixPlayer.SetInputWeight(index, weight); // if(weight >= 1) // { // mixPlayer.SetInputWeight(0, 1); // blendTime = 0; // //blending = false; // //playGraph.Disconnect(clipPlayable,0); // } }
// Start is called before the first frame update void Start() { graph = PlayableGraph.Create(name); if (m_maxSpringJoint <= 0) { m_maxSpringJoint = 4; } // points. m_SphereGameObjects = new GameObject[m_maxSpringJoint]; for (int ii = 0; ii < m_maxSpringJoint; ii++) { m_SphereGameObjects[ii] = GameObject.CreatePrimitive(PrimitiveType.Sphere); m_SphereGameObjects[ii].layer = 8; // todo. m_SphereGameObjects[ii].transform.position = new Vector3(0.0f, floorPositionY - (float)ii, 0.0f); m_SphereGameObjects[ii].name = "joint" + ii; if (GameObjectMaterial != null) { var renderer = m_SphereGameObjects[ii].GetComponent <MeshRenderer>(); renderer.material = GameObjectMaterial; } } #if false // capusles. m_CapsuleGameObjects = new GameObject[m_maxSpringJoint - 1]; for (int ii = 0; ii < m_maxSpringJoint - 1; ii++) { m_CapsuleGameObjects[ii] = GameObject.CreatePrimitive(PrimitiveType.Capsule); m_CapsuleGameObjects[ii].transform.position = new Vector3(0.0f, -0.5f + (float)-ii, 0.0f); } #endif m_rootGameObject = new GameObject(); // Parent-child relationship. #if false for (int ii = 1; ii < m_maxSpringJoint; ii++) { m_SphereGameObjects[ii].transform.parent = m_SphereGameObjects[ii - 1].transform; } if (m_CapsuleGameObjects != null) { for (int ii = 0; ii < m_maxSpringJoint - 1; ii++) { m_CapsuleGameObjects[ii].transform.parent = m_SphereGameObjects[ii].transform; } } var animator = m_SphereGameObjects[0].AddComponent <Animator>(); UnityEngine.AvatarBuilder.BuildGenericAvatar( m_SphereGameObjects[0], m_SphereGameObjects[0].name); #else for (int ii = 0; ii < m_maxSpringJoint; ii++) { m_SphereGameObjects[ii].transform.parent = m_rootGameObject.transform; } var animator = m_rootGameObject.AddComponent <Animator>(); UnityEngine.AvatarBuilder.BuildGenericAvatar( m_rootGameObject, m_rootGameObject.name); #endif joints = new NativeArray <TransformStreamHandle>(m_maxSpringJoint, Allocator.Persistent); for (int ii = 0; ii < m_maxSpringJoint; ii++) { joints[ii] = animator.BindStreamTransform(m_SphereGameObjects[ii].transform); } // AnimatorUtility.OptimizeTransformHierarchy(m_SphereGameObjects[0], null); #if false effectors = new NativeArray <TransformSceneHandle>(m_maxSpringJoint, Allocator.Persistent); for (int ii = 0; ii < m_maxSpringJoint; ii++) { effectors[ii] = animator.BindSceneTransform(new GameObject().transform); } ; #endif // targetEffector = animator.BindSceneTransform(m_targetGameObject.transform); job = new AnimationJob() { // effectors = effectors, joints = joints, floorPositionY = floorPositionY, rootOffset = rootOffset, restLength = restLength, hangGameObjectFlag = HangGameObject ? 1:0, // targetEffector = targetEffector, }; job.SetUp(); var playable = AnimationScriptPlayable.Create(graph, job); AnimationPlayableUtilities.Play(animator, playable, graph); }
private void Start() { AnimationPlayableUtilities.PlayClip(GetComponent <Animator>(), clip, out playableGraph); }
void Start() { PlayableGraph graph; var clip = MakeClip(); var playable = AnimationPlayableUtilities.PlayClip(animator, clip, out graph); }
public void PlayCurrent() { AnimationPlayableUtilities.PlayClip(anim, clip, out PlayableGraph g); this.g = g; }
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(); } }