Extended Editor (5)

Source: Internet
Author: User

Listen to events

This is the last section to expand the project view. Here we will introduce how to use programs to constrain Resources in the project view. For example, you can use a program to determine whether the original location of the resource and the location to be moved are legal, so as to determine whether the current move can be blocked. Unity provides a base class for listening.

Using unityengine; using unityeditor; public class script_04: unityeditor. assetmodificationprocessor {[initializeonloadmethod] Static void initializeonloadmethod () {// globally monitors whether resources in the project view change (add, delete, and move) editorapplication. projectchanged + = delegate () {debug. log ("change") ;};}// listener "double-click the left mouse button to open the resource" event public static bool isopenforedit (string assetpath, out string message) {message = NULL; debug. logformat ("Assetpath: {0}", assetpath); // true indicates that the resource can be opened. False indicates that the resource cannot be opened in unity and return true ;} // listen to "resource is about to be created" event public static void onwillcreateasset (string path) {debug. logformat ("Path: {0}", PATH) ;}// listener "resource to be saved soon" event public static string [] onwillsaveasset (string [] paths) {If (paths! = NULL) {debug. logformat ("Path: {0}", String. join (",", paths);} return paths;} // listen to "resource to be moved soon" event public static assetmoveresult onwillmoveasset (string oldpath, string newpath) {debug. logformat ("from: {0} to: {1}", oldpath, newpath); // assermoveresult. didmove return assetmoveresult. didmove;} // listen to "resource to be deleted soon" event public static assetdeleteresult onwilldeleteasset (string assetpath, removeassetoptions opint) {debug. logformat ("delete: {0}", assetpath); // assetdeleteresult. didnotdelete indicates that the resource can be deleted. Return assetdeleteresult. didnotdelete ;}}

This class must inherit unityeditor. assetmodificationprocessor, and then rewrite the method for creating, moving, saving, and deleting listening resources to process their own special logic.

Extended Editor (5)

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.