This commit is contained in:
badlogic 2019-10-15 16:16:28 +02:00
commit d31cbcc091
32 changed files with 5959 additions and 38 deletions

View File

@ -103,6 +103,7 @@
* Removed dependency on `RHI`, `RenderCore`, and `ShaderCore`.
* Re-importing atlases and their textures now works consistently in all situations.
* Added mix-and-match example to demonstrate the new Skin API.
* Materials on `SkeletonRendererComponent` are now blueprint read and writeable. This allows setting dynamic material instances at runtime
## C# ##
* **Breaking changes**
@ -185,6 +186,7 @@
by e.g. the LWRP renderer, leading to incorrect draw order (e.g. "A1 B A2" changed to "A1A2 B").
You can leave this parameter disabled when everything is drawn correctly to save the additional performance cost.
* **Additional Timeline features.** SpineAnimationStateClip now provides a `Speed Multiplier`, a start time offset parameter `Clip In`, support for blending successive animations by overlapping tracks. An additional `Use Blend Duration` parameter *(defaults to true)* allows for automatic synchronisation of MixDuration with the current overlap blend duration. An additional Spine preferences parameter `Use Blend Duration` has been added which can be disabled to default to the previous behaviour before this update.
* Additional `SpriteMask and RectMask2D` example scene added for demonstration of mask setup and interaction.
* **Changes of default values**
* `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`.

View File

@ -40,7 +40,7 @@ void USpineBoneDriverComponent::BeginPlay () {
}
void USpineBoneDriverComponent::BeforeUpdateWorldTransform(USpineSkeletonComponent* skeleton) {
if (skeleton == lastBoundComponent) {
if (skeleton == lastBoundComponent && skeleton) {
if (UseComponentTransform) {
skeleton->SetBoneWorldPosition(BoneName, GetComponentLocation());
}
@ -56,7 +56,7 @@ void USpineBoneDriverComponent::TickComponent (float DeltaTime, ELevelTick TickT
if (Target) {
USpineSkeletonComponent* skeleton = static_cast<USpineSkeletonComponent*>(Target->GetComponentByClass(USpineSkeletonComponent::StaticClass()));
if (skeleton != lastBoundComponent) {
if (skeleton != lastBoundComponent && skeleton) {
// if (lastBoundComponent) lastBoundComponent->BeforeUpdateWorldTransform.RemoveAll(this);
if (!skeleton->BeforeUpdateWorldTransform.GetAllObjects().Contains(this))
skeleton->BeforeUpdateWorldTransform.AddDynamic(this, &USpineBoneDriverComponent::BeforeUpdateWorldTransform);

View File

@ -50,16 +50,16 @@ public:
void UpdateRenderer(USpineSkeletonComponent* Skeleton);
// Material Instance parents
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
UMaterialInterface* NormalBlendMaterial;
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
UMaterialInterface* AdditiveBlendMaterial;
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
UMaterialInterface* MultiplyBlendMaterial;
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadOnly)
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
UMaterialInterface* ScreenBlendMaterial;
// Need to hold on to the dynamic instances, or the GC will kill us while updating them

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 67f5d13210e654b4f89385bb61a0c96b
timeCreated: 1550658341
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -29,6 +29,10 @@
// Contributed by: Mitch Thompson
#if UNITY_2019_2_OR_NEWER
#define HINGE_JOINT_NEW_BEHAVIOUR
#endif
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
@ -158,9 +162,22 @@ namespace Spine.Unity.Examples {
joint.connectedAnchor = localPos;
joint.GetComponent<Rigidbody2D>().mass = joint.connectedBody.mass * massFalloffFactor;
#if HINGE_JOINT_NEW_BEHAVIOUR
float referenceAngle = (rbParent.transform.eulerAngles.z - t.eulerAngles.z + 360f) % 360f;
float minAngle = referenceAngle - rotationLimit;
float maxAngle = referenceAngle + rotationLimit;
if (maxAngle > 180f) {
minAngle -= 360f;
maxAngle -= 360f;
}
#else
float minAngle = - rotationLimit;
float maxAngle = rotationLimit;
#endif
joint.limits = new JointAngleLimits2D {
min = -rotationLimit,
max = rotationLimit
min = minAngle,
max = maxAngle
};
joint.useLimits = true;
}
@ -284,7 +301,7 @@ namespace Spine.Unity.Examples {
t.parent = transform;
t.localPosition = new Vector3(b.WorldX, b.WorldY, 0);
t.localRotation = Quaternion.Euler(0, 0, b.WorldRotationX - b.ShearX);
t.localScale = new Vector3(b.WorldScaleX, b.WorldScaleY, 0);
t.localScale = new Vector3(b.WorldScaleX, b.WorldScaleY, 1);
// MITCH: You left "todo: proper ragdoll branching"
var colliders = AttachBoundingBoxRagdollColliders(b, boneGameObject, skeleton, this.gravityScale);

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1042fbf38cbac704db44b9251e33ec19
folderAsset: yes
timeCreated: 1562070793
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -0,0 +1,74 @@
fileFormatVersion: 2
guid: eb942ce288aa1654dbf5ed0cad424cdc
timeCreated: 1550658271
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,272 @@
raptor-pma.png
size: 1024,512
format: RGBA8888
filter: Linear,Linear
repeat: none
back-arm
rotate: false
xy: 895, 295
size: 46, 25
orig: 46, 25
offset: 0, 0
index: -1
back-bracer
rotate: true
xy: 992, 216
size: 39, 28
orig: 39, 28
offset: 0, 0
index: -1
back-hand
rotate: false
xy: 594, 58
size: 36, 34
orig: 36, 34
offset: 0, 0
index: -1
back-knee
rotate: true
xy: 729, 86
size: 49, 67
orig: 49, 67
offset: 0, 0
index: -1
back-thigh
rotate: false
xy: 379, 2
size: 39, 24
orig: 39, 24
offset: 0, 0
index: -1
eyes-open
rotate: true
xy: 902, 194
size: 47, 45
orig: 47, 45
offset: 0, 0
index: -1
front-arm
rotate: false
xy: 945, 306
size: 48, 26
orig: 48, 26
offset: 0, 0
index: -1
front-bracer
rotate: false
xy: 949, 197
size: 41, 29
orig: 41, 29
offset: 0, 0
index: -1
front-hand
rotate: false
xy: 949, 266
size: 41, 38
orig: 41, 38
offset: 0, 0
index: -1
front-open-hand
rotate: false
xy: 875, 148
size: 43, 44
orig: 43, 44
offset: 0, 0
index: -1
front-thigh
rotate: true
xy: 793, 171
size: 57, 29
orig: 57, 29
offset: 0, 0
index: -1
gun
rotate: true
xy: 379, 28
size: 107, 103
orig: 107, 103
offset: 0, 0
index: -1
gun-nohand
rotate: false
xy: 487, 87
size: 105, 102
orig: 105, 102
offset: 0, 0
index: -1
head
rotate: false
xy: 807, 361
size: 136, 149
orig: 136, 149
offset: 0, 0
index: -1
lower-leg
rotate: false
xy: 827, 195
size: 73, 98
orig: 73, 98
offset: 0, 0
index: -1
mouth-grind
rotate: true
xy: 920, 145
size: 47, 30
orig: 47, 30
offset: 0, 0
index: -1
mouth-smile
rotate: true
xy: 992, 257
size: 47, 30
orig: 47, 30
offset: 0, 0
index: -1
neck
rotate: false
xy: 359, 114
size: 18, 21
orig: 18, 21
offset: 0, 0
index: -1
raptor-back-arm
rotate: false
xy: 653, 142
size: 82, 86
orig: 82, 86
offset: 0, 0
index: -1
raptor-body
rotate: false
xy: 2, 277
size: 632, 233
orig: 632, 233
offset: 0, 0
index: -1
raptor-front-arm
rotate: true
xy: 484, 4
size: 81, 102
orig: 81, 102
offset: 0, 0
index: -1
raptor-front-leg
rotate: false
xy: 2, 18
size: 191, 257
orig: 191, 257
offset: 0, 0
index: -1
raptor-hindleg-back
rotate: false
xy: 636, 295
size: 169, 215
orig: 169, 215
offset: 0, 0
index: -1
raptor-horn
rotate: false
xy: 195, 22
size: 182, 80
orig: 182, 80
offset: 0, 0
index: -1
raptor-horn-back
rotate: true
xy: 945, 334
size: 176, 77
orig: 176, 77
offset: 0, 0
index: -1
raptor-jaw
rotate: false
xy: 359, 137
size: 126, 138
orig: 126, 138
offset: 0, 0
index: -1
raptor-jaw-tooth
rotate: true
xy: 895, 322
size: 37, 48
orig: 37, 48
offset: 0, 0
index: -1
raptor-mouth-inside
rotate: true
xy: 949, 228
size: 36, 41
orig: 36, 41
offset: 0, 0
index: -1
raptor-saddle-strap-back
rotate: true
xy: 653, 86
size: 54, 74
orig: 54, 74
offset: 0, 0
index: -1
raptor-saddle-strap-front
rotate: false
xy: 594, 94
size: 57, 95
orig: 57, 95
offset: 0, 0
index: -1
raptor-saddle-w-shadow
rotate: false
xy: 195, 104
size: 162, 171
orig: 162, 171
offset: 0, 0
index: -1
raptor-tail-shadow
rotate: false
xy: 636, 230
size: 189, 63
orig: 189, 63
offset: 0, 0
index: -1
raptor-tongue
rotate: false
xy: 807, 295
size: 86, 64
orig: 86, 64
offset: 0, 0
index: -1
stirrup-back
rotate: true
xy: 952, 151
size: 44, 35
orig: 44, 35
offset: 0, 0
index: -1
stirrup-front
rotate: false
xy: 902, 243
size: 45, 50
orig: 45, 50
offset: 0, 0
index: -1
stirrup-strap
rotate: false
xy: 824, 147
size: 49, 46
orig: 49, 46
offset: 0, 0
index: -1
torso
rotate: false
xy: 737, 137
size: 54, 91
orig: 54, 91
offset: 0, 0
index: -1
visor
rotate: false
xy: 487, 191
size: 131, 84
orig: 131, 84
offset: 0, 0
index: -1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 237a4ac5be7ab634ea6b20fcab00aa97
timeCreated: 1562070793
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 KiB

View File

@ -0,0 +1,82 @@
fileFormatVersion: 2
guid: c1a5fbc2700be764fa3c6c44b2ed67a0
timeCreated: 1563964704
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a6b194f808b1af6499c93410e504af42, type: 3}
m_Name: raptor-pma_Atlas
m_EditorClassIdentifier:
atlasFile: {fileID: 4900000, guid: 237a4ac5be7ab634ea6b20fcab00aa97, type: 3}
materials:
- {fileID: 2100000, guid: 3d645292a7b9c7547bf7b14caa569410, type: 2}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: accb8bd06230af54b9b294a8ed032d3f
timeCreated: 1562070794
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,30 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: raptor-pma_Material
m_Shader: {fileID: 4800000, guid: 1e8a610c9e01c3648bac42585e5fc676, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: c1a5fbc2700be764fa3c6c44b2ed67a0, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Cutoff: 0.1
- _StencilComp: 8
- _StencilRef: 1
- _StraightAlphaInput: 0
m_Colors: []

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3d645292a7b9c7547bf7b14caa569410
timeCreated: 1562070793
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,30 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: raptor-pma_Material_InsideMask
m_Shader: {fileID: 4800000, guid: 1e8a610c9e01c3648bac42585e5fc676, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: c1a5fbc2700be764fa3c6c44b2ed67a0, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Cutoff: 0.1
- _StencilComp: 4
- _StencilRef: 1
- _StraightAlphaInput: 0
m_Colors: []

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 11b8e87884357884a8d31758fca91bb7
timeCreated: 1562070882
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,30 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: raptor-pma_Material_OutsideMask
m_Shader: {fileID: 4800000, guid: 1e8a610c9e01c3648bac42585e5fc676, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: c1a5fbc2700be764fa3c6c44b2ed67a0, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Cutoff: 0.1
- _StencilComp: 5
- _StencilRef: 1
- _StraightAlphaInput: 0
m_Colors: []

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4bbf1af7150ed574095b8679b9a72db3
timeCreated: 1562070873
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c272ebc04370d3d4d81beb5917e6abca
timeCreated: 1562070793
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f1b3b4b945939a54ea0b23d3396115fb, type: 3}
m_Name: raptor-pro_SkeletonData
m_EditorClassIdentifier:
atlasAssets:
- {fileID: 11400000, guid: accb8bd06230af54b9b294a8ed032d3f, type: 2}
scale: 0.01
skeletonJSON: {fileID: 4900000, guid: c272ebc04370d3d4d81beb5917e6abca, type: 3}
skeletonDataModifiers: []
fromAnimation: []
toAnimation: []
duration: []
defaultMix: 0.2
controller: {fileID: 9100000, guid: 6125809f19e57af43904a3b3971f9560, type: 2}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 784054e42b1ea374cb535eaf51bf4369
timeCreated: 1562070794
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -310,16 +310,37 @@ namespace Spine.Unity.AttachmentTools {
}
/// <summary>
/// Creates and populates a duplicate skin with cloned attachments that are backed by a new packed texture atlas comprised of all the regions from the original skin.</summary>
/// <remarks>GetRepackedSkin is an expensive operation, preferably call it at level load time. No Spine.Atlas object is created so there is no way to find AtlasRegions except through the Attachments using them.</remarks>
public static Skin GetRepackedSkin (this Skin o, string newName, Material materialPropertySource, out Material outputMaterial, out Texture2D outputTexture, int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps, bool useOriginalNonrenderables = true) {
return GetRepackedSkin(o, newName, materialPropertySource.shader, out outputMaterial, out outputTexture, maxAtlasSize, padding, textureFormat, mipmaps, materialPropertySource, useOriginalNonrenderables);
/// Creates and populates a duplicate skin with cloned attachments that are backed by a new packed texture atlas
/// comprised of all the regions from the original skin.</summary>
/// <remarks>GetRepackedSkin is an expensive operation, preferably call it at level load time.
/// No Spine.Atlas object is created so there is no way to find AtlasRegions except through the Attachments using them.</remarks>
/// <param name="additionalTexturePropertyIDsToCopy">Optional additional textures (such as normal maps) to copy while repacking.
/// To copy e.g. the main texture and normal maps, pass 'new int[] { Shader.PropertyToID("_BumpMap") }' at this parameter.</param>
/// <param name="additionalOutputTextures">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
/// this array will be filled with the resulting repacked texture for every property,
/// just as the main repacked texture is assigned to <c>outputTexture</c>.</param>
public static Skin GetRepackedSkin (this Skin o, string newName, Material materialPropertySource, out Material outputMaterial, out Texture2D outputTexture,
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
bool useOriginalNonrenderables = true, bool clearCache = false,
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null) {
return GetRepackedSkin(o, newName, materialPropertySource.shader, out outputMaterial, out outputTexture,
maxAtlasSize, padding, textureFormat, mipmaps, materialPropertySource,
clearCache, useOriginalNonrenderables, additionalTexturePropertyIDsToCopy, additionalOutputTextures);
}
/// <summary>
/// Creates and populates a duplicate skin with cloned attachments that are backed by a new packed texture atlas comprised of all the regions from the original skin.</summary>
/// <remarks>GetRepackedSkin is an expensive operation, preferably call it at level load time. No Spine.Atlas object is created so there is no way to find AtlasRegions except through the Attachments using them.</remarks>
public static Skin GetRepackedSkin (this Skin o, string newName, Shader shader, out Material outputMaterial, out Texture2D outputTexture, int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps, Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true) {
/// Creates and populates a duplicate skin with cloned attachments that are backed by a new packed texture atlas
/// comprised of all the regions from the original skin.</summary>
/// <remarks>GetRepackedSkin is an expensive operation, preferably call it at level load time.
/// No Spine.Atlas object is created so there is no way to find AtlasRegions except through the Attachments using them.</remarks>
public static Skin GetRepackedSkin (this Skin o, string newName, Shader shader, out Material outputMaterial, out Texture2D outputTexture,
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true,
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null) {
outputTexture = null;
if (o == null) throw new System.NullReferenceException("Skin was null");
var skinAttachments = o.Attachments;
var newSkin = new Skin(newName);
@ -333,7 +354,12 @@ namespace Spine.Unity.AttachmentTools {
// Collect all textures from the attachments of the original skin.
var repackedAttachments = new List<Attachment>();
var texturesToPack = new List<Texture2D>();
int numTextureParamsToRepack = 1 + (additionalTexturePropertyIDsToCopy == null ? 0 : additionalTexturePropertyIDsToCopy.Length);
additionalOutputTextures = (additionalTexturePropertyIDsToCopy == null ? null : new Texture2D[additionalTexturePropertyIDsToCopy.Length]);
List<Texture2D>[] texturesToPackAtParam = new List<Texture2D>[numTextureParamsToRepack];
for (int i = 0; i < numTextureParamsToRepack; ++i) {
texturesToPackAtParam[i] = new List<Texture2D>();
}
var originalRegions = new List<AtlasRegion>();
int newRegionIndex = 0;
@ -350,7 +376,10 @@ namespace Spine.Unity.AttachmentTools {
regionIndexes.Add(existingIndex); // Store the region index for the eventual new attachment.
} else {
originalRegions.Add(region);
texturesToPack.Add(region.ToTexture()); // Add the texture to the PackTextures argument
for (int i = 0; i < numTextureParamsToRepack; ++i) {
Texture2D regionTexture = (i == 0 ? region.ToTexture() : region.ToTexture(texturePropertyId : additionalTexturePropertyIDsToCopy[i - 1]));
texturesToPackAtParam[i].Add(regionTexture); // Add the texture to the PackTextures argument
}
existingRegions.Add(region, newRegionIndex); // Add the region to the dictionary of known regions
regionIndexes.Add(newRegionIndex); // Store the region index for the eventual new attachment.
newRegionIndex++;
@ -363,26 +392,37 @@ namespace Spine.Unity.AttachmentTools {
}
}
// Fill a new texture with the collected attachment textures.
var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize, textureFormat, mipmaps);
newTexture.mipMapBias = AtlasUtilities.DefaultMipmapBias;
if (texturesToPack.Count > 0) {
var sourceTexture = texturesToPack[0];
newTexture.CopyTextureAttributesFrom(sourceTexture);
}
newTexture.name = newName;
var rects = newTexture.PackTextures(texturesToPack.ToArray(), padding, maxAtlasSize);
// Rehydrate the repacked textures as a Material, Spine atlas and Spine.AtlasAttachments
var newMaterial = new Material(shader);
if (materialPropertySource != null) {
newMaterial.CopyPropertiesFromMaterial(materialPropertySource);
newMaterial.shaderKeywords = materialPropertySource.shaderKeywords;
}
newMaterial.name = newName;
newMaterial.mainTexture = newTexture;
Rect[] rects = null;
for (int i = 0; i < numTextureParamsToRepack; ++i) {
// Fill a new texture with the collected attachment textures.
var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize, textureFormat, mipmaps);
newTexture.mipMapBias = AtlasUtilities.DefaultMipmapBias;
var texturesToPack = texturesToPackAtParam[i];
if (texturesToPack.Count > 0) {
var sourceTexture = texturesToPack[0];
newTexture.CopyTextureAttributesFrom(sourceTexture);
}
newTexture.name = newName;
var rectsForTexParam = newTexture.PackTextures(texturesToPack.ToArray(), padding, maxAtlasSize);
if (i == 0) {
rects = rectsForTexParam;
newMaterial.mainTexture = newTexture;
outputTexture = newTexture;
}
else {
newMaterial.SetTexture(additionalTexturePropertyIDsToCopy[i - 1], newTexture);
additionalOutputTextures[i - 1] = newTexture;
}
}
var page = newMaterial.ToSpineAtlasPage();
page.name = newName;
@ -404,7 +444,6 @@ namespace Spine.Unity.AttachmentTools {
if (clearCache)
AtlasUtilities.ClearCache();
outputTexture = newTexture;
outputMaterial = newMaterial;
return newSkin;
}
@ -413,7 +452,16 @@ namespace Spine.Unity.AttachmentTools {
return Sprite.Create(ar.GetMainTexture(), ar.GetUnityRect(), new Vector2(0.5f, 0.5f), pixelsPerUnit);
}
static Dictionary<AtlasRegion, Texture2D> CachedRegionTextures = new Dictionary<AtlasRegion, Texture2D>();
struct IntAndAtlasRegionKey {
int i;
AtlasRegion region;
public IntAndAtlasRegionKey(int i, AtlasRegion region) {
this.i = i;
this.region = region;
}
}
static Dictionary<IntAndAtlasRegionKey, Texture2D> CachedRegionTextures = new Dictionary<IntAndAtlasRegionKey, Texture2D>();
static List<Texture2D> CachedRegionTexturesList = new List<Texture2D>();
public static void ClearCache () {
@ -426,19 +474,22 @@ namespace Spine.Unity.AttachmentTools {
/// <summary>Creates a new Texture2D object based on an AtlasRegion.
/// If applyImmediately is true, Texture2D.Apply is called immediately after the Texture2D is filled with data.</summary>
public static Texture2D ToTexture (this AtlasRegion ar, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) {
public static Texture2D ToTexture (this AtlasRegion ar, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
int texturePropertyId = 0) {
Texture2D output;
CachedRegionTextures.TryGetValue(ar, out output);
IntAndAtlasRegionKey cacheKey = new IntAndAtlasRegionKey(texturePropertyId, ar);
CachedRegionTextures.TryGetValue(cacheKey, out output);
if (output == null) {
Texture2D sourceTexture = ar.GetMainTexture();
Texture2D sourceTexture = texturePropertyId == 0 ? ar.GetMainTexture() : ar.GetTexture(texturePropertyId);
Rect r = ar.GetUnityRect();
int width = (int)r.width;
int height = (int)r.height;
output = new Texture2D(width, height, textureFormat, mipmaps) { name = ar.name };
output.CopyTextureAttributesFrom(sourceTexture);
AtlasUtilities.CopyTexture(sourceTexture, r, output);
CachedRegionTextures.Add(ar, output);
CachedRegionTextures.Add(cacheKey, output);
CachedRegionTexturesList.Add(output);
}
@ -577,6 +628,20 @@ namespace Spine.Unity.AttachmentTools {
return material.mainTexture as Texture2D;
}
/// <summary>
/// Convenience method for getting any texture of the material of the page of the region by texture property name.</summary>
static Texture2D GetTexture (this AtlasRegion region, string texturePropertyName) {
var material = (region.page.rendererObject as Material);
return material.GetTexture(texturePropertyName) as Texture2D;
}
/// <summary>
/// Convenience method for getting any texture of the material of the page of the region by texture property id.</summary>
static Texture2D GetTexture (this AtlasRegion region, int texturePropertyId) {
var material = (region.page.rendererObject as Material);
return material.GetTexture(texturePropertyId) as Texture2D;
}
static void CopyTextureAttributesFrom(this Texture2D destination, Texture2D source) {
destination.filterMode = source.filterMode;
destination.anisoLevel = source.anisoLevel;

View File

@ -7,7 +7,9 @@
"Unity.Timeline"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,