-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsing AnimationEvent dynamicly
More file actions
78 lines (67 loc) · 2.12 KB
/
Using AnimationEvent dynamicly
File metadata and controls
78 lines (67 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Linq;
using UnityEngine;
namespace Temp
{
public class TestAnimationEvent : MonoBehaviour
{
[System.Serializable]
public class EventData
{
public string clipName;
public int maxFrame = 10;
public float time;
public string functionName="HelloKyle";
public string stringParameter;
public int intParameter;
public float floatParameter;
}
public EventData[] configList;
public string clipName;
public Animator TargetAnimator;
private void Start()
{
SetEvent();
}
[ContextMenu("DoSetEvent")]
void SetEvent()
{
float frameRate;
var clips = TargetAnimator.runtimeAnimatorController.animationClips;
var targetClip = clips.First(clip => clip.name == clipName);
frameRate = targetClip.frameRate;
foreach (var eventData in configList)
{
AnimationEvent evt=new AnimationEvent()
{
time = eventData.time/frameRate,
functionName = eventData.functionName,
stringParameter = eventData.stringParameter,
intParameter = eventData.intParameter,
floatParameter = eventData.floatParameter,
};
targetClip.AddEvent(evt);
}
}
/// <summary>
/// 动画事件只会调用从上到下找到的第一个符合functionName的函数,
/// </summary>
/// <param name="e"></param>
void HelloKyle (AnimationEvent e)
{
Debug.LogError("AnimationEvent ");
}
void HelloKyle(int data)
{
Debug.LogError("int data"+data);
}
void HelloKyle(float data)
{
Debug.LogError("float data"+data);
}
void HelloKyle(string data)
{
Debug.LogError("string data"+data);
}
}
}