Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

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

RequireSpriteDataProviderAttribute

class in UnityEditor.Experimental.U2D

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Use this attribute on a class that inherits from SpriteEditorModuleBase to indicate what data provider it needs.

When you use this attribute, Sprite Editor Window will only make the module available for selection if ISpriteEditorDataProvider.HasDataProvider returns true for all the data providers the module needs.

#pragma strict
@RequireSpriteDataProvider(ISpriteOutlineDataProvider, ITextureDataProvider)
public class MySpriteEditorCustomModule extends SpriteEditorModuleBase {
	StringmoduleName {
		return "MySpriteEditorCustomModule";
	}
	public override function ApplyRevert(apply: boolean) {
		return true;
	}
	public override function CanBeActivated() {
		return true;
	}
	public override function DoMainGUI() {
	}
	public override function DoToolbarGUI(drawArea: Rect) {
	}
	public override function OnModuleActivate() {
		var outlineProvider: var = spriteEditor.GetDataProvider.<ISpriteOutlineDataProvider>();
		var spriteRects: var = spriteEditor.GetDataProvider.<ISpriteEditorDataProvider>().GetSpriteRects();
		for (var spriteRect: var in spriteRects) {
			// Access outline data
			Debug.Log(outlineProvider.GetOutlines(spriteRect.spriteID));
		}
	}
	public override function OnModuleDeactivate() {
	}
	public override function DoPostGUI() {
	}
}
using UnityEditor.Experimental.U2D;
using UnityEngine;

[RequireSpriteDataProvider(typeof(ISpriteOutlineDataProvider), typeof(ITextureDataProvider))] public class MySpriteEditorCustomModule : SpriteEditorModuleBase { public override string moduleName { get { return "MySpriteEditorCustomModule"; } }

public override bool ApplyRevert(bool apply) { return true; }

public override bool CanBeActivated() { return true; }

public override void DoMainGUI() {}

public override void DoToolbarGUI(Rect drawArea) {}

public override void OnModuleActivate() { var outlineProvider = spriteEditor.GetDataProvider<ISpriteOutlineDataProvider>(); var spriteRects = spriteEditor.GetDataProvider<ISpriteEditorDataProvider>().GetSpriteRects(); foreach (var spriteRect in spriteRects) { // Access outline data Debug.Log(outlineProvider.GetOutlines(spriteRect.spriteID)); } }

public override void OnModuleDeactivate() {}

public override void DoPostGUI() {} }

Constructors

RequireSpriteDataProviderAttributeUse the attribute to indicate the custom data provider that SpriteEditorBaseModule needs.

Did you find this page useful? Please give it a rating: