Event for script control of Animation

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.