Because the action design often modifies the action, an animation event must be added after each change, so a script is directly written. Of course, a table can be created later, then, read from the table using the script and generate the corresponding animation event. Place the code in the assets/Editor directory. The reference code is as follows:
Using unityengine; using system. collections; using unityeditor; public class addeventstoanimations: monobehaviour {[menuitem ("assets/demo2/Add animations events")] // menu static void addevents () added to the editor () {float T = 0.03333f; int I = 0; string attack01str = "assets/my project/raw data/character/hero/Anis/attack01.anim"; const int nlen = 4; animationevent [] arr = new animationevent [nlen]; // set 3 points to add event int [] attack01time = new int [nLen-1] {, 40 }; // load the animation animationclip attack01clip = assetdatabase. loadmainassetatpath (attack01str) as animationclip; If (attack01clip = NULL) {debug. log ("attack 01 clip is null"); Return ;}// add event for (I = 0; I <attack01time. length; I ++) {animationevent attack01 = new animationevent (); attack01.functionname = "yyattack1"; attack01.time = T * attack01time [I]; arr [I] = attack01 ;} // here is the end event. Check whether you need the animationevent attack011 = new animationevent (); attack011.functionname = "yyattackend"; attack011.time = T * 70; identifier = "attack01 "; arr [I] = attack011; // use the editor function to set the animation event animationutility. setanimationevents (attack01clip, arr );}
Http://jiaowodouge.blog.163.com/blog/static/187245168201171142327625/