Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool AddEvent(string clipName, float time, string functionName) {
- return AddEvent<Object>(clipName, time, functionName, null);
- }
- bool AddEvent<T>(string clipName, float time, string functionName, T parameter)
- {
- bool found=false;
- AnimationClip animationClip=null;
- foreach (AnimationClip aniclip in ani.runtimeAnimatorController.animationClips)
- if (aniclip.name.Equals(clipName)) {
- animationClip=aniclip;
- found=true;
- break;
- }
- if (found==false) return false;
- AnimationEvent animationEvent = new AnimationEvent();
- animationEvent.functionName = functionName;
- animationEvent.time = time;
- if (!(parameter is Object && parameter==null))
- switch (parameter)
- {
- case int p: animationEvent.intParameter=p; break;
- case float p: animationEvent.floatParameter=p; break;
- case string p: animationEvent.stringParameter=p; break;
- case Object p: animationEvent.objectReferenceParameter=p; break;
- default:
- break;
- }
- animationClip.AddEvent(animationEvent);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement