The Unity editor learns to create its own window

Source: Internet
Author: User

Another physical activity, the resources to move. Specific tasks I will not reveal, anyway, is the bottom of the management of the capital and other things.

In order to simplify the operation, I still insist on writing a plug-in, and then feel good to make a small window of their own, wrote a small editor plugin.

OK, this small window completes the function is very simple, is moves the resource to a certain folder. Well, the code is shared as follows,

If you look at the effect, just put it in the project file and restart unity. The code is simple and the comment is not written:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingUnityeditor;usingUnityengine;usingSystem.IO; Public classonekeymove:editorwindow{ PublicRespath Respath; voidStart () {if(respath==NULL) {Respath=NewRespath (); }} [MenuItem ("myutil/One-click Move")]     Public Static voidInit () {if(Resources.findobjectsoftypeall<onekeymove> (). Length = =0)        {            varWin = scriptableobject.createinstance<onekeymove>(); Win.title="One-click Move"; Win.        Show (); }    }     Public voidOngui () {if(Respath = =NULL) {Respath=NewRespath (); } Editorguilayout.labelfield ("Moving Files", Editorstyles.boldlabel);        Editorguilayout.space ();        Guilayout.beginhorizontal (); Editorguilayout.labelfield ("Current File", Guilayout.width ( the)); Rect Firstrect= Editorguilayout.getcontrolrect (Guilayout.width ( $)); Respath._firstfile=Editorgui.textfield (Firstrect, respath._firstfile); if(Event.current.type = = Eventtype.dragupdated | | Event.current.type = = eventtype.dragexited) &&firstrect.contains (Event.current.mousePosition)) {            if(Draganddrop.paths! =NULL&& DragAndDrop.paths.Length >0)            {                stringSfxpath = draganddrop.paths[0]; if(!string. IsNullOrEmpty (sfxpath) && Event.current.type = =eventtype.dragupdated) {Draganddrop.acceptdrag (); Respath._firstfile=Sfxpath;        }}} guilayout.endhorizontal ();        Editorguilayout.space ();        Guilayout.beginhorizontal (); Editorguilayout.labelfield ("Target", Guilayout.width ( the)); Rect Secondrect= Editorguilayout.getcontrolrect (Guilayout.width ( $)); Respath._secondfile=Editorgui.textfield (secondrect, respath._secondfile); if(Event.current.type = = Eventtype.dragupdated | | Event.current.type = = eventtype.dragexited) &&secondrect.contains (Event.current.mousePosition)) {            if(Draganddrop.paths! =NULL&& DragAndDrop.paths.Length >0)            {                stringSfxpath = draganddrop.paths[0]; if(!string. IsNullOrEmpty (sfxpath) && Event.current.type = =eventtype.dragupdated) {Draganddrop.acceptdrag (); Respath._secondfile=Sfxpath;        }}} guilayout.endhorizontal ();        Editorguilayout.space (); if(Guilayout.button ("One-click Move"))        {            stringResname = Respath._firstfile.remove (0, Respath._firstfile.lastindexof ('/') +1);                       Debug.Log (Resname); stringTargetPath = Respath._secondfile +"/layout/"+Resname; stringRealpath = Application.dataPath.Substring (0, Application.dataPath.LastIndexOf ('/'))+"/"+respath._secondfile +"/layout"; if(!directory.exists (Realpath))            {directory.createdirectory (Realpath);            } Assetdatabase.refresh ();            Debug.Log (TargetPath);        Assetdatabase.moveasset (Respath._firstfile, TargetPath);            } editorguilayout.space (); }}[serializable] Public classRespath { Public string_firstfile="";  Public string_secondfile="";}

The Unity editor learns to create its own window

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.