Stripped folder paths from atlas region names. Formatting.

This commit is contained in:
NathanSweet 2013-05-25 17:41:52 +02:00
parent cef7e46e5b
commit 9d4aff8da7
3 changed files with 42 additions and 79 deletions

View File

@ -4,24 +4,21 @@ using Spine;
// TODO: handle TPackerCW flip mode (probably not swap uv horizontaly)
/*
*/
public class tk2dSpineAttachmentLoader : AttachmentLoader {
/*
*/
private tk2dSpriteCollectionData sprites;
/*
*/
public tk2dSpineAttachmentLoader(tk2dSpriteCollectionData s) {
if(s == null) throw new ArgumentNullException("sprites cannot be null.");
sprites = s;
public tk2dSpineAttachmentLoader(tk2dSpriteCollectionData sprites) {
if (sprites == null) throw new ArgumentNullException("sprites cannot be null.");
this.sprites = sprites;
}
public Attachment NewAttachment(Skin skin, AttachmentType type, String name) {
if (type != AttachmentType.region) throw new Exception("Unknown attachment type: " + type);
// Strip folder names.
int index = name.LastIndexOfAny(new char[] {'/', '\\'});
if (index != -1) name = name.Substring(index + 1);
tk2dSpriteDefinition attachmentParameters = null;
for (int i = 0; i < sprites.inst.spriteDefinitions.Length; ++i) {
tk2dSpriteDefinition def = sprites.inst.spriteDefinitions[i];
@ -33,8 +30,7 @@ public class tk2dSpineAttachmentLoader : AttachmentLoader {
if (attachmentParameters == null) throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")");
if (attachmentParameters.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")");
if(attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2d toolkit atlases are supported: " + name + " (" + type + ")");
Texture tex = attachmentParameters.material.mainTexture;
if (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name + " (" + type + ")");
Vector2 minTexCoords = Vector2.one;
Vector2 maxTexCoords = Vector2.zero;
@ -44,8 +40,9 @@ public class tk2dSpineAttachmentLoader : AttachmentLoader {
maxTexCoords = Vector2.Max(maxTexCoords, uv);
}
int width = (int)(Mathf.Abs(maxTexCoords.x - minTexCoords.x) * tex.width);
int height = (int)(Mathf.Abs(maxTexCoords.y - minTexCoords.y) * tex.height);
Texture texture = attachmentParameters.material.mainTexture;
int width = (int)(Mathf.Abs(maxTexCoords.x - minTexCoords.x) * texture.width);
int height = (int)(Mathf.Abs(maxTexCoords.y - minTexCoords.y) * texture.height);
bool rotated = (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.Tk2d);
@ -65,6 +62,7 @@ public class tk2dSpineAttachmentLoader : AttachmentLoader {
rotated
);
// TODO - Set attachment.RegionOffsetX/Y. What units does attachmentParameters.untrimmedBoundsData use?!
attachment.RegionWidth = width;
attachment.RegionHeight = height;
attachment.RegionOriginalWidth = width;

View File

@ -5,15 +5,10 @@ using Spine;
// TODO: split skeleton and animation components
// TODO: add events in animation component
/*
*/
[ExecuteInEditMode]
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionForceBuild {
/*
*/
public tk2dSpineSkeletonDataAsset skeletonDataAsset;
public Skeleton skeleton;
@ -22,8 +17,6 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
public float animationSpeed = 1;
public Spine.AnimationState state;
/*
*/
private Mesh mesh;
private Vector3[] vertices;
private Color[] colors;
@ -32,14 +25,10 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
private int cachedQuadCount;
private float[] vertexPositions;
/*
*/
void Awake() {
vertexPositions = new float[8];
}
/*
*/
void Update () {
SkeletonData skeletonData = (skeletonDataAsset != null) ? skeletonDataAsset.GetSkeletonData() : null;
@ -56,8 +45,6 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
UpdateMesh();
}
/*
*/
private void Clear() {
GetComponent<MeshFilter>().mesh = null;
DestroyImmediate(mesh);
@ -69,8 +56,6 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
state = null;
}
/*
*/
private void Initialize() {
mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
@ -81,8 +66,6 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
skeleton = new Skeleton(skeletonDataAsset.GetSkeletonData());
}
/*
*/
private void UpdateMesh() {
int quadIndex = 0;
int drawCount = skeleton.DrawOrder.Count;
@ -143,8 +126,8 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
if (skeletonDataAsset.normalGenerationMode == tk2dSpriteCollection.NormalGenerationMode.NormalsAndTangents) {
Vector4[] tangents = new Vector4[mesh.normals.Length];
for (int t = 0; t < tangents.Length; ++t) {
tangents[t] = new Vector4(1, 0, 0, 1);
for (int i = 0; i < tangents.Length; i++) {
tangents[i] = new Vector4(1, 0, 0, 1);
}
mesh.tangents = tangents;
}
@ -153,8 +136,6 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
renderer.sharedMaterial = skeletonDataAsset.spritesData.inst.materials[0];
}
/*
*/
private void UpdateCache() {
int quadCount = 0;
int drawCount = skeleton.DrawOrder.Count;
@ -173,17 +154,12 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
triangles = new int[quadCount * 6];
}
/*
*/
private void UpdateSkeleton() {
skeleton.Update(Time.deltaTime * animationSpeed);
skeleton.UpdateWorldTransform();
}
/*
*/
private void UpdateAnimation() {
// Check if we need to stop current animation
if(state.Animation != null && animationName == null) {
state.ClearAnimation();

View File

@ -3,12 +3,7 @@ using System.IO;
using UnityEngine;
using Spine;
/*
*/
public class tk2dSpineSkeletonDataAsset : ScriptableObject {
/*
*/
public tk2dSpriteCollectionData spritesData;
public tk2dSpriteCollection.NormalGenerationMode normalGenerationMode = tk2dSpriteCollection.NormalGenerationMode.None;
@ -20,13 +15,9 @@ public class tk2dSpineSkeletonDataAsset : ScriptableObject {
public string[] toAnimation;
public float[] duration;
/*
*/
private SkeletonData skeletonData;
private AnimationStateData stateData;
/*
*/
public SkeletonData GetSkeletonData() {
if (skeletonData != null) return skeletonData;
@ -41,8 +32,6 @@ public class tk2dSpineSkeletonDataAsset : ScriptableObject {
return stateData;
}
/*
*/
private void MakeSkeletonAndAnimationData() {
if (spritesData == null) {
Debug.LogWarning("Sprite collection not set for skeleton data asset: " + name,this);