Experimental: this API is experimental and might be changed or removed in the future.

SpriteEditorModuleBase

class in UnityEditor.Experimental.U2D

切换到手册

描述

Sprite Editor 窗口自定义模块继承内容的基类。

Sprite Editor 窗口功能可通过提供自定义模块进行扩展。通过继承 SpriteEditorModuleBase,用户将能从 Sprite Editor 窗口激活模块的功能。

using UnityEditor.Experimental.U2D;
using UnityEngine;

public class MySpriteEditorCustomModule : SpriteEditorModuleBase { // The name of the module that will be shown in Sprite Editor Window drop down menu public override string moduleName { get { return "MySpriteEditorCustomModule"; } }

// This is called when user clicks on the Apply or Revert button in Sprite Editor Window public override bool ApplyRevert(bool apply) { return true; }

// Indicates if the module can be activated with the current ISpriteEditor state public override bool CanBeActivated() { return true; }

// Called after SpriteEditorWindow drawn the sprite. // UnityEditor.Handles draw calls will operate in Texture space public override void DoMainGUI() {}

// Draw user tool bar public override void DoToolbarGUI(Rect drawArea) {}

// Called when the module is activated by user public override void OnModuleActivate() {}

// Called when user switches to another module public override void OnModuleDeactivate() {}

// Any last GUI draw. This is in the SpriteEditorWindow's space. // Any GUI draw will appear on top public override void DoPostGUI() {} }

变量

moduleName将显示在 Sprite Editor 窗口中的模块名称。
spriteEditor将模块实例化的 ISpriteEditor 实例。

公共函数

ApplyRevert这将在用户单击 Sprite Editor 窗口中的 Apply 或 Revert 按钮时调用。
CanBeActivated表明模块能否通过当前的 ISpriteEditor 状态激活。
DoMainGUI实现此方法以在 Sprite Editor 窗口中绘制。
DoPostGUI实现此方法以在 Sprite Editor 窗口中绘制小部件。
DoToolbarGUI实现此方法以创建自定义工具栏。
OnModuleActivate当用户激活模块时调用此方法。
OnModuleDeactivate当用户切换至其他模块时调用此方法。