提交Spine插件
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
public class BoneLocalOverride : MonoBehaviour {
|
||||
[SpineBone]
|
||||
public string boneName;
|
||||
|
||||
[Space]
|
||||
[Range(0, 1)] public float alpha = 1;
|
||||
|
||||
[Space]
|
||||
public bool overridePosition = true;
|
||||
public Vector2 localPosition;
|
||||
|
||||
[Space]
|
||||
public bool overrideRotation = true;
|
||||
[Range(0, 360)] public float rotation = 0;
|
||||
|
||||
ISkeletonAnimation spineComponent;
|
||||
Bone bone;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnValidate () {
|
||||
if (Application.isPlaying) return;
|
||||
spineComponent = spineComponent ?? GetComponent<ISkeletonAnimation>();
|
||||
if (spineComponent == null) return;
|
||||
if (bone != null) bone.SetToSetupPose();
|
||||
OverrideLocal(spineComponent);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Awake () {
|
||||
spineComponent = GetComponent<ISkeletonAnimation>();
|
||||
if (spineComponent == null) { this.enabled = false; return; }
|
||||
spineComponent.UpdateLocal += OverrideLocal;
|
||||
|
||||
if (bone == null) { this.enabled = false; return; }
|
||||
}
|
||||
|
||||
void OverrideLocal (ISkeletonAnimation animated) {
|
||||
if (bone == null || bone.Data.Name != boneName) {
|
||||
if (string.IsNullOrEmpty(boneName)) return;
|
||||
bone = spineComponent.Skeleton.FindBone(boneName);
|
||||
if (bone == null) {
|
||||
Debug.LogFormat("Cannot find bone: '{0}'", boneName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (overridePosition) {
|
||||
bone.X = Mathf.Lerp(bone.X, localPosition.x, alpha);
|
||||
bone.Y = Mathf.Lerp(bone.Y, localPosition.y, alpha);
|
||||
}
|
||||
|
||||
if (overrideRotation)
|
||||
bone.Rotation = Mathf.Lerp(bone.Rotation, rotation, alpha);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61e6f96a4b02648479575d8b9127f5ed
|
||||
timeCreated: 1492782100
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Spine.Unity.Modules.AttachmentTools;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
public class CombinedSkin : MonoBehaviour {
|
||||
[SpineSkin]
|
||||
public List<string> skinsToCombine;
|
||||
|
||||
Skin combinedSkin;
|
||||
|
||||
void Start () {
|
||||
var skeletonComponent = GetComponent<ISkeletonComponent>();
|
||||
if (skeletonComponent == null) return;
|
||||
var skeleton = skeletonComponent.Skeleton;
|
||||
if (skeleton == null) return;
|
||||
|
||||
combinedSkin = combinedSkin ?? new Skin("combined");
|
||||
combinedSkin.Clear();
|
||||
foreach (var skinName in skinsToCombine) {
|
||||
var skin = skeleton.Data.FindSkin(skinName);
|
||||
if (skin != null) combinedSkin.AddAttachments(skin);
|
||||
}
|
||||
|
||||
skeleton.SetSkin(combinedSkin);
|
||||
skeleton.SetToSetupPose();
|
||||
var animationStateComponent = skeletonComponent as IAnimationStateComponent;
|
||||
if (animationStateComponent != null) animationStateComponent.AnimationState.Apply(skeleton);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e864d2963143ec04eb4f905e6add115e
|
||||
timeCreated: 1495176902
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8033179a12443e4eaef33b35fed074c
|
||||
folderAsset: yes
|
||||
timeCreated: 1495179724
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,83 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Spine;
|
||||
using Spine.Unity.Modules.AttachmentTools;
|
||||
|
||||
namespace Spine.Unity.Modules {
|
||||
/// <summary>
|
||||
/// Example code for a component that replaces the default attachment of a slot with an image from a Spine atlas.</summary>
|
||||
public class AtlasRegionAttacher : MonoBehaviour {
|
||||
|
||||
[System.Serializable]
|
||||
public class SlotRegionPair {
|
||||
[SpineSlot] public string slot;
|
||||
[SpineAtlasRegion] public string region;
|
||||
}
|
||||
|
||||
[SerializeField] protected SpineAtlasAsset atlasAsset;
|
||||
[SerializeField] protected bool inheritProperties = true;
|
||||
[SerializeField] protected List<SlotRegionPair> attachments = new List<SlotRegionPair>();
|
||||
|
||||
Atlas atlas;
|
||||
|
||||
void Awake () {
|
||||
var skeletonRenderer = GetComponent<SkeletonRenderer>();
|
||||
skeletonRenderer.OnRebuild += Apply;
|
||||
if (skeletonRenderer.valid) Apply(skeletonRenderer);
|
||||
}
|
||||
|
||||
void Start () { } // Allow checkbox in inspector
|
||||
|
||||
void Apply (SkeletonRenderer skeletonRenderer) {
|
||||
if (!this.enabled) return;
|
||||
|
||||
atlas = atlasAsset.GetAtlas();
|
||||
if (atlas == null) return;
|
||||
float scale = skeletonRenderer.skeletonDataAsset.scale;
|
||||
|
||||
foreach (var entry in attachments) {
|
||||
Slot slot = skeletonRenderer.Skeleton.FindSlot(entry.slot);
|
||||
Attachment originalAttachment = slot.Attachment;
|
||||
AtlasRegion region = atlas.FindRegion(entry.region);
|
||||
|
||||
if (region == null) {
|
||||
slot.Attachment = null;
|
||||
} else if (inheritProperties && originalAttachment != null) {
|
||||
slot.Attachment = originalAttachment.GetRemappedClone(region, true, true, scale);
|
||||
} else {
|
||||
var newRegionAttachment = region.ToRegionAttachment(region.name, scale);
|
||||
slot.Attachment = newRegionAttachment;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afde57cc4fd39bb4dbd61b73403ae6a8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e55c8477eccddc4cb5c3551a3945ca7
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,178 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
// Original Contribution by: Mitch Thompson
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Spine.Unity.Modules.AttachmentTools;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
public class SpriteAttacher : MonoBehaviour {
|
||||
public const string DefaultPMAShader = "Spine/Skeleton";
|
||||
public const string DefaultStraightAlphaShader = "Sprites/Default";
|
||||
|
||||
#region Inspector
|
||||
public bool attachOnStart = true;
|
||||
public bool overrideAnimation = true;
|
||||
public Sprite sprite;
|
||||
[SpineSlot] public string slot;
|
||||
#endregion
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnValidate () {
|
||||
var skeletonComponent = GetComponent<ISkeletonComponent>();
|
||||
var skeletonRenderer = skeletonComponent as SkeletonRenderer;
|
||||
bool applyPMA;
|
||||
|
||||
if (skeletonRenderer != null) {
|
||||
applyPMA = skeletonRenderer.pmaVertexColors;
|
||||
} else {
|
||||
var skeletonGraphic = skeletonComponent as SkeletonGraphic;
|
||||
applyPMA = skeletonGraphic != null && skeletonGraphic.MeshGenerator.settings.pmaVertexColors;
|
||||
}
|
||||
|
||||
if (applyPMA) {
|
||||
try {
|
||||
sprite.texture.GetPixel(0, 0);
|
||||
} catch (UnityException e) {
|
||||
Debug.LogFormat("Texture of {0} ({1}) is not read/write enabled. SpriteAttacher requires this in order to work with a SkeletonRenderer that renders premultiplied alpha. Please check the texture settings.", sprite.name, sprite.texture.name);
|
||||
UnityEditor.EditorGUIUtility.PingObject(sprite.texture);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
RegionAttachment attachment;
|
||||
Slot spineSlot;
|
||||
bool applyPMA;
|
||||
|
||||
static Dictionary<Texture, AtlasPage> atlasPageCache;
|
||||
static AtlasPage GetPageFor (Texture texture, Shader shader) {
|
||||
if (atlasPageCache == null) atlasPageCache = new Dictionary<Texture, AtlasPage>();
|
||||
AtlasPage atlasPage;
|
||||
atlasPageCache.TryGetValue(texture, out atlasPage);
|
||||
if (atlasPage == null) {
|
||||
var newMaterial = new Material(shader);
|
||||
atlasPage = newMaterial.ToSpineAtlasPage();
|
||||
atlasPageCache[texture] = atlasPage;
|
||||
}
|
||||
return atlasPage;
|
||||
}
|
||||
|
||||
void Start () {
|
||||
// Initialize slot and attachment references.
|
||||
Initialize(false);
|
||||
|
||||
if (attachOnStart)
|
||||
Attach();
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
[System.Obsolete]
|
||||
public static RegionAttachment AttachUnitySprite (this Skeleton skeleton, string slotName, Sprite sprite, string shaderName = SpriteAttacher.DefaultPMAShader, bool applyPMA = true, float rotation = 0f) {
|
||||
return skeleton.AttachUnitySprite(slotName, sprite, Shader.Find(shaderName), applyPMA, rotation: rotation);
|
||||
}
|
||||
|
||||
[System.Obsolete]
|
||||
public static RegionAttachment AddUnitySprite (this SkeletonData skeletonData, string slotName, Sprite sprite, string skinName = "", string shaderName = SpriteAttacher.DefaultPMAShader, bool applyPMA = true, float rotation = 0f) {
|
||||
return skeletonData.AddUnitySprite(slotName, sprite, skinName, Shader.Find(shaderName), applyPMA, rotation: rotation);
|
||||
}
|
||||
|
||||
[System.Obsolete]
|
||||
public static RegionAttachment AttachUnitySprite (this Skeleton skeleton, string slotName, Sprite sprite, Shader shader, bool applyPMA, float rotation = 0f) {
|
||||
RegionAttachment att = applyPMA ? sprite.ToRegionAttachmentPMAClone(shader, rotation: rotation) : sprite.ToRegionAttachment(new Material(shader), rotation: rotation);
|
||||
skeleton.FindSlot(slotName).Attachment = att;
|
||||
return att;
|
||||
}
|
||||
|
||||
[System.Obsolete]
|
||||
public static RegionAttachment AddUnitySprite (this SkeletonData skeletonData, string slotName, Sprite sprite, string skinName, Shader shader, bool applyPMA, float rotation = 0f) {
|
||||
RegionAttachment att = applyPMA ? sprite.ToRegionAttachmentPMAClone(shader, rotation: rotation) : sprite.ToRegionAttachment(new Material(shader), rotation);
|
||||
|
||||
var slotIndex = skeletonData.FindSlotIndex(slotName);
|
||||
Skin skin = skeletonData.DefaultSkin;
|
||||
if (skinName != "")
|
||||
skin = skeletonData.FindSkin(skinName);
|
||||
|
||||
skin.AddAttachment(slotIndex, att.Name, att);
|
||||
|
||||
return att;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ee7b5e36685e2445a0097de42940987
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1a4a1f889c97e84db5e1ef512f77f3e
|
||||
folderAsset: yes
|
||||
timeCreated: 1498053541
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,84 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
|
||||
// This is a sample component for C# vertex effects for Spine rendering components.
|
||||
// Using shaders and materials to control vertex properties is still more performant
|
||||
// than using this API, but in cases where your vertex effect logic cannot be
|
||||
// expressed as shader code, these vertex effects can be useful.
|
||||
public class JitterEffectExample : MonoBehaviour {
|
||||
|
||||
[Range(0f, 0.8f)]
|
||||
public float jitterMagnitude = 0.2f;
|
||||
|
||||
SkeletonRenderer skeletonRenderer;
|
||||
|
||||
void OnEnable () {
|
||||
skeletonRenderer = GetComponent<SkeletonRenderer>();
|
||||
if (skeletonRenderer == null) return;
|
||||
|
||||
// Use the OnPostProcessVertices callback to modify the vertices at the correct time.
|
||||
skeletonRenderer.OnPostProcessVertices -= ProcessVertices;
|
||||
skeletonRenderer.OnPostProcessVertices += ProcessVertices;
|
||||
|
||||
Debug.Log("Jitter Effect Enabled.");
|
||||
}
|
||||
|
||||
void ProcessVertices (MeshGeneratorBuffers buffers) {
|
||||
if (!this.enabled) return;
|
||||
|
||||
// For efficiency, limit your effect to the actual mesh vertex count using vertexCount
|
||||
int vertexCount = buffers.vertexCount;
|
||||
|
||||
// Modify vertex positions by accessing Vector3[] vertexBuffer
|
||||
var vertices = buffers.vertexBuffer;
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
vertices[i] += (Vector3)(Random.insideUnitCircle * jitterMagnitude);
|
||||
|
||||
// You can also modify uvs and colors.
|
||||
//var uvs = buffers.uvBuffer;
|
||||
//var colors = buffers.colorBuffer;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
void OnDisable () {
|
||||
if (skeletonRenderer == null) return;
|
||||
skeletonRenderer.OnPostProcessVertices -= ProcessVertices;
|
||||
|
||||
Debug.Log("Jitter Effect Disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b9ca76eac8062f42b99bbf78e777ee1
|
||||
timeCreated: 1498053868
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,105 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
|
||||
// This is a sample component for C# vertex effects for Spine rendering components.
|
||||
// Using shaders and materials to control vertex properties is still more performant
|
||||
// than using this API, but in cases where your vertex effect logic cannot be
|
||||
// expressed as shader code, these vertex effects can be useful.
|
||||
public class TwoByTwoTransformEffectExample : MonoBehaviour {
|
||||
|
||||
public Vector2 xAxis = new Vector2(1, 0);
|
||||
public Vector2 yAxis = new Vector2(0, 1);
|
||||
|
||||
SkeletonRenderer skeletonRenderer;
|
||||
|
||||
void OnEnable () {
|
||||
skeletonRenderer = GetComponent<SkeletonRenderer>();
|
||||
if (skeletonRenderer == null) return;
|
||||
|
||||
// Use the OnPostProcessVertices callback to modify the vertices at the correct time.
|
||||
skeletonRenderer.OnPostProcessVertices -= ProcessVertices;
|
||||
skeletonRenderer.OnPostProcessVertices += ProcessVertices;
|
||||
|
||||
Debug.Log("2x2 Transform Effect Enabled.");
|
||||
}
|
||||
|
||||
void ProcessVertices (MeshGeneratorBuffers buffers) {
|
||||
if (!this.enabled)
|
||||
return;
|
||||
|
||||
int vertexCount = buffers.vertexCount; // For efficiency, limit your effect to the actual mesh vertex count using vertexCount
|
||||
|
||||
// Modify vertex positions by accessing Vector3[] vertexBuffer
|
||||
var vertices = buffers.vertexBuffer;
|
||||
Vector3 transformedPos = default(Vector3);
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
Vector3 originalPos = vertices[i];
|
||||
transformedPos.x = (xAxis.x * originalPos.x) + (yAxis.x * originalPos.y);
|
||||
transformedPos.y = (xAxis.y * originalPos.x) + (yAxis.y * originalPos.y);
|
||||
vertices[i] = transformedPos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnDisable () {
|
||||
if (skeletonRenderer == null) return;
|
||||
skeletonRenderer.OnPostProcessVertices -= ProcessVertices;
|
||||
Debug.Log("2x2 Transform Effect Disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(Spine.Unity.Examples.TwoByTwoTransformEffectExample))]
|
||||
public class TwoByTwoTransformEffectExampleEditor : UnityEditor.Editor {
|
||||
|
||||
Spine.Unity.Examples.TwoByTwoTransformEffectExample Target { get { return target as Spine.Unity.Examples.TwoByTwoTransformEffectExample; } }
|
||||
|
||||
void OnSceneGUI () {
|
||||
var transform = Target.transform;
|
||||
LocalVectorHandle(ref Target.xAxis, transform, Color.red);
|
||||
LocalVectorHandle(ref Target.yAxis, transform, Color.green);
|
||||
}
|
||||
|
||||
static void LocalVectorHandle (ref Vector2 v, Transform transform, Color color) {
|
||||
Color originalColor = UnityEditor.Handles.color;
|
||||
UnityEditor.Handles.color = color;
|
||||
UnityEditor.Handles.DrawLine(transform.position, transform.TransformPoint(v));
|
||||
v = transform.InverseTransformPoint(UnityEditor.Handles.FreeMoveHandle(transform.TransformPoint(v), Quaternion.identity, 0.3f, Vector3.zero, UnityEditor.Handles.CubeHandleCap));
|
||||
UnityEditor.Handles.color = originalColor;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8afb2340fbd3fe14f9f4e07cba073e17
|
||||
timeCreated: 1523229765
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
|
||||
// To use this example component, add it to your SkeletonAnimation Spine GameObject.
|
||||
// This component will disable that SkeletonAnimation component to prevent it from calling its own Update and LateUpdate methods.
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class SkeletonAnimationFixedTimestep : MonoBehaviour {
|
||||
#region Inspector
|
||||
public SkeletonAnimation skeletonAnimation;
|
||||
|
||||
[Tooltip("The duration of each frame in seconds. For 12 fps: enter '1/12' in the Unity inspector.")]
|
||||
public float frameDeltaTime = 1 / 15f;
|
||||
|
||||
[Header("Advanced")]
|
||||
[Tooltip("The maximum number of fixed timesteps. If the game framerate drops below the If the framerate is consistently faster than the limited frames, this does nothing.")]
|
||||
public int maxFrameSkip = 4;
|
||||
|
||||
[Tooltip("If enabled, the Skeleton mesh will be updated only on the same frame when the animation and skeleton are updated. Disable this or call SkeletonAnimation.LateUpdate yourself if you are modifying the Skeleton using other components that don't run in the same fixed timestep.")]
|
||||
public bool frameskipMeshUpdate = true;
|
||||
|
||||
[Tooltip("This is the amount the internal accumulator starts with. Set it to some fraction of your frame delta time if you want to stagger updates between multiple skeletons.")]
|
||||
public float timeOffset;
|
||||
#endregion
|
||||
|
||||
float accumulatedTime = 0;
|
||||
bool requiresNewMesh;
|
||||
|
||||
void OnValidate () {
|
||||
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
||||
if (frameDeltaTime <= 0) frameDeltaTime = 1 / 60f;
|
||||
if (maxFrameSkip < 1) maxFrameSkip = 1;
|
||||
}
|
||||
|
||||
void Awake () {
|
||||
requiresNewMesh = true;
|
||||
accumulatedTime = timeOffset;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
if (skeletonAnimation.enabled)
|
||||
skeletonAnimation.enabled = false;
|
||||
|
||||
accumulatedTime += Time.deltaTime;
|
||||
|
||||
float frames = 0;
|
||||
while (accumulatedTime >= frameDeltaTime) {
|
||||
frames++;
|
||||
if (frames > maxFrameSkip) break;
|
||||
accumulatedTime -= frameDeltaTime;
|
||||
}
|
||||
|
||||
if (frames > 0) {
|
||||
skeletonAnimation.Update(frames * frameDeltaTime);
|
||||
requiresNewMesh = true;
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate () {
|
||||
if (frameskipMeshUpdate && !requiresNewMesh) return;
|
||||
|
||||
skeletonAnimation.LateUpdate();
|
||||
requiresNewMesh = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1670ee04b19c794db301d734c71bdd6
|
||||
timeCreated: 1545031871
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1258037ca4297c7428842419a266f7a4
|
||||
folderAsset: yes
|
||||
timeCreated: 1502103133
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,161 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
namespace Spine.Unity {
|
||||
|
||||
using Animation = Spine.Animation;
|
||||
using AnimationState = Spine.AnimationState;
|
||||
|
||||
public class SkeletonAnimationMulti : MonoBehaviour {
|
||||
const int MainTrackIndex = 0;
|
||||
|
||||
public bool initialFlipX, initialFlipY;
|
||||
public string initialAnimation;
|
||||
public bool initialLoop;
|
||||
[Space]
|
||||
public List<SkeletonDataAsset> skeletonDataAssets = new List<SkeletonDataAsset>();
|
||||
[Header("Settings")]
|
||||
public MeshGenerator.Settings meshGeneratorSettings = MeshGenerator.Settings.Default;
|
||||
|
||||
readonly List<SkeletonAnimation> skeletonAnimations = new List<SkeletonAnimation>();
|
||||
readonly Dictionary<string, Animation> animationNameTable = new Dictionary<string, Animation>();
|
||||
readonly Dictionary<Animation, SkeletonAnimation> animationSkeletonTable = new Dictionary<Animation, SkeletonAnimation>();
|
||||
//Stateful
|
||||
SkeletonAnimation currentSkeletonAnimation;
|
||||
|
||||
void Clear () {
|
||||
foreach (var s in skeletonAnimations)
|
||||
Destroy(s.gameObject);
|
||||
|
||||
skeletonAnimations.Clear();
|
||||
animationNameTable.Clear();
|
||||
animationSkeletonTable.Clear();
|
||||
}
|
||||
|
||||
void SetActiveSkeleton (SkeletonAnimation skeletonAnimation) {
|
||||
foreach (var sa in skeletonAnimations)
|
||||
sa.gameObject.SetActive(sa == skeletonAnimation);
|
||||
|
||||
currentSkeletonAnimation = skeletonAnimation;
|
||||
}
|
||||
|
||||
#region Lifecycle
|
||||
void Awake () {
|
||||
Initialize(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region API
|
||||
public Dictionary<Animation, SkeletonAnimation> AnimationSkeletonTable { get { return this.animationSkeletonTable; } }
|
||||
public Dictionary<string, Animation> AnimationNameTable { get { return this.animationNameTable; } }
|
||||
public SkeletonAnimation CurrentSkeletonAnimation { get { return this.currentSkeletonAnimation; } }
|
||||
|
||||
public void Initialize (bool overwrite) {
|
||||
if (skeletonAnimations.Count != 0 && !overwrite) return;
|
||||
|
||||
Clear();
|
||||
|
||||
var settings = this.meshGeneratorSettings;
|
||||
Transform thisTransform = this.transform;
|
||||
foreach (var sda in skeletonDataAssets) {
|
||||
var sa = SkeletonAnimation.NewSkeletonAnimationGameObject(sda);
|
||||
sa.transform.SetParent(thisTransform, false);
|
||||
|
||||
sa.SetMeshSettings(settings);
|
||||
sa.initialFlipX = this.initialFlipX;
|
||||
sa.initialFlipY = this.initialFlipY;
|
||||
var skeleton = sa.skeleton;
|
||||
skeleton.ScaleX = this.initialFlipX ? -1 : 1;
|
||||
skeleton.ScaleY = this.initialFlipY ? -1 : 1;
|
||||
|
||||
sa.Initialize(false);
|
||||
skeletonAnimations.Add(sa);
|
||||
}
|
||||
|
||||
// Build cache
|
||||
var animationNameTable = this.animationNameTable;
|
||||
var animationSkeletonTable = this.animationSkeletonTable;
|
||||
foreach (var skeletonAnimation in skeletonAnimations) {
|
||||
foreach (var animationObject in skeletonAnimation.Skeleton.Data.Animations) {
|
||||
animationNameTable[animationObject.Name] = animationObject;
|
||||
animationSkeletonTable[animationObject] = skeletonAnimation;
|
||||
}
|
||||
}
|
||||
|
||||
SetActiveSkeleton(skeletonAnimations[0]);
|
||||
SetAnimation(initialAnimation, initialLoop);
|
||||
}
|
||||
|
||||
public Animation FindAnimation (string animationName) {
|
||||
// Analysis disable once LocalVariableHidesMember
|
||||
Animation animation;
|
||||
animationNameTable.TryGetValue(animationName, out animation);
|
||||
return animation;
|
||||
}
|
||||
|
||||
public TrackEntry SetAnimation (string animationName, bool loop) {
|
||||
return SetAnimation(FindAnimation(animationName), loop);
|
||||
}
|
||||
|
||||
public TrackEntry SetAnimation (Animation animation, bool loop) {
|
||||
if (animation == null) return null;
|
||||
|
||||
SkeletonAnimation skeletonAnimation;
|
||||
animationSkeletonTable.TryGetValue(animation, out skeletonAnimation);
|
||||
|
||||
if (skeletonAnimation != null) {
|
||||
SetActiveSkeleton(skeletonAnimation);
|
||||
skeletonAnimation.skeleton.SetToSetupPose();
|
||||
return skeletonAnimation.state.SetAnimation(MainTrackIndex, animation, loop);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetEmptyAnimation (float mixDuration) {
|
||||
currentSkeletonAnimation.state.SetEmptyAnimation(MainTrackIndex, mixDuration);
|
||||
}
|
||||
|
||||
public void ClearAnimation () {
|
||||
currentSkeletonAnimation.state.ClearTrack(MainTrackIndex);
|
||||
}
|
||||
|
||||
public TrackEntry GetCurrent () {
|
||||
return currentSkeletonAnimation.state.GetCurrent(MainTrackIndex);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5ea35d82fb1b5d4583e89b4343976b6
|
||||
timeCreated: 1502103123
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,83 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
namespace Spine.Unity.Prototyping {
|
||||
/// <summary>
|
||||
/// Stores and serializes initial settings for a Spine Skeleton component. The settings only get applied on Start at runtime.</summary>
|
||||
public class SkeletonColorInitialize : MonoBehaviour {
|
||||
public Color skeletonColor = Color.white;
|
||||
public List<SlotSettings> slotSettings = new List<SlotSettings>();
|
||||
|
||||
[System.Serializable]
|
||||
public class SlotSettings {
|
||||
[SpineSlot]
|
||||
public string slot = string.Empty;
|
||||
public Color color = Color.white;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnValidate () {
|
||||
var skeletonComponent = GetComponent<ISkeletonComponent>();
|
||||
if (skeletonComponent != null) {
|
||||
skeletonComponent.Skeleton.SetSlotsToSetupPose();
|
||||
var animationStateComponent = GetComponent<IAnimationStateComponent>();
|
||||
if (animationStateComponent != null && animationStateComponent.AnimationState != null) {
|
||||
animationStateComponent.AnimationState.Apply(skeletonComponent.Skeleton);
|
||||
}
|
||||
}
|
||||
ApplySettings();
|
||||
}
|
||||
#endif
|
||||
|
||||
void Start () {
|
||||
ApplySettings();
|
||||
}
|
||||
|
||||
void ApplySettings () {
|
||||
var skeletonComponent = GetComponent<ISkeletonComponent>();
|
||||
if (skeletonComponent != null) {
|
||||
var skeleton = skeletonComponent.Skeleton;
|
||||
skeleton.SetColor(skeletonColor);
|
||||
|
||||
foreach (var s in slotSettings) {
|
||||
var slot = skeleton.FindSlot(s.slot);
|
||||
if (slot != null) slot.SetColor(s.color);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e3501002f468384b80d5853d04e19ca
|
||||
timeCreated: 1494113429
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using Spine.Unity;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
|
||||
/// <summary>
|
||||
/// Add this component to a Spine GameObject to apply a specific slot's Colors as MaterialProperties.
|
||||
/// This allows you to apply the two color tint to the whole skeleton and not require the overhead of an extra vertex stream on the mesh.
|
||||
/// </summary>
|
||||
public class SlotTintBlackFollower : MonoBehaviour {
|
||||
#region Inspector
|
||||
/// <summary>
|
||||
/// Serialized name of the slot loaded at runtime. Change the slot field instead of this if you want to change the followed slot at runtime.</summary>
|
||||
[SpineSlot]
|
||||
[SerializeField]
|
||||
protected string slotName;
|
||||
|
||||
[SerializeField]
|
||||
protected string colorPropertyName = "_Color";
|
||||
[SerializeField]
|
||||
protected string blackPropertyName = "_Black";
|
||||
#endregion
|
||||
|
||||
public Slot slot;
|
||||
MeshRenderer mr;
|
||||
MaterialPropertyBlock mb;
|
||||
int colorPropertyId, blackPropertyId;
|
||||
|
||||
void Start () {
|
||||
Initialize(false);
|
||||
}
|
||||
|
||||
public void Initialize (bool overwrite) {
|
||||
if (overwrite || mb == null) {
|
||||
mb = new MaterialPropertyBlock();
|
||||
mr = GetComponent<MeshRenderer>();
|
||||
slot = GetComponent<ISkeletonComponent>().Skeleton.FindSlot(slotName);
|
||||
|
||||
colorPropertyId = Shader.PropertyToID(colorPropertyName);
|
||||
blackPropertyId = Shader.PropertyToID(blackPropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update () {
|
||||
Slot s = slot;
|
||||
if (s == null) return;
|
||||
|
||||
mb.SetColor(colorPropertyId, s.GetColor());
|
||||
mb.SetColor(blackPropertyId, s.GetColorTintBlack());
|
||||
|
||||
mr.SetPropertyBlock(mb);
|
||||
}
|
||||
|
||||
void OnDisable () {
|
||||
mb.Clear();
|
||||
mr.SetPropertyBlock(mb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49a62759c814e7a458b9026d504e0898
|
||||
timeCreated: 1489227143
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,80 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated May 1, 2019. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2019, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
|
||||
* INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Spine.Unity.Prototyping {
|
||||
|
||||
public class SpineEventUnityHandler : MonoBehaviour {
|
||||
|
||||
[System.Serializable]
|
||||
public class EventPair {
|
||||
[SpineEvent] public string spineEvent;
|
||||
public UnityEvent unityHandler;
|
||||
public AnimationState.TrackEntryEventDelegate eventDelegate;
|
||||
}
|
||||
|
||||
public List<EventPair> events = new List<EventPair>();
|
||||
|
||||
ISkeletonComponent skeletonComponent;
|
||||
IAnimationStateComponent animationStateComponent;
|
||||
|
||||
void Start () {
|
||||
skeletonComponent = skeletonComponent ?? GetComponent<ISkeletonComponent>();
|
||||
if (skeletonComponent == null) return;
|
||||
animationStateComponent = animationStateComponent ?? skeletonComponent as IAnimationStateComponent;
|
||||
if (animationStateComponent == null) return;
|
||||
var skeleton = skeletonComponent.Skeleton;
|
||||
if (skeleton == null) return;
|
||||
|
||||
|
||||
var skeletonData = skeleton.Data;
|
||||
var state = animationStateComponent.AnimationState;
|
||||
foreach (var ep in events) {
|
||||
var eventData = skeletonData.FindEvent(ep.spineEvent);
|
||||
ep.eventDelegate = ep.eventDelegate ?? delegate(TrackEntry trackEntry, Event e) { if (e.Data == eventData) ep.unityHandler.Invoke(); };
|
||||
state.Event += ep.eventDelegate;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy () {
|
||||
animationStateComponent = animationStateComponent ?? GetComponent<IAnimationStateComponent>();
|
||||
if (animationStateComponent == null) return;
|
||||
|
||||
var state = animationStateComponent.AnimationState;
|
||||
foreach (var ep in events) {
|
||||
if (ep.eventDelegate != null) state.Event -= ep.eventDelegate;
|
||||
ep.eventDelegate = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90293750f472d3340b452cec6fea2606
|
||||
timeCreated: 1495263964
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user