mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
[unity] SpriteAttacher texture settings editor warning.
This commit is contained in:
parent
5726df0c60
commit
db36661be1
@ -45,11 +45,37 @@ namespace Spine.Unity.Modules {
|
|||||||
[SpineSlot] public string slot;
|
[SpineSlot] public string slot;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
void OnValidate () {
|
||||||
|
var skeletonComponent = GetComponent<ISkeletonComponent>();
|
||||||
|
var skeletonRenderer = skeletonComponent as SkeletonRenderer;
|
||||||
|
bool apma;
|
||||||
|
|
||||||
|
if (skeletonRenderer != null) {
|
||||||
|
apma = skeletonRenderer.pmaVertexColors;
|
||||||
|
} else {
|
||||||
|
var skeletonGraphic = skeletonComponent as SkeletonGraphic;
|
||||||
|
apma = skeletonGraphic != null && skeletonGraphic.SpineMeshGenerator.PremultiplyVertexColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apma) {
|
||||||
|
try {
|
||||||
|
sprite.texture.GetPixel(0, 0);
|
||||||
|
} catch (UnityException e) {
|
||||||
|
Debug.LogFormat("Texture of {0} ({1}) is not read/write enabled. SpriteAttacher requires this in order to work with a SkeletonRenderer that renders premultiplied alpha. Please check the texture settings.", sprite.name, sprite.texture.name);
|
||||||
|
UnityEditor.EditorGUIUtility.PingObject(sprite.texture);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
RegionAttachment attachment;
|
RegionAttachment attachment;
|
||||||
bool applyPMA;
|
bool applyPMA;
|
||||||
|
|
||||||
Dictionary<Texture, AtlasPage> atlasPageCache = new Dictionary<Texture, AtlasPage>();
|
static Dictionary<Texture, AtlasPage> atlasPageCache;
|
||||||
AtlasPage GetPageFor (Texture texture, Shader shader) {
|
static AtlasPage GetPageFor (Texture texture, Shader shader) {
|
||||||
|
if (atlasPageCache == null) atlasPageCache = new Dictionary<Texture, AtlasPage>();
|
||||||
AtlasPage atlasPage;
|
AtlasPage atlasPage;
|
||||||
atlasPageCache.TryGetValue(texture, out atlasPage);
|
atlasPageCache.TryGetValue(texture, out atlasPage);
|
||||||
if (atlasPage == null) {
|
if (atlasPage == null) {
|
||||||
@ -76,7 +102,7 @@ namespace Spine.Unity.Modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Shader attachmentShader = applyPMA ? Shader.Find(DefaultPMAShader) : Shader.Find(DefaultStraightAlphaShader);
|
Shader attachmentShader = applyPMA ? Shader.Find(DefaultPMAShader) : Shader.Find(DefaultStraightAlphaShader);
|
||||||
attachment = applyPMA ? sprite.ToRegionAttachmentPMAClone(attachmentShader) : sprite.ToRegionAttachment(GetPageFor(sprite.texture, attachmentShader));
|
attachment = applyPMA ? sprite.ToRegionAttachmentPMAClone(attachmentShader) : sprite.ToRegionAttachment(SpriteAttacher.GetPageFor(sprite.texture, attachmentShader));
|
||||||
skeletonComponent.Skeleton.FindSlot(slot).Attachment = attachment;
|
skeletonComponent.Skeleton.FindSlot(slot).Attachment = attachment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user