usingUnityengine;usingSystem.Collections;usingUnityeditor; Public classclipeventeditor:editorwindow{/// <summary> ///The MenuItem property allows you to add menu items to the main menu and the Inspector context menu///The MenuItem property turns any static function into a menu command. Only static functions can use this MenuItem property. ///You can use the specified character to create a hotkey:% (Ctrl on Windows, CMD on OS x), # (Shift), & (Alt), _ (no modifier key). ///For example, create a menu hotkey for shift-alt-g using gameobject/do Something #&g. ///Create a menu hotkey g and no modifier keys (key combinations), use gameobject/do Something _g. ///The hotkey text must be preceded by an empty characters (Gameobject/do_g will not be interpreted as a hotkey, but gameobject/do _g so, notice that there are spaces in front of _g). /// ///Note: This is an editor class and if you want to use it you need to put it under the Assets/editor folder in the project directory. ///the editor class is under the Unityeditor namespace. So when using C # scripts, you need to precede the script with a "using Unityeditor" reference. /// </summary>[MenuItem ("tools/clipeventeditor%1",false)]//shortcut key ctrl+1 Static voidShow () {//static function getwindow.<t> (Utility:bool, Title:string, Focus:bool): T//returns the current First editor window of type T on the screen. //if not, creates and displays a new window and returns an instance of it. //utility is set to true to create a floating window; For dummies, create a standard window. //Title if GetWindow creates a new window, it gets the title. If this value is null, the class title is used. Getwindow<clipeventeditor> (true,"Editor"); } PublicAnimationclip Clip; PublicGameobject OBJ; voidOngui () {Guilayout.label ("Animation Event Editor"); //Editorguilayout.objectfield: Make an Object field. Objects can be specified either by dragging objects or by selecting objects from the Object picker. Clip = (animationclip) Editorguilayout.objectfield (clip,typeof(Animationclip),true); OBJ= (gameobject) Editorguilayout.objectfield (OBJ,typeof(Gameobject),true); if(Clip) {varEvents =animationutility.getanimationevents (Clip); if(Guilayout.button ("Show hidden Events")) { for(inti =0; i < events.length; i++) { if(float. Isinfinity (Events[i].time)) {Events[i].time=0; } } //TODO ... Save Changes } } }}
Editorwindow and MenuItem