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