Skip to content

Commit 91ec121

Browse files
committed
Runtime 情况下新增事件无需重新绑定也能正常触发,删除Rebind
Rebind 会重置 Animator状态,所以能不用绝对不用它
1 parent d6add48 commit 91ec121

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

Assets/MecanimEventSystem/Runtime/CallbackListener.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
using Codice.CM.SEIDInfo;
21
using System;
32
using System.Collections.Generic;
4-
using System.Numerics;
5-
using UnityEditor;
63
using UnityEngine;
74
using static zFrame.Event.EventHandler;
85

96
namespace zFrame.Event
107
{
11-
//代码分析,编辑器下就把事件绑定好
12-
//Please use Editor.AnimationUtility to add persistent animation events to an animation clip
13-
//UnityEngine.AnimationClip:AddEvent(UnityEngine.AnimationEvent)
8+
[RequireComponent(typeof(Animator))]
149
public class CallbackListener : MonoBehaviour
1510
{
1611
Animator animator;
@@ -29,7 +24,8 @@ private void AnimatorEventCallBack(AnimationEvent ae)
2924
if (action != null)
3025
{
3126
action.Invoke(ae);
32-
if (action.Method.DeclaringType.Name == nameof(AnimationAwaiter)) // the callback which comes from AnimationAwaiter should be oneshot event.
27+
// the callback which comes from AnimationAwaiter should be oneshot event.
28+
if (action.Method.DeclaringType.Name == nameof(AnimationAwaiter))
3329
{
3430
actions.Remove(action);
3531
}

Assets/MecanimEventSystem/Runtime/EventHandler.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ public static void GenerateAnimationEvent(EventInfo eventInfo, int frame)
7474
messageOptions = SendMessageOptions.DontRequireReceiver, //回调未找到不提示
7575
};
7676
eventInfo.animationClip.AddEvent(varEvent); //绑定事件
77-
eventInfo.animator.Rebind(); //重新绑定动画器的所有动画的属性和网格数据。
78-
if (LogLevels.HasFlag(LogLevel.Info))
79-
{
80-
Debug.Log($"{nameof(EventHandler)}:完成 AnimationEvent 添加, 建议优先在编辑器下就把事件安插OK以避免动画机的重新绑定,see more ↓ \nClip Name = {eventInfo.animationClip.name} , frame = {frame} , time = {_time} ,Function Name = {func}");
81-
}
8277
}
8378

8479
/// <summary>数据重置,用于总管理类清理数据用</summary>

0 commit comments

Comments
 (0)