Advertisement
Guest User

Untitled

a guest
Jun 20th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. bool AddEvent(string clipName, float time, string functionName) {
  2.     return AddEvent<Object>(clipName, time, functionName, null);
  3. }
  4. bool AddEvent<T>(string clipName, float time, string functionName, T parameter)
  5. {
  6.     bool found=false;
  7.     AnimationClip animationClip=null;
  8.     foreach (AnimationClip aniclip in ani.runtimeAnimatorController.animationClips)
  9.         if (aniclip.name.Equals(clipName)) {
  10.             animationClip=aniclip;
  11.             found=true;
  12.             break;
  13.         }
  14.     if (found==false) return false;
  15.  
  16.     AnimationEvent animationEvent = new AnimationEvent();
  17.     animationEvent.functionName = functionName;
  18.     animationEvent.time = time;
  19.     if (!(parameter is Object && parameter==null))
  20.         switch (parameter)
  21.         {
  22.             case int p: animationEvent.intParameter=p; break;
  23.             case float p: animationEvent.floatParameter=p; break;
  24.             case string p: animationEvent.stringParameter=p; break;
  25.             case Object p: animationEvent.objectReferenceParameter=p; break;
  26.             default:
  27.             break;
  28.         }
  29.     animationClip.AddEvent(animationEvent);
  30.  
  31.     return true;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement