Interface ISpriteEditorDataProvider
An interface that allows Sprite Editor Window to edit Sprite data for user custom importer.
Namespace: UnityEditor.U2D.Sprites
Assembly: Unity.2D.Sprite.Editor.dll
Syntax
public interface ISpriteEditorDataProvider
Remarks
Use this interface to edit Sprite data.
using UnityEditor;
using UnityEditor.U2D.Sprites;
using UnityEngine;
public class PivotUpdater : AssetPostprocessor
{
private void OnPreprocessTexture()
{
var factory = new SpriteDataProviderFactories();
factory.Init();
var dataProvider = factory.GetSpriteEditorDataProviderFromObject(assetImporter);
dataProvider.InitSpriteEditorDataProvider();
SetPivot(dataProvider, new Vector2(0.5f, 0.5f));
dataProvider.Apply();
}
static void SetPivot(ISpriteEditorDataProvider dataProvider, Vector2 pivot)
{
var spriteRects = dataProvider.GetSpriteRects();
foreach (var rect in spriteRects)
{
rect.pivot = pivot;
rect.alignment = SpriteAlignment.Custom;
}
dataProvider.SetSpriteRects(spriteRects);
}
}</code></pre>
Properties
pixelsPerUnit
The number of pixels in the sprite that correspond to one unit in world space.
Declaration
float pixelsPerUnit { get; }
Property Value
Type | Description |
---|---|
float |
spriteImportMode
SpriteImportMode to indicate how Sprite data will be imported.
Declaration
SpriteImportMode spriteImportMode { get; }
Property Value
Type | Description |
---|---|
SpriteImportMode |
targetObject
The object that this data provider is acquiring its data from.
Declaration
Object targetObject { get; }
Property Value
Type | Description |
---|---|
Object |
Methods
Apply()
Applying any changed data.
Declaration
void Apply()
GetDataProvider<T>()
Gets other data providers that might be supported by ISpriteEditorDataProvider.targetObject.
Declaration
T GetDataProvider<T>() where T : class
Returns
Type | Description |
---|---|
T | Data provider type. |
Type Parameters
Name | Description |
---|---|
T | The data provider type to acquire. |
GetSpriteRects()
Returns an array of SpriteRect representing Sprite data the provider has.
Declaration
SpriteRect[] GetSpriteRects()
Returns
Type | Description |
---|---|
SpriteRect[] | Array of SpriteRect. |
HasDataProvider(Type)
Queries if ISpriteEditorDataProvider.targetObject supports the data provider type.
Declaration
bool HasDataProvider(Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Data provider type. |
Returns
Type | Description |
---|---|
bool | True if supports, false otherwise. |
InitSpriteEditorDataProvider()
Allows the data provider to initialize any data if needed.
Declaration
void InitSpriteEditorDataProvider()
RegisterDataChangeCallback(Action<ISpriteEditorDataProvider>)
Register callback for data change.
Declaration
void RegisterDataChangeCallback(Action<ISpriteEditorDataProvider> action)
Parameters
Type | Name | Description |
---|---|---|
Action<ISpriteEditorDataProvider> | action | Callback delegate. |
SetSpriteRects(SpriteRect[])
Sets the data provider's current SpriteRect.
Declaration
void SetSpriteRects(SpriteRect[] spriteRects)
Parameters
Type | Name | Description |
---|---|---|
SpriteRect[] | spriteRects | Updated array of SpriteRect. |
UnregisterDataChangeCallback(Action<ISpriteEditorDataProvider>)
Unregister callback for data change.
Declaration
void UnregisterDataChangeCallback(Action<ISpriteEditorDataProvider> action)
Parameters
Type | Name | Description |
---|---|---|
Action<ISpriteEditorDataProvider> | action | Callback delegate. |