public void PlayIdle() { if (!animancer.IsPlaying(enemyData.GetIdleClip())) { animancerState_layer1 = animancer.Play(enemyData.GetIdleClip()); } }
public void PlayFadeIn(Action action = null) { Time.timeScale = 1f; var state = animancer.Play(fadeIn); state.Events.OnEnd = () => { action?.Invoke(); }; }
/************************************************************************************************************************/ private void Awake() { // Instead of only a single animation, we have a different one for each direction we can face. // So we get whichever is appropriate for that direction and play it. var clip = _Idles.GetClip(_Facing); _Animancer.Play(clip); }
/************************************************************************************************************************/ private void OnEnable() { // Transitions store their events so we only initialize them once on startup // instead of setting the event every time the animation is played. _Action.Events.OnEnd = OnActionEnd; // The Fade Duration of this transition will be ignored because nothing else is playing yet so there is // nothing to fade from. _Animancer.Play(_Idle); }
} //抽象方法的接口2 /************************************************************************************************************************/ protected virtual void Awake() { // Start在动画开始时暂停。 _Animancer.Play(_WakeUp); _Animancer.Evaluate(); _Animancer.Playable.PauseGraph(); // 在这里初始化OnEnd事件,这样我们就不会每次使用它们时都分配垃圾。 _WakeUp.Events.Sequence.OnEnd = () => _Animancer.Play(MovementAnimation); _Sleep.Events.Sequence.OnEnd = _Animancer.Playable.PauseGraph; }
/************************************************************************************************************************/ protected virtual void Awake() { // Start paused at the beginning of the animation. _Animancer.Play(_WakeUp); _Animancer.Evaluate(); _Animancer.Playable.PauseGraph(); // Initialise the OnEnd events here so we don't allocate garbage every time they are used. _WakeUp.Events.Sequence.OnEnd = () => _Animancer.Play(MovementAnimation); _Sleep.Events.Sequence.OnEnd = _Animancer.Playable.PauseGraph; }
/************************************************************************************************************************/ // Called by a UI Button. public void PlaySeparateAnimation() { #if UNITY_EDITOR // Disable this warning since this example is intentionally showing the reason why the warning exists. var warnings = OptionalWarning.NativeControllerHumanoid.DisableTemporarily(); _Animancer.Play(_SeparateAnimation); warnings.Enable(); #else _Animancer.Play(_SeparateAnimation); #endif }
/************************************************************************************************************************/ private void OnEnable() { // Idle on default layer 0. _BasicAnimancer.Play(_Idle); _LayeredAnimancer.Play(_Idle); // Set the mask for layer 1 (this automatically creates the layer). _LayeredAnimancer.Layers[ActionLayer].SetMask(_ActionMask); // Since we set a mask it will use the name of the mask in the Inspector by default. But we can also // replace it with a custom name. Either way, layer names are only used in the Inspector and any calls to // this method will be compiled out of runtime builds. _LayeredAnimancer.Layers[ActionLayer].SetName("Action Layer"); }
private void SetAnimation() { var set = _isMoving ? moving : idles; var clip = set.GetClip(Facing); animancer.Play(clip); }
/************************************************************************************************************************/ private void OnEnable() { // Idle on default layer 0. _BasicAnimancer.Play(_Idle); _LayeredAnimancer.Play(_Idle); // Set the mask for layer 1 (this automatically creates the layer). _LayeredAnimancer.SetLayerMask(ActionLayer, _ActionMask); }
// Start is called before the first frame update void Start() { animancer.Play(nonCombatAnimationClips[0]); controller = gameObject.GetComponent <CharacterController>(); velocity = Vector3.zero; gravity = new Vector3(0f, -3.3f, 0f); moveSpeed = 3f; scaleMoveSpeed = 1f; turnSpeed = 100.0f; jumpSpeed = 150.0f; fallSpeed = -4f; drag = 0.85f; jumping = false; inCombat = false; chainAttack = false; }
/************************************************************************************************************************/ private void Awake() { // Start paused at the beginning of the animation. _Animancer.Play(_WakeUp); _Animancer.Playable.Evaluate(); _Animancer.Playable.PauseGraph(); // Cache the delegates we will use with the OnEnd event so we don't allocate garbage every time. _PauseGraph = _Animancer.Playable.PauseGraph; _FadeToMovement = () => _Animancer.CrossFade(_Move); }
public override void OnPrePerform() { Agent.Memory.TryGetData(targetMemoryKey, out target); startTime = Time.time; navMeshAgent.stoppingDistance = stopDistance; navMeshAgent.updateRotation = true; navMeshAgent.isStopped = false; onPrePerform?.Invoke(); Debug.Log("追逐"); state = anim.Play(animationClip, 0.1f); }
/************************************************************************************************************************/ private void Play(DirectionalAnimationSet animations) { // Store the current time. _MovementSynchronization.StoreTime(_CurrentAnimationSet); _CurrentAnimationSet = animations; _Animancer.Play(animations.GetClip(_Facing)); // If the new animation is in the synchronization group, give it the same time the previous animation had. _MovementSynchronization.SyncTime(_CurrentAnimationSet); }
/************************************************************************************************************************/ private void Play(DirectionalAnimationSet animations) { // 装载每一个单独的动画时, 我们有不同的动画对应每个面朝的方向. // 所以我们选择适合那个方向的,然后播放它. var clip = animations.GetClip(_Facing); _Animancer.Play(clip); // 或者我们可以在一行中这样做: _Animancer.Play(animations.GetClip(_Facing)); }
/************************************************************************************************************************/ private AnimancerState Play(int index) { //我们想要确保文本总是显示当前动画的名称,所以用这个方法包装常规的AnimancerComponent.Play组件,我们只需调用它 //如果我们希望其他脚本能够播放它们自己的转换,我们可以将这个方法设为public,并给它一个ClipState。转换参数, //而不只是一个“索引”。但这种方式只允许我们调用' Play(0) '和' Play(i) ',而不是' Play(_animate[0]) '和' Play(_animate [i]) ' var animation = _Animations[index]; _Text.text = animation.Clip.name; return(_Animancer.Play(animation)); }
/************************************************************************************************************************/ private void Play(DirectionalAnimationSet animations) { // Instead of only a single animation, we have a different one for each direction we can face. // So we get whichever is appropriate for that direction and play it. var clip = animations.GetClip(_Facing); _Animancer.Play(clip); // Or we could do that in one line: // _Animancer.Play(animations.GetClip(_Facing)); }
/************************************************************************************************************************/ protected void Update() { // W or UpArrow = 1. // S or DownArrow = -1. // Otherwise 0. var movement = Input.GetAxisRaw("Vertical"); if (movement != 0) { PlayMove(); // 我们没有向后移动的动画,所以只是把正向的行走动画倒过来播放用作后退动画. _Animancer.States.Current.Speed = movement; // PlayMove可以返回它播放的AnimancerState,但是使用CurrentState会节省力一点. } else { // 如果我们不移动,回到待机状态. _Animancer.Play(_Idle, 0.25f); } }
/************************************************************************************************************************/ private void OnEnable() { // 因为Float1ControllerTransition是一个可以在多个对象之间共享的转换资产,所以我们不能简单地访问_Controller.Transition. // 因为它只会保存最近播放的状态(只对一个实例是正确的,而对其他实例则不正确). // 相反,我们会在播放后立即获取状态. _Animancer.Play(_Controller); _State = _Controller.Transition.State; // Play方法返回的状态会做同样的事情,但它只返回一个基本的AnimancerState,我们需要一个Float1ControllerState来访问它下面的参数属性, // 所以我们需要对它进行类型转换:_State = (Float1ControllerState)_Animancer.Play(_Controller); }
/************************************************************************************************************************/ private AnimancerState Play(int index) { // We want to make sure that the text always shows the name of the current animation, so this method wraps // the regular AnimancerComponent.Play and we simply call this instead. // If we wanted other scripts to be able to play their own transitions, we could make this method public // and give it a ClipState.Transition parameter instead of just an `index`. But this way allows us to call // `Play(0)` and `Play(i)` instead of `Play(_Animations[0])` and `Play(_Animations[i])`. var animation = _Animations[index]; _Text.text = animation.Clip.name; return(_Animancer.Play(animation)); }
/************************************************************************************************************************/ private void Awake() { // Start paused at the beginning of the animation. _Animancer.Play(_WakeUp); _Animancer.Playable.Evaluate(); _Animancer.Playable.PauseGraph(); // Create the locomotion state but don't do anything with it yet. _Animancer.GetOrCreateState(_Locomotion); // Cache the delegates we will use with the OnEnd event so we don't allocate garbage every time. _PauseGraph = _Animancer.Playable.PauseGraph; _FadeToMovement = () => _Animancer.Transition(_Locomotion); }
/************************************************************************************************************************/ private void Awake() { _LeftFootWeight = new AnimatedProperty(_Animancer, AnimatedProperty.Type.Float, "LeftFootIK"); _RightFootWeight = new AnimatedProperty(_Animancer, AnimatedProperty.Type.Float, "RightFootIK"); _Animancer.Play(_Animation); // Tell Unity that OnAnimatorIK needs to be called every frame. ApplyAnimatorIK = true; // Get the foot bones. _LeftFoot = _Animancer.Animator.GetBoneTransform(HumanBodyBones.LeftFoot); _RightFoot = _Animancer.Animator.GetBoneTransform(HumanBodyBones.RightFoot); }
/************************************************************************************************************************/ private void Awake() { // 应用启动状态并暂停渲染 var state = _Animancer.Play(_Open); state.NormalizedTime = _Openness; _Animancer.Evaluate(); _Animancer.Playable.PauseGraph(); // 并在动画结束时暂停它以保存当前状态 state.Events.OnEnd = _Animancer.Playable.PauseGraph; // 通常情况下,当我们播放一个新的动画时,OnEnd事件会被清除,但是因为在这个例子中只有一个动画,所以我们让它继续播放并暂停/取消暂停渲染. }
/************************************************************************************************************************/ protected void Update() { // W or UpArrow = 1. // S or DownArrow = -1. // Otherwise 0. var movement = Input.GetAxisRaw("Vertical"); if (movement != 0) { PlayMove(); // Since we don't have animations for moving backwards, just use the input as their speed so that // moving backwards simply plays the animation backwards. _Animancer.States.Current.Speed = movement; // PlayMove could return the AnimancerState it plays, but using the CurrentState saves a bit of effort. } else { // If we aren't moving, return to idle. _Animancer.Play(_Idle, 0.25f); } }
// Start is called before the first frame update void Start() { animancer.Play(idle); controller = gameObject.GetComponent <CharacterController>(); velocity = Vector3.zero; gravity = new Vector3(0f, -3.3f, 0f); moveSpeed = 3f; turnSpeed = 100.0f; jumpSpeed = 150.0f; fallSpeed = -4f; drag = 0.85f; jumping = false; }
/************************************************************************************************************************/ private void Awake() { // Apply the starting state and pause the graph. var state = _Animancer.Play(_Open); state.NormalizedTime = _Openness; _Animancer.Evaluate(); _Animancer.Playable.PauseGraph(); // And also pause it whenever the animation finishes to save performance. state.Events.OnEnd = _Animancer.Playable.PauseGraph; // Normally the OnEnd event would be cleared whenever we play a new animation, but since there is only one // animation in this example we just leave it playing and pause/unpause the graph instead. }
/************************************************************************************************************************/ private void Awake() { // Make sure both curves are actually being extracted from the same animation. Debug.Assert(_LeftFootWeight.Clip == _RightFootWeight.Clip); // Play that animation (ExposedCurve has an implicit cast to use its Clip). _Animancer.Play(_LeftFootWeight); // Tell Unity that OnAnimatorIK needs to be called every frame. ApplyAnimatorIK = true; // Get the foot bones. _LeftFoot = _Animancer.Animator.GetBoneTransform(HumanBodyBones.LeftFoot); _RightFoot = _Animancer.Animator.GetBoneTransform(HumanBodyBones.RightFoot); }
/************************************************************************************************************************/ private void OnEnable() { // Since Float1ControllerTransition is a Transition Asset which can be shared among multiple objects, we // cannot simply access the _Controller.Transition.State whenever we want because it will only hold the // most recently played state (which will only be correct for one instance but not the others). // So instead, we grab the state right after playing it. _Animancer.Play(_Controller); _State = _Controller.Transition.State; // The state returned by the Play method would do the same thing, but it only returns a base AnimancerState // and we need a Float1ControllerState to access its Parameter property below so we would need to cast it: // _State = (Float1ControllerState)_Animancer.Play(_Controller); }
/************************************************************************************************************************/ /// <summary> /// Enter the swing state and play the appropriate animation. /// <para></para> /// This method is <c>virtual</c> so that <see cref="GolfHitControllerAnimationSimple"/> can <c>override</c> it /// to register the <see cref="HitBall"/> method to be called by the event. /// </summary> protected virtual void StartSwing() { _State = State.Swing; _Animancer.Play(_Swing); }
/************************************************************************************************************************/ private void OnEnable() { _Animancer.Play(_Controller); }