mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 23:34:53 +08:00
Merge branch '3.6' into 3.7-beta
This commit is contained in:
commit
95eecaf138
@ -29,15 +29,9 @@
|
||||
*****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework.Media;
|
||||
using Spine;
|
||||
|
||||
namespace Spine {
|
||||
public class Example : Microsoft.Xna.Framework.Game {
|
||||
@ -50,7 +44,7 @@ namespace Spine {
|
||||
|
||||
private string assetsFolder = "data/";
|
||||
|
||||
public Example () {
|
||||
public Example() {
|
||||
IsMouseVisible = true;
|
||||
|
||||
graphics = new GraphicsDeviceManager(this);
|
||||
@ -59,56 +53,51 @@ namespace Spine {
|
||||
graphics.PreferredBackBufferHeight = 600;
|
||||
}
|
||||
|
||||
protected override void Initialize () {
|
||||
// TODO: Add your initialization logic here
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
protected override void LoadContent() {
|
||||
// Two color tint effect, comment line 76 to disable
|
||||
// Two color tint effect, comment line 80 to disable
|
||||
var spineEffect = Content.Load<Effect>("Content\\SpineEffect");
|
||||
spineEffect.Parameters["World"].SetValue(Matrix.Identity);
|
||||
spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up));
|
||||
|
||||
skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
|
||||
skeletonRenderer.PremultipliedAlpha = true;
|
||||
skeletonRenderer.PremultipliedAlpha = false;
|
||||
skeletonRenderer.Effect = spineEffect;
|
||||
|
||||
// String name = "spineboy";
|
||||
// String name = "goblins-mesh";
|
||||
// String name = "raptor";
|
||||
// String name = "tank";
|
||||
// String name = "coin";
|
||||
String name = "TwoColorTest";
|
||||
bool binaryData = true;
|
||||
// String name = "spineboy-ess";
|
||||
// String name = "goblins-pro";
|
||||
// String name = "raptor-pro";
|
||||
// String name = "tank-pro";
|
||||
String name = "coin-pro";
|
||||
String atlasName = name.Replace("-pro", "").Replace("-ess", "");
|
||||
bool binaryData = false;
|
||||
|
||||
Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
|
||||
Atlas atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice));
|
||||
|
||||
float scale = 1;
|
||||
if (name == "spineboy") scale = 0.6f;
|
||||
if (name == "raptor") scale = 0.5f;
|
||||
if (name == "tank") scale = 0.3f;
|
||||
if (name == "TwoColorTest") scale = 0.5f;
|
||||
if (name == "spineboy-ess") scale = 0.6f;
|
||||
if (name == "raptor-pro") scale = 0.5f;
|
||||
if (name == "tank-pro") scale = 0.3f;
|
||||
if (name == "coin-pro") scale = 1;
|
||||
|
||||
SkeletonData skeletonData;
|
||||
if (binaryData) {
|
||||
SkeletonBinary binary = new SkeletonBinary(atlas);
|
||||
binary.Scale = scale;
|
||||
skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
SkeletonJson json = new SkeletonJson(atlas);
|
||||
json.Scale = scale;
|
||||
skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json");
|
||||
}
|
||||
skeleton = new Skeleton(skeletonData);
|
||||
if (name == "goblins-mesh") skeleton.SetSkin("goblin");
|
||||
if (name == "goblins-pro") skeleton.SetSkin("goblin");
|
||||
|
||||
// Define mixing between animations.
|
||||
AnimationStateData stateData = new AnimationStateData(skeleton.Data);
|
||||
state = new AnimationState(stateData);
|
||||
|
||||
if (name == "spineboy") {
|
||||
if (name == "spineboy-ess") {
|
||||
stateData.SetMix("run", "jump", 0.2f);
|
||||
stateData.SetMix("jump", "run", 0.4f);
|
||||
|
||||
@ -123,41 +112,36 @@ namespace Spine {
|
||||
entry.End += End; // Event handling for queued animations.
|
||||
state.AddAnimation(0, "run", true, 0);
|
||||
}
|
||||
else if (name == "raptor") {
|
||||
else if (name == "raptor-pro") {
|
||||
state.SetAnimation(0, "walk", true);
|
||||
state.AddAnimation(1, "gungrab", false, 2);
|
||||
}
|
||||
else if (name == "coin") {
|
||||
else if (name == "coin-pro") {
|
||||
state.SetAnimation(0, "rotate", true);
|
||||
}
|
||||
else if (name == "tank") {
|
||||
else if (name == "tank-pro") {
|
||||
state.SetAnimation(0, "drive", true);
|
||||
}
|
||||
else if (name == "TwoColorTest") {
|
||||
state.SetAnimation(0, "animation", true);
|
||||
} else {
|
||||
else {
|
||||
state.SetAnimation(0, "walk", true);
|
||||
}
|
||||
|
||||
skeleton.X = 400 + (name == "tank" ? 300: 0);
|
||||
skeleton.Y = 580 + (name == "TwoColorTest" ? -300 : 0);
|
||||
skeleton.X = 400 + (name == "tank-pro" ? 300 : 0);
|
||||
skeleton.Y = GraphicsDevice.Viewport.Height;
|
||||
skeleton.UpdateWorldTransform();
|
||||
|
||||
headSlot = skeleton.FindSlot("head");
|
||||
}
|
||||
|
||||
protected override void UnloadContent () {
|
||||
}
|
||||
|
||||
protected override void Update (GameTime gameTime) {
|
||||
protected override void Update(GameTime gameTime) {
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
protected override void Draw (GameTime gameTime) {
|
||||
protected override void Draw(GameTime gameTime) {
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
|
||||
state.Update(gameTime.ElapsedGameTime.Milliseconds / 1000f);
|
||||
state.Apply(skeleton);
|
||||
state.Apply(skeleton);
|
||||
skeleton.UpdateWorldTransform();
|
||||
if (skeletonRenderer.Effect is BasicEffect) {
|
||||
((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1, 0);
|
||||
@ -186,19 +170,19 @@ namespace Spine {
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
|
||||
public void Start (TrackEntry entry) {
|
||||
public void Start(TrackEntry entry) {
|
||||
Console.WriteLine(entry + ": start");
|
||||
}
|
||||
|
||||
public void End (TrackEntry entry) {
|
||||
public void End(TrackEntry entry) {
|
||||
Console.WriteLine(entry + ": end");
|
||||
}
|
||||
|
||||
public void Complete (TrackEntry entry) {
|
||||
public void Complete(TrackEntry entry) {
|
||||
Console.WriteLine(entry + ": complete ");
|
||||
}
|
||||
|
||||
public void Event (TrackEntry entry, Event e) {
|
||||
public void Event(TrackEntry entry, Event e) {
|
||||
Console.WriteLine(entry + ": event " + e);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -66,7 +66,7 @@ package spine.examples {
|
||||
private var skinChangeCount: Number = 0;
|
||||
|
||||
public function GoblinsExample() {
|
||||
var useStarlingAtlas : Boolean = false;
|
||||
var useStarlingAtlas : Boolean = true;
|
||||
|
||||
var attachmentLoader : AttachmentLoader;
|
||||
if (useStarlingAtlas) {
|
||||
|
||||
@ -27,21 +27,18 @@
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.starling {
|
||||
import spine.attachments.ClippingAttachment;
|
||||
import spine.attachments.PointAttachment;
|
||||
import spine.attachments.PathAttachment;
|
||||
|
||||
import starling.display.Image;
|
||||
|
||||
import spine.Bone;
|
||||
import spine.Skin;
|
||||
import spine.attachments.AttachmentLoader;
|
||||
import spine.attachments.BoundingBoxAttachment;
|
||||
import spine.attachments.ClippingAttachment;
|
||||
import spine.attachments.MeshAttachment;
|
||||
import spine.attachments.PathAttachment;
|
||||
import spine.attachments.PointAttachment;
|
||||
import spine.attachments.RegionAttachment;
|
||||
|
||||
import starling.display.Image;
|
||||
import starling.textures.SubTexture;
|
||||
import starling.textures.Texture;
|
||||
import starling.textures.TextureAtlas;
|
||||
@ -56,17 +53,17 @@ package spine.starling {
|
||||
|
||||
Bone.yDown = true;
|
||||
}
|
||||
|
||||
protected function getTexture(path:String):Texture {
|
||||
return atlas.getTexture(path);
|
||||
}
|
||||
|
||||
protected function getTexture(path : String) : Texture {
|
||||
return atlas.getTexture(path);
|
||||
}
|
||||
|
||||
public function newRegionAttachment(skin : Skin, name : String, path : String) : RegionAttachment {
|
||||
var texture : Texture = atlas.getTexture(path);
|
||||
var texture : Texture = atlas.getTexture(path);
|
||||
if (texture == null)
|
||||
throw new Error("Region not found in Starling atlas: " + path + " (region attachment: " + name + ")");
|
||||
var attachment : RegionAttachment = new RegionAttachment(name);
|
||||
var rotated : Boolean = atlas.getRotation(path);
|
||||
var rotated : Boolean = atlas.getRotation(path);
|
||||
attachment.rendererObject = new Image(Texture.fromTexture(texture)); // Discard frame.
|
||||
var frame : Rectangle = texture.frame;
|
||||
attachment.regionOffsetX = frame ? -frame.x : 0;
|
||||
@ -83,35 +80,18 @@ package spine.starling {
|
||||
attachment.regionWidth = attachment.regionHeight;
|
||||
attachment.regionHeight = tmp;
|
||||
}
|
||||
var subTexture : SubTexture = texture as SubTexture;
|
||||
if (subTexture) {
|
||||
var root : Texture = subTexture.root;
|
||||
var rectRegion : Rectangle = atlas.getRegion(path);
|
||||
if (!rotated) {
|
||||
attachment["regionU"] = rectRegion.x / root.width;
|
||||
attachment["regionV"] = rectRegion.y / root.height;
|
||||
attachment["regionU2"] = (rectRegion.x + subTexture.width) / root.width;
|
||||
attachment["regionV2"] = (rectRegion.y + subTexture.height) / root.height;
|
||||
} else {
|
||||
attachment["regionU2"] = rectRegion.x / root.width;
|
||||
attachment["regionV2"] = rectRegion.y / root.height;
|
||||
attachment["regionU"] = (rectRegion.x + subTexture.width) / root.width;
|
||||
attachment["regionV"] = (rectRegion.y + subTexture.height) / root.height;
|
||||
}
|
||||
attachment.setUVs(attachment["regionU"], attachment["regionV"], attachment["regionU2"], attachment["regionV2"], atlas.getRotation(path));
|
||||
if (!rotated) {
|
||||
attachment["regionU"] = 0;
|
||||
attachment["regionV"] = 0;
|
||||
attachment["regionU2"] = 1;
|
||||
attachment["regionV2"] = 1;
|
||||
} else {
|
||||
if (!rotated) {
|
||||
attachment["regionU"] = 0;
|
||||
attachment["regionV"] = 1;
|
||||
attachment["regionU2"] = 1;
|
||||
attachment["regionV2"] = 0;
|
||||
} else {
|
||||
attachment["regionU2"] = 0;
|
||||
attachment["regionV2"] = 1;
|
||||
attachment["regionU"] = 1;
|
||||
attachment["regionV"] = 0;
|
||||
}
|
||||
attachment["regionU2"] = 0;
|
||||
attachment["regionV2"] = 1;
|
||||
attachment["regionU"] = 1;
|
||||
attachment["regionV"] = 0;
|
||||
}
|
||||
attachment.setUVs(attachment["regionU"], attachment["regionV"], attachment["regionU2"], attachment["regionV2"], atlas.getRotation(path));
|
||||
return attachment;
|
||||
}
|
||||
|
||||
@ -181,7 +161,7 @@ package spine.starling {
|
||||
public function newPointAttachment(skin : Skin, name : String) : PointAttachment {
|
||||
return new PointAttachment(name);
|
||||
}
|
||||
|
||||
|
||||
public function newClippingAttachment(skin : Skin, name : String) : ClippingAttachment {
|
||||
return new ClippingAttachment(name);
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
// Contributed by: Mitch Thompson
|
||||
// Original Contribution by: Mitch Thompson
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
@ -41,6 +41,7 @@ namespace Spine.Unity.Modules {
|
||||
|
||||
#region Inspector
|
||||
public bool attachOnStart = true;
|
||||
public bool overrideAnimation = true;
|
||||
public Sprite sprite;
|
||||
[SpineSlot] public string slot;
|
||||
#endregion
|
||||
@ -71,6 +72,7 @@ namespace Spine.Unity.Modules {
|
||||
#endif
|
||||
|
||||
RegionAttachment attachment;
|
||||
Slot spineSlot;
|
||||
bool applyPMA;
|
||||
|
||||
static Dictionary<Texture, AtlasPage> atlasPageCache;
|
||||
@ -87,24 +89,58 @@ namespace Spine.Unity.Modules {
|
||||
}
|
||||
|
||||
void Start () {
|
||||
if (attachOnStart) Attach();
|
||||
// Initialize slot and attachment references.
|
||||
Initialize(false);
|
||||
|
||||
if (attachOnStart)
|
||||
Attach();
|
||||
}
|
||||
|
||||
public void Attach () {
|
||||
var skeletonComponent = GetComponent<ISkeletonComponent>();
|
||||
var skeletonRenderer = skeletonComponent as SkeletonRenderer;
|
||||
if (skeletonRenderer != null)
|
||||
this.applyPMA = skeletonRenderer.pmaVertexColors;
|
||||
else {
|
||||
var skeletonGraphic = skeletonComponent as SkeletonGraphic;
|
||||
if (skeletonGraphic != null)
|
||||
this.applyPMA = skeletonGraphic.MeshGenerator.settings.pmaVertexColors;
|
||||
void AnimationOverrideSpriteAttach (ISkeletonAnimation animated) {
|
||||
if (overrideAnimation && isActiveAndEnabled)
|
||||
Attach();
|
||||
}
|
||||
|
||||
public void Initialize (bool overwrite = true) {
|
||||
if (overwrite || attachment == null) {
|
||||
// Get the applyPMA value.
|
||||
var skeletonComponent = GetComponent<ISkeletonComponent>();
|
||||
var skeletonRenderer = skeletonComponent as SkeletonRenderer;
|
||||
if (skeletonRenderer != null)
|
||||
this.applyPMA = skeletonRenderer.pmaVertexColors;
|
||||
else {
|
||||
var skeletonGraphic = skeletonComponent as SkeletonGraphic;
|
||||
if (skeletonGraphic != null)
|
||||
this.applyPMA = skeletonGraphic.MeshGenerator.settings.pmaVertexColors;
|
||||
}
|
||||
|
||||
// Subscribe to UpdateComplete to override animation keys.
|
||||
if (overrideAnimation) {
|
||||
var animatedSkeleton = skeletonComponent as ISkeletonAnimation;
|
||||
if (animatedSkeleton != null) {
|
||||
animatedSkeleton.UpdateComplete -= AnimationOverrideSpriteAttach;
|
||||
animatedSkeleton.UpdateComplete += AnimationOverrideSpriteAttach;
|
||||
}
|
||||
}
|
||||
|
||||
spineSlot = spineSlot ?? skeletonComponent.Skeleton.FindSlot(slot);
|
||||
Shader attachmentShader = applyPMA ? Shader.Find(DefaultPMAShader) : Shader.Find(DefaultStraightAlphaShader);
|
||||
attachment = applyPMA ? sprite.ToRegionAttachmentPMAClone(attachmentShader) : sprite.ToRegionAttachment(SpriteAttacher.GetPageFor(sprite.texture, attachmentShader));
|
||||
}
|
||||
|
||||
Shader attachmentShader = applyPMA ? Shader.Find(DefaultPMAShader) : Shader.Find(DefaultStraightAlphaShader);
|
||||
attachment = applyPMA ? sprite.ToRegionAttachmentPMAClone(attachmentShader) : sprite.ToRegionAttachment(SpriteAttacher.GetPageFor(sprite.texture, attachmentShader));
|
||||
skeletonComponent.Skeleton.FindSlot(slot).Attachment = attachment;
|
||||
}
|
||||
|
||||
void OnDestroy () {
|
||||
var animatedSkeleton = GetComponent<ISkeletonAnimation>();
|
||||
if (animatedSkeleton != null)
|
||||
animatedSkeleton.UpdateComplete -= AnimationOverrideSpriteAttach;
|
||||
}
|
||||
|
||||
/// <summary>Update the slot's attachment to the Attachment generated from the sprite.</summary>
|
||||
public void Attach () {
|
||||
if (spineSlot != null)
|
||||
spineSlot.Attachment = attachment;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SpriteAttachmentExtensions {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user