mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Use IHasRendererObject.
This commit is contained in:
parent
f6a98b0f43
commit
4e3cf15acb
@ -37,13 +37,9 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to get the region (image) of a renderable attachment. If the attachment is not renderable, it returns null.</summary>
|
/// Tries to get the region (image) of a renderable attachment. If the attachment is not renderable, it returns null.</summary>
|
||||||
public static AtlasRegion GetRegion (this Attachment attachment) {
|
public static AtlasRegion GetRegion (this Attachment attachment) {
|
||||||
var regionAttachment = attachment as RegionAttachment;
|
var renderableAttachment = attachment as IHasRendererObject;
|
||||||
if (regionAttachment != null)
|
if (renderableAttachment != null)
|
||||||
return regionAttachment.RendererObject as AtlasRegion;
|
return renderableAttachment.RendererObject as AtlasRegion;
|
||||||
|
|
||||||
var meshAttachment = attachment as MeshAttachment;
|
|
||||||
if (meshAttachment != null)
|
|
||||||
return meshAttachment.RendererObject as AtlasRegion;
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -418,7 +414,7 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
var newAttachment = originalAttachment.GetClone(true);
|
var newAttachment = originalAttachment.GetClone(true);
|
||||||
if (IsRenderable(newAttachment)) {
|
if (IsRenderable(newAttachment)) {
|
||||||
|
|
||||||
var region = newAttachment.GetAtlasRegion();
|
var region = newAttachment.GetRegion();
|
||||||
int existingIndex;
|
int existingIndex;
|
||||||
if (existingRegions.TryGetValue(region, out existingIndex)) {
|
if (existingRegions.TryGetValue(region, out existingIndex)) {
|
||||||
regionIndexes.Add(existingIndex); // Store the region index for the eventual new attachment.
|
regionIndexes.Add(existingIndex); // Store the region index for the eventual new attachment.
|
||||||
@ -503,7 +499,7 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
var newAttachment = kvp.Value.GetClone(true);
|
var newAttachment = kvp.Value.GetClone(true);
|
||||||
if (IsRenderable(newAttachment)) {
|
if (IsRenderable(newAttachment)) {
|
||||||
|
|
||||||
var region = newAttachment.GetAtlasRegion();
|
var region = newAttachment.GetRegion();
|
||||||
int existingIndex;
|
int existingIndex;
|
||||||
if (existingRegions.TryGetValue(region, out existingIndex)) {
|
if (existingRegions.TryGetValue(region, out existingIndex)) {
|
||||||
regionIndexes.Add(existingIndex); // Store the region index for the eventual new attachment.
|
regionIndexes.Add(existingIndex); // Store the region index for the eventual new attachment.
|
||||||
@ -719,20 +715,6 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tries to get the backing AtlasRegion of an attachment if it is renderable. Returns null for non-renderable attachments.</summary>
|
|
||||||
static AtlasRegion GetAtlasRegion (this Attachment a) {
|
|
||||||
var regionAttachment = a as RegionAttachment;
|
|
||||||
if (regionAttachment != null)
|
|
||||||
return (regionAttachment.RendererObject) as AtlasRegion;
|
|
||||||
|
|
||||||
var meshAttachment = a as MeshAttachment;
|
|
||||||
if (meshAttachment != null)
|
|
||||||
return (meshAttachment.RendererObject) as AtlasRegion;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convenience method for getting the main texture of the material of the page of the region.</summary>
|
/// Convenience method for getting the main texture of the material of the page of the region.</summary>
|
||||||
static Texture2D GetMainTexture (this AtlasRegion region) {
|
static Texture2D GetMainTexture (this AtlasRegion region) {
|
||||||
|
|||||||
@ -212,13 +212,10 @@ namespace Spine.Unity {
|
|||||||
#region Attachments
|
#region Attachments
|
||||||
public static Material GetMaterial (this Attachment a) {
|
public static Material GetMaterial (this Attachment a) {
|
||||||
object rendererObject = null;
|
object rendererObject = null;
|
||||||
var regionAttachment = a as RegionAttachment;
|
var renderableAttachment = a as IHasRendererObject;
|
||||||
if (regionAttachment != null)
|
if (renderableAttachment != null) {
|
||||||
rendererObject = regionAttachment.RendererObject;
|
rendererObject = renderableAttachment.RendererObject;
|
||||||
|
}
|
||||||
var meshAttachment = a as MeshAttachment;
|
|
||||||
if (meshAttachment != null)
|
|
||||||
rendererObject = meshAttachment.RendererObject;
|
|
||||||
|
|
||||||
if (rendererObject == null)
|
if (rendererObject == null)
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user