提交Spine插件

This commit is contained in:
YiHan0621
2025-08-28 18:32:49 +08:00
parent 254a40d87d
commit 316427ebef
970 changed files with 139525 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
/******************************************************************************
* 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 UnityEngine.UI;
namespace Spine.Unity.Examples {
public class AttackSpineboy : MonoBehaviour {
public SkeletonAnimation spineboy;
public SkeletonAnimation attackerSpineboy;
public SpineGauge gauge;
public Text healthText;
int currentHealth = 100;
const int maxHealth = 100;
public AnimationReferenceAsset shoot, hit, idle, death;
public UnityEngine.Events.UnityEvent onAttack;
void Update () {
if (Input.GetKeyDown(KeyCode.Space)) {
currentHealth -= 10;
healthText.text = currentHealth + "/" + maxHealth;
attackerSpineboy.AnimationState.SetAnimation(1, shoot, false);
attackerSpineboy.AnimationState.AddEmptyAnimation(1, 0.5f, 2f);
if (currentHealth > 0) {
spineboy.AnimationState.SetAnimation(0, hit, false);
spineboy.AnimationState.AddAnimation(0, idle, true, 0);
gauge.fillPercent = (float)currentHealth/(float)maxHealth;
onAttack.Invoke();
} else {
if (currentHealth >= 0) {
gauge.fillPercent = 0;
spineboy.AnimationState.SetAnimation(0, death, false).TrackEnd = float.PositiveInfinity;
}
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7eab8e63d650dc74c80d142cd4b9fe4b
timeCreated: 1480095094
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
/******************************************************************************
* 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 {
public class DataAssetsFromExportsExample : MonoBehaviour {
public TextAsset skeletonJson;
public TextAsset atlasText;
public Texture2D[] textures;
public Material materialPropertySource;
SpineAtlasAsset runtimeAtlasAsset;
SkeletonDataAsset runtimeSkeletonDataAsset;
SkeletonAnimation runtimeSkeletonAnimation;
void CreateRuntimeAssetsAndGameObject () {
// 1. Create the AtlasAsset (needs atlas text asset and textures, and materials/shader);
// 2. Create SkeletonDataAsset (needs json or binary asset file, and an AtlasAsset)
// 3. Create SkeletonAnimation (needs a valid SkeletonDataAsset)
runtimeAtlasAsset = SpineAtlasAsset.CreateRuntimeInstance(atlasText, textures, materialPropertySource, true);
runtimeSkeletonDataAsset = SkeletonDataAsset.CreateRuntimeInstance(skeletonJson, runtimeAtlasAsset, true);
}
IEnumerator Start () {
CreateRuntimeAssetsAndGameObject();
runtimeSkeletonDataAsset.GetSkeletonData(false); // preload.
yield return new WaitForSeconds(0.5f);
runtimeSkeletonAnimation = SkeletonAnimation.NewSkeletonAnimationGameObject(runtimeSkeletonDataAsset);
// Extra Stuff
runtimeSkeletonAnimation.Initialize(false);
runtimeSkeletonAnimation.Skeleton.SetSkin("base");
runtimeSkeletonAnimation.Skeleton.SetSlotsToSetupPose();
runtimeSkeletonAnimation.AnimationState.SetAnimation(0, "run", true);
runtimeSkeletonAnimation.GetComponent<MeshRenderer>().sortingOrder = 10;
runtimeSkeletonAnimation.transform.Translate(Vector3.down * 2);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bb0837af7345d504db63d0c662fd12dc
timeCreated: 1500249349
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
/******************************************************************************
* 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 {
public class DraggableTransform : MonoBehaviour {
Vector2 mousePreviousWorld, mouseDeltaWorld;
Camera mainCamera;
void Start () {
mainCamera = Camera.main;
}
void Update () {
Vector2 mouseCurrent = Input.mousePosition;
Vector2 mouseCurrentWorld = mainCamera.ScreenToWorldPoint(new Vector3(mouseCurrent.x, mouseCurrent.y, -mainCamera.transform.position.z));
mouseDeltaWorld = mouseCurrentWorld - mousePreviousWorld;
mousePreviousWorld = mouseCurrentWorld;
}
void OnMouseDrag () {
transform.Translate(mouseDeltaWorld);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ac0a69923492d1b4aa7ca656033ec6a3
timeCreated: 1520587078
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,103 @@
/******************************************************************************
* 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.
*****************************************************************************/
// Contributed by: Mitch Thompson
using UnityEngine;
using System.Collections;
using Spine.Unity;
namespace Spine.Unity.Examples {
public class FootSoldierExample : MonoBehaviour {
[SpineAnimation("Idle")]
public string idleAnimation;
[SpineAnimation]
public string attackAnimation;
[SpineAnimation]
public string moveAnimation;
[SpineSlot]
public string eyesSlot;
[SpineAttachment(currentSkinOnly: true, slotField: "eyesSlot")]
public string eyesOpenAttachment;
[SpineAttachment(currentSkinOnly: true, slotField: "eyesSlot")]
public string blinkAttachment;
[Range(0, 0.2f)]
public float blinkDuration = 0.05f;
public KeyCode attackKey = KeyCode.Mouse0;
public KeyCode rightKey = KeyCode.D;
public KeyCode leftKey = KeyCode.A;
public float moveSpeed = 3;
SkeletonAnimation skeletonAnimation;
void Awake () {
skeletonAnimation = GetComponent<SkeletonAnimation>();
skeletonAnimation.OnRebuild += Apply;
}
void Apply (SkeletonRenderer skeletonRenderer) {
StartCoroutine("Blink");
}
void Update () {
if (Input.GetKey(attackKey)) {
skeletonAnimation.AnimationName = attackAnimation;
} else {
if (Input.GetKey(rightKey)) {
skeletonAnimation.AnimationName = moveAnimation;
skeletonAnimation.Skeleton.ScaleX = 1;
transform.Translate(moveSpeed * Time.deltaTime, 0, 0);
} else if(Input.GetKey(leftKey)) {
skeletonAnimation.AnimationName = moveAnimation;
skeletonAnimation.Skeleton.ScaleX = -1;
transform.Translate(-moveSpeed * Time.deltaTime, 0, 0);
} else {
skeletonAnimation.AnimationName = idleAnimation;
}
}
}
IEnumerator Blink() {
while (true) {
yield return new WaitForSeconds(Random.Range(0.25f, 3f));
skeletonAnimation.Skeleton.SetAttachment(eyesSlot, blinkAttachment);
yield return new WaitForSeconds(blinkDuration);
skeletonAnimation.Skeleton.SetAttachment(eyesSlot, eyesOpenAttachment);
}
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 3c826b50b0cfee343be3bdbbf59d0f7c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@@ -0,0 +1,220 @@
/******************************************************************************
* 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 UnityEngine.Events;
using Spine.Unity;
namespace Spine.Unity.Examples {
[RequireComponent(typeof(CharacterController))]
public class BasicPlatformerController : MonoBehaviour {
public enum CharacterState {
None,
Idle,
Walk,
Run,
Crouch,
Rise,
Fall,
Attack
}
[Header("Components")]
public CharacterController controller;
[Header("Controls")]
public string XAxis = "Horizontal";
public string YAxis = "Vertical";
public string JumpButton = "Jump";
[Header("Moving")]
public float walkSpeed = 1.5f;
public float runSpeed = 7f;
public float gravityScale = 6.6f;
[Header("Jumping")]
public float jumpSpeed = 25;
public float minimumJumpDuration = 0.5f;
public float jumpInterruptFactor = 0.5f;
public float forceCrouchVelocity = 25;
public float forceCrouchDuration = 0.5f;
[Header("Animation")]
public SkeletonAnimationHandleExample animationHandle;
// Events
public event UnityAction OnJump, OnLand, OnHardLand;
Vector2 input = default(Vector2);
Vector3 velocity = default(Vector3);
float minimumJumpEndTime = 0;
float forceCrouchEndTime;
bool wasGrounded = false;
CharacterState previousState, currentState;
void Update () {
float dt = Time.deltaTime;
bool isGrounded = controller.isGrounded;
bool landed = !wasGrounded && isGrounded;
// Dummy input.
input.x = Input.GetAxis(XAxis);
input.y = Input.GetAxis(YAxis);
bool inputJumpStop = Input.GetButtonUp(JumpButton);
bool inputJumpStart = Input.GetButtonDown(JumpButton);
bool doCrouch = (isGrounded && input.y < -0.5f) || (forceCrouchEndTime > Time.time);
bool doJumpInterrupt = false;
bool doJump = false;
bool hardLand = false;
if (landed) {
if (-velocity.y > forceCrouchVelocity) {
hardLand = true;
doCrouch = true;
forceCrouchEndTime = Time.time + forceCrouchDuration;
}
}
if (!doCrouch) {
if (isGrounded) {
if (inputJumpStart) {
doJump = true;
}
} else {
doJumpInterrupt = inputJumpStop && Time.time < minimumJumpEndTime;
}
}
// Dummy physics and controller using UnityEngine.CharacterController.
Vector3 gravityDeltaVelocity = Physics.gravity * gravityScale * dt;
if (doJump) {
velocity.y = jumpSpeed;
minimumJumpEndTime = Time.time + minimumJumpDuration;
} else if (doJumpInterrupt) {
if (velocity.y > 0)
velocity.y *= jumpInterruptFactor;
}
velocity.x = 0;
if (!doCrouch) {
if (input.x != 0) {
velocity.x = Mathf.Abs(input.x) > 0.6f ? runSpeed : walkSpeed;
velocity.x *= Mathf.Sign(input.x);
}
}
if (!isGrounded) {
if (wasGrounded) {
if (velocity.y < 0)
velocity.y = 0;
} else {
velocity += gravityDeltaVelocity;
}
}
controller.Move(velocity * dt);
wasGrounded = isGrounded;
// Determine and store character state
if (isGrounded) {
if (doCrouch) {
currentState = CharacterState.Crouch;
} else {
if (input.x == 0)
currentState = CharacterState.Idle;
else
currentState = Mathf.Abs(input.x) > 0.6f ? CharacterState.Run : CharacterState.Walk;
}
} else {
currentState = velocity.y > 0 ? CharacterState.Rise : CharacterState.Fall;
}
bool stateChanged = previousState != currentState;
previousState = currentState;
// Animation
// Do not modify character parameters or state in this phase. Just read them.
// Detect changes in state, and communicate with animation handle if it changes.
if (stateChanged)
HandleStateChanged();
if (input.x != 0)
animationHandle.SetFlip(input.x);
// Fire events.
if (doJump) {
OnJump.Invoke();
}
if (landed) {
if (hardLand) {
OnHardLand.Invoke();
} else {
OnLand.Invoke();
}
}
}
void HandleStateChanged () {
// When the state changes, notify the animation handle of the new state.
string stateName = null;
switch (currentState) {
case CharacterState.Idle:
stateName = "idle";
break;
case CharacterState.Walk:
stateName = "walk";
break;
case CharacterState.Run:
stateName = "run";
break;
case CharacterState.Crouch:
stateName = "crouch";
break;
case CharacterState.Rise:
stateName = "rise";
break;
case CharacterState.Fall:
stateName = "fall";
break;
case CharacterState.Attack:
stateName = "attack";
break;
default:
break;
}
animationHandle.PlayAnimationForState(stateName, 0);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 27b3e3370f55c0a438ef0a10c2eba510
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,52 @@
/******************************************************************************
* 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.
*****************************************************************************/
// Contributed by: Mitch Thompson
using UnityEngine;
namespace Spine.Unity.Examples {
public class ConstrainedCamera : MonoBehaviour {
public Transform target;
public Vector3 offset;
public Vector3 min;
public Vector3 max;
public float smoothing = 5f;
// Update is called once per frame
void LateUpdate () {
Vector3 goalPoint = target.position + offset;
goalPoint.x = Mathf.Clamp(goalPoint.x, min.x, max.x);
goalPoint.y = Mathf.Clamp(goalPoint.y, min.y, max.y);
goalPoint.z = Mathf.Clamp(goalPoint.z, min.z, max.z);
transform.position = Vector3.Lerp(transform.position, goalPoint, smoothing * Time.deltaTime);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6df2d8b571e22504284108b691b4a3cd
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,66 @@
/******************************************************************************
* 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;
using Spine.Unity;
namespace Spine.Unity.Examples {
public class Raptor : MonoBehaviour {
#region Inspector
public AnimationReferenceAsset walk;
public AnimationReferenceAsset gungrab;
public AnimationReferenceAsset gunkeep;
#endregion
SkeletonAnimation skeletonAnimation;
void Start () {
skeletonAnimation = GetComponent<SkeletonAnimation>();
StartCoroutine(GunGrabRoutine());
}
IEnumerator GunGrabRoutine () {
// Play the walk animation on track 0.
skeletonAnimation.AnimationState.SetAnimation(0, walk, true);
// Repeatedly play the gungrab and gunkeep animation on track 1.
while (true) {
yield return new WaitForSeconds(Random.Range(0.5f, 3f));
skeletonAnimation.AnimationState.SetAnimation(1, gungrab, false);
yield return new WaitForSeconds(Random.Range(0.5f, 3f));
skeletonAnimation.AnimationState.SetAnimation(1, gunkeep, false);
}
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 8b0d38dc0b91fb443a41838d475ae49b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,109 @@
/******************************************************************************
* 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;
using Spine.Unity;
namespace Spine.Unity.Examples {
public class SpineBeginnerTwo : MonoBehaviour {
#region Inspector
// [SpineAnimation] attribute allows an Inspector dropdown of Spine animation names coming form SkeletonAnimation.
[SpineAnimation]
public string runAnimationName;
[SpineAnimation]
public string idleAnimationName;
[SpineAnimation]
public string walkAnimationName;
[SpineAnimation]
public string shootAnimationName;
[Header("Transitions")]
[SpineAnimation]
public string idleTurnAnimationName;
[SpineAnimation]
public string runToIdleAnimationName;
public float runWalkDuration = 1.5f;
#endregion
SkeletonAnimation skeletonAnimation;
// Spine.AnimationState and Spine.Skeleton are not Unity-serialized objects. You will not see them as fields in the inspector.
public Spine.AnimationState spineAnimationState;
public Spine.Skeleton skeleton;
void Start () {
// Make sure you get these AnimationState and Skeleton references in Start or Later.
// Getting and using them in Awake is not guaranteed by default execution order.
skeletonAnimation = GetComponent<SkeletonAnimation>();
spineAnimationState = skeletonAnimation.AnimationState;
skeleton = skeletonAnimation.Skeleton;
StartCoroutine(DoDemoRoutine());
}
/// This is an infinitely repeating Unity Coroutine. Read the Unity documentation on Coroutines to learn more.
IEnumerator DoDemoRoutine () {
while (true) {
// SetAnimation is the basic way to set an animation.
// SetAnimation sets the animation and starts playing it from the beginning.
// Common Mistake: If you keep calling it in Update, it will keep showing the first pose of the animation, do don't do that.
spineAnimationState.SetAnimation(0, walkAnimationName, true);
yield return new WaitForSeconds(runWalkDuration);
spineAnimationState.SetAnimation(0, runAnimationName, true);
yield return new WaitForSeconds(runWalkDuration);
// AddAnimation queues up an animation to play after the previous one ends.
spineAnimationState.SetAnimation(0, runToIdleAnimationName, false);
spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
yield return new WaitForSeconds(1f);
skeleton.ScaleX = -1; // skeleton allows you to flip the skeleton.
spineAnimationState.SetAnimation(0, idleTurnAnimationName, false);
spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
yield return new WaitForSeconds(0.5f);
skeleton.ScaleX = 1;
spineAnimationState.SetAnimation(0, idleTurnAnimationName, false);
spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
yield return new WaitForSeconds(0.5f);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a57fe3aaf2b1f964182d90c5546754d1
timeCreated: 1452593662
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
/******************************************************************************
* 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;
using Spine.Unity;
namespace Spine.Unity.Examples {
public class SpineBlinkPlayer : MonoBehaviour {
const int BlinkTrack = 1;
public AnimationReferenceAsset blinkAnimation;
public float minimumDelay = 0.15f;
public float maximumDelay = 3f;
IEnumerator Start () {
var skeletonAnimation = GetComponent<SkeletonAnimation>(); if (skeletonAnimation == null) yield break;
while (true) {
skeletonAnimation.AnimationState.SetAnimation(SpineBlinkPlayer.BlinkTrack, blinkAnimation, false);
yield return new WaitForSeconds(Random.Range(minimumDelay, maximumDelay));
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5a5ef44bf3e0d864794c0da71c84363d
timeCreated: 1455509353
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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 UnityEngine;
using System.Collections;
namespace Spine.Unity.Examples {
public class SpineboyBeginnerInput : MonoBehaviour {
#region Inspector
public string horizontalAxis = "Horizontal";
public string attackButton = "Fire1";
public string jumpButton = "Jump";
public SpineboyBeginnerModel model;
void OnValidate () {
if (model == null)
model = GetComponent<SpineboyBeginnerModel>();
}
#endregion
void Update () {
if (model == null) return;
float currentHorizontal = Input.GetAxisRaw(horizontalAxis);
model.TryMove(currentHorizontal);
if (Input.GetButton(attackButton))
model.TryShoot();
if (Input.GetButtonDown(jumpButton))
model.TryJump();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8f685123e0610c347a7b2c03c8a19535
timeCreated: 1452595430
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,114 @@
/******************************************************************************
* 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;
namespace Spine.Unity.Examples {
[SelectionBase]
public class SpineboyBeginnerModel : MonoBehaviour {
#region Inspector
[Header("Current State")]
public SpineBeginnerBodyState state;
public bool facingLeft;
[Range(-1f, 1f)]
public float currentSpeed;
[Header("Balance")]
public float shootInterval = 0.12f;
#endregion
float lastShootTime;
public event System.Action ShootEvent; // Lets other scripts know when Spineboy is shooting. Check C# Documentation to learn more about events and delegates.
#region API
public void TryJump () {
StartCoroutine(JumpRoutine());
}
public void TryShoot () {
float currentTime = Time.time;
if (currentTime - lastShootTime > shootInterval) {
lastShootTime = currentTime;
if (ShootEvent != null) ShootEvent(); // Fire the "ShootEvent" event.
}
}
public void TryMove (float speed) {
currentSpeed = speed; // show the "speed" in the Inspector.
if (speed != 0) {
bool speedIsNegative = (speed < 0f);
facingLeft = speedIsNegative; // Change facing direction whenever speed is not 0.
}
if (state != SpineBeginnerBodyState.Jumping) {
state = (speed == 0) ? SpineBeginnerBodyState.Idle : SpineBeginnerBodyState.Running;
}
}
#endregion
IEnumerator JumpRoutine () {
if (state == SpineBeginnerBodyState.Jumping) yield break; // Don't jump when already jumping.
state = SpineBeginnerBodyState.Jumping;
// Fake jumping.
{
var pos = transform.localPosition;
const float jumpTime = 1.2f;
const float half = jumpTime * 0.5f;
const float jumpPower = 20f;
for (float t = 0; t < half; t += Time.deltaTime) {
float d = jumpPower * (half - t);
transform.Translate((d * Time.deltaTime) * Vector3.up);
yield return null;
}
for (float t = 0; t < half; t += Time.deltaTime) {
float d = jumpPower * t;
transform.Translate((d * Time.deltaTime) * Vector3.down);
yield return null;
}
transform.localPosition = pos;
}
state = SpineBeginnerBodyState.Idle;
}
}
public enum SpineBeginnerBodyState {
Idle,
Running,
Jumping
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f999dde27e9711a45b0ee1b0d25217ec
timeCreated: 1452594812
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,148 @@
/******************************************************************************
* 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;
using Spine.Unity;
namespace Spine.Unity.Examples {
public class SpineboyBeginnerView : MonoBehaviour {
#region Inspector
[Header("Components")]
public SpineboyBeginnerModel model;
public SkeletonAnimation skeletonAnimation;
public AnimationReferenceAsset run, idle, shoot, jump;
public EventDataReferenceAsset footstepEvent;
[Header("Audio")]
public float footstepPitchOffset = 0.2f;
public float gunsoundPitchOffset = 0.13f;
public AudioSource footstepSource, gunSource, jumpSource;
[Header("Effects")]
public ParticleSystem gunParticles;
#endregion
SpineBeginnerBodyState previousViewState;
void Start () {
if (skeletonAnimation == null) return;
model.ShootEvent += PlayShoot;
skeletonAnimation.AnimationState.Event += HandleEvent;
}
void HandleEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
if (e.Data == footstepEvent.EventData)
PlayFootstepSound();
}
void Update () {
if (skeletonAnimation == null) return;
if (model == null) return;
if ((skeletonAnimation.skeleton.ScaleX < 0) != model.facingLeft) { // Detect changes in model.facingLeft
Turn(model.facingLeft);
}
// Detect changes in model.state
var currentModelState = model.state;
if (previousViewState != currentModelState) {
PlayNewStableAnimation();
}
previousViewState = currentModelState;
}
void PlayNewStableAnimation () {
var newModelState = model.state;
Animation nextAnimation;
// Add conditionals to not interrupt transient animations.
if (previousViewState == SpineBeginnerBodyState.Jumping && newModelState != SpineBeginnerBodyState.Jumping) {
PlayFootstepSound();
}
if (newModelState == SpineBeginnerBodyState.Jumping) {
jumpSource.Play();
nextAnimation = jump;
} else {
if (newModelState == SpineBeginnerBodyState.Running) {
nextAnimation = run;
} else {
nextAnimation = idle;
}
}
skeletonAnimation.AnimationState.SetAnimation(0, nextAnimation, true);
}
void PlayFootstepSound () {
footstepSource.Play();
footstepSource.pitch = GetRandomPitch(footstepPitchOffset);
}
[ContextMenu("Check Tracks")]
void CheckTracks () {
var state = skeletonAnimation.AnimationState;
Debug.Log(state.GetCurrent(0));
Debug.Log(state.GetCurrent(1));
}
#region Transient Actions
public void PlayShoot () {
// Play the shoot animation on track 1.
var track = skeletonAnimation.AnimationState.SetAnimation(1, shoot, false);
track.AttachmentThreshold = 1f;
track.MixDuration = 0f;
var empty = skeletonAnimation.state.AddEmptyAnimation(1, 0.5f, 0.1f);
empty.AttachmentThreshold = 1f;
gunSource.pitch = GetRandomPitch(gunsoundPitchOffset);
gunSource.Play();
//gunParticles.randomSeed = (uint)Random.Range(0, 100);
gunParticles.Play();
}
public void Turn (bool facingLeft) {
skeletonAnimation.Skeleton.ScaleX = facingLeft ? -1f : 1f;
// Maybe play a transient turning animation too, then call ChangeStableAnimation.
}
#endregion
#region Utility
public float GetRandomPitch (float maxPitchOffset) {
return 1f + Random.Range(-maxPitchOffset, maxPitchOffset);
}
#endregion
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b59f510ae90fd1a419f19ed805e6e229
timeCreated: 1452594730
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,61 @@
/******************************************************************************
* 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.Examples {
public class SpineboyTargetController : MonoBehaviour {
public SkeletonAnimation skeletonAnimation;
[SpineBone(dataField:"skeletonAnimation")]
public string boneName;
public new Camera camera;
Bone bone;
void OnValidate () {
if (skeletonAnimation == null) skeletonAnimation = GetComponent<SkeletonAnimation>();
}
void Start () {
bone = skeletonAnimation.Skeleton.FindBone(boneName);
}
void Update () {
var mousePosition = Input.mousePosition;
var worldMousePosition = camera.ScreenToWorldPoint(mousePosition);
var skeletonSpacePoint = skeletonAnimation.transform.InverseTransformPoint(worldMousePosition);
skeletonSpacePoint.x *= skeletonAnimation.Skeleton.ScaleX;
skeletonSpacePoint.y *= skeletonAnimation.Skeleton.ScaleY;
bone.SetLocalPosition(skeletonSpacePoint);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: af275876c7b01264b85161629a9bc217
timeCreated: 1489915484
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
/******************************************************************************
* 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 an example of how you could store animation transitions for use in your animation system.
// More ideally, this would be stored in a ScriptableObject in asset form rather than in a MonoBehaviour.
public sealed class TransitionDictionaryExample : MonoBehaviour {
[System.Serializable]
public struct SerializedEntry {
public AnimationReferenceAsset from;
public AnimationReferenceAsset to;
public AnimationReferenceAsset transition;
}
[SerializeField]
List<SerializedEntry> transitions = new List<SerializedEntry>();
readonly Dictionary<AnimationStateData.AnimationPair, Animation> dictionary = new Dictionary<AnimationStateData.AnimationPair, Animation>();
void Start () {
dictionary.Clear();
foreach (var e in transitions) {
dictionary.Add(new AnimationStateData.AnimationPair(e.from.Animation, e.to.Animation), e.transition.Animation);
}
}
public Animation GetTransition (Animation from, Animation to) {
Animation result;
dictionary.TryGetValue(new AnimationStateData.AnimationPair(from, to), out result);
return result;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 69a52bf79b7e78e4cb1dfd2d2e698c2d
timeCreated: 1524024687
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,67 @@
/******************************************************************************
* 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 Goblins : MonoBehaviour {
SkeletonAnimation skeletonAnimation;
Bone headBone;
bool girlSkin;
[Range(-360, 360)]
public float extraRotation;
public void Start () {
skeletonAnimation = GetComponent<SkeletonAnimation>();
headBone = skeletonAnimation.Skeleton.FindBone("head");
skeletonAnimation.UpdateLocal += UpdateLocal;
}
// This is called after the animation is applied to the skeleton and can be used to adjust the bones dynamically.
public void UpdateLocal (ISkeletonAnimation skeletonRenderer) {
headBone.Rotation += extraRotation;
}
public void OnMouseDown () {
skeletonAnimation.Skeleton.SetSkin(girlSkin ? "goblin" : "goblingirl");
skeletonAnimation.Skeleton.SetSlotsToSetupPose();
girlSkin = !girlSkin;
if (girlSkin) {
skeletonAnimation.Skeleton.SetAttachment("right hand item", null);
skeletonAnimation.Skeleton.SetAttachment("left hand item", "spear");
} else
skeletonAnimation.Skeleton.SetAttachment("left hand item", "dagger");
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 40a82af6554a7594f9ffa9ac8dde212f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
using System.Collections.Generic;
using UnityEngine;
namespace Spine.Unity.Examples {
public class HandleEventWithAudioExample : MonoBehaviour {
public SkeletonAnimation skeletonAnimation;
[SpineEvent(dataField: "skeletonAnimation", fallbackToTextField: true)]
public string eventName;
[Space]
public AudioSource audioSource;
public AudioClip audioClip;
public float basePitch = 1f;
public float randomPitchOffset = 0.1f;
[Space]
public bool logDebugMessage = false;
Spine.EventData eventData;
void OnValidate () {
if (skeletonAnimation == null) GetComponent<SkeletonAnimation>();
if (audioSource == null) GetComponent<AudioSource>();
}
void Start () {
if (audioSource == null) return;
if (skeletonAnimation == null) return;
skeletonAnimation.Initialize(false);
if (!skeletonAnimation.valid) return;
eventData = skeletonAnimation.Skeleton.Data.FindEvent(eventName);
skeletonAnimation.AnimationState.Event += HandleAnimationStateEvent;
}
private void HandleAnimationStateEvent (TrackEntry trackEntry, Event e) {
if (logDebugMessage) Debug.Log("Event fired! " + e.Data.Name);
//bool eventMatch = string.Equals(e.Data.Name, eventName, System.StringComparison.Ordinal); // Testing recommendation: String compare.
bool eventMatch = (eventData == e.Data); // Performance recommendation: Match cached reference instead of string.
if (eventMatch) {
Play();
}
}
public void Play () {
audioSource.pitch = basePitch + Random.Range(-randomPitchOffset, randomPitchOffset);
audioSource.clip = audioClip;
audioSource.Play();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1d55a3bd6ac81af44b2f9a4447f2ae72
timeCreated: 1516481531
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
/******************************************************************************
* 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 UnityEngine.Events;
namespace Spine.Unity.Examples {
public class HeroEffectsHandlerExample : MonoBehaviour {
public BasicPlatformerController eventSource;
public UnityEvent OnJump, OnLand, OnHardLand;
public void Awake () {
if (eventSource == null)
return;
eventSource.OnLand += OnLand.Invoke;
eventSource.OnJump += OnJump.Invoke;
eventSource.OnHardLand += OnHardLand.Invoke;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8a0f8a82c5d8a334db6996478778b892
timeCreated: 1545916292
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
/******************************************************************************
* 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;
public class HurtFlashEffect : MonoBehaviour {
const int DefaultFlashCount = 3;
public int flashCount = DefaultFlashCount;
public Color flashColor = Color.white;
[Range(1f/120f, 1f/15f)]
public float interval = 1f/60f;
public string fillPhaseProperty = "_FillPhase";
public string fillColorProperty = "_FillColor";
MaterialPropertyBlock mpb;
MeshRenderer meshRenderer;
public void Flash () {
if (mpb == null) mpb = new MaterialPropertyBlock();
if (meshRenderer == null) meshRenderer = GetComponent<MeshRenderer>();
meshRenderer.GetPropertyBlock(mpb);
StartCoroutine(FlashRoutine());
}
IEnumerator FlashRoutine () {
if (flashCount < 0) flashCount = DefaultFlashCount;
int fillPhase = Shader.PropertyToID(fillPhaseProperty);
int fillColor = Shader.PropertyToID(fillColorProperty);
var wait = new WaitForSeconds(interval);
for (int i = 0; i < flashCount; i++) {
mpb.SetColor(fillColor, flashColor);
mpb.SetFloat(fillPhase, 1f);
meshRenderer.SetPropertyBlock(mpb);
yield return wait;
mpb.SetFloat(fillPhase, 0f);
meshRenderer.SetPropertyBlock(mpb);
yield return wait;
}
yield return null;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 395f769061839bf488f157c37d23835d
timeCreated: 1497416645
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
namespace Spine.Unity.Examples {
public class MaterialPropertyBlockExample : MonoBehaviour {
public float timeInterval = 1f;
public Gradient randomColors = new Gradient();
public string colorPropertyName = "_FillColor";
MaterialPropertyBlock mpb;
float timeToNextColor = 0;
void Start () {
mpb = new MaterialPropertyBlock();
}
void Update () {
if (timeToNextColor <= 0) {
timeToNextColor = timeInterval;
Color newColor = randomColors.Evaluate(UnityEngine.Random.value);
mpb.SetColor(colorPropertyName, newColor);
GetComponent<MeshRenderer>().SetPropertyBlock(mpb);
}
timeToNextColor -= Time.deltaTime;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0456e5bde0b34594782f280f40128902
timeCreated: 1516388202
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
/******************************************************************************
* 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 {
public class MaterialReplacementExample : MonoBehaviour {
public Material originalMaterial;
public Material replacementMaterial;
public bool replacementEnabled = true;
public SkeletonAnimation skeletonAnimation;
[Space]
public string phasePropertyName = "_FillPhase";
[Range(0f, 1f)] public float phase = 1f;
bool previousEnabled;
MaterialPropertyBlock mpb;
void Start () {
previousEnabled = replacementEnabled;
SetReplacementEnabled(replacementEnabled);
mpb = new MaterialPropertyBlock();
}
void Update () {
mpb.SetFloat(phasePropertyName, phase);
GetComponent<MeshRenderer>().SetPropertyBlock(mpb);
if (previousEnabled != replacementEnabled)
SetReplacementEnabled(replacementEnabled);
previousEnabled = replacementEnabled;
}
void SetReplacementEnabled (bool active) {
if (replacementEnabled) {
skeletonAnimation.CustomMaterialOverride[originalMaterial] = replacementMaterial;
} else {
skeletonAnimation.CustomMaterialOverride.Remove(originalMaterial);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 62982591830b87b45a3f6efd3ee82630
timeCreated: 1539082420
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@@ -0,0 +1,104 @@
/******************************************************************************
* 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 {
public class DummyMecanimControllerExample : MonoBehaviour {
public Animator logicAnimator;
public SkeletonAnimationHandleExample animationHandle;
[Header("Controls")]
public KeyCode walkButton = KeyCode.LeftShift;
public KeyCode jumpButton = KeyCode.Space;
[Header("Animator Properties")]
public string horizontalSpeedProperty = "Speed";
public string verticalSpeedProperty = "VerticalSpeed";
public string groundedProperty = "Grounded";
[Header("Fake Physics")]
public float jumpDuration = 1.5f;
public Vector2 speed;
public bool isGrounded;
void Awake () {
isGrounded = true;
}
void Update () {
float x = Input.GetAxisRaw("Horizontal");
if (Input.GetKey(walkButton)) {
x *= 0.4f;
}
speed.x = x;
// Flip skeleton.
if (x != 0) {
animationHandle.SetFlip(x);
}
if (Input.GetKeyDown(jumpButton)) {
if (isGrounded)
StartCoroutine(FakeJump());
}
logicAnimator.SetFloat(horizontalSpeedProperty, Mathf.Abs(speed.x));
logicAnimator.SetFloat(verticalSpeedProperty, speed.y);
logicAnimator.SetBool(groundedProperty, isGrounded);
}
IEnumerator FakeJump () {
// Rise
isGrounded = false;
speed.y = 10f;
float durationLeft = jumpDuration * 0.5f;
while (durationLeft > 0) {
durationLeft -= Time.deltaTime;
if (!Input.GetKey(jumpButton)) break;
yield return null;
}
// Fall
speed.y = -10f;
float fallDuration = (jumpDuration * 0.5f) - durationLeft;
yield return new WaitForSeconds(fallDuration);
// Land
speed.y = 0f;
isGrounded = true;
yield return null;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 782062825deffd64ba7e7e9f978788e5
timeCreated: 1531300740
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
/******************************************************************************
* 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 StateMachineBehaviour handles sending the Mecanim state information to the component that handles playing the Spine animations.
public class MecanimToAnimationHandleExample : StateMachineBehaviour {
SkeletonAnimationHandleExample animationHandle;
bool initialized;
override public void OnStateEnter (Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (!initialized) {
animationHandle = animator.GetComponent<SkeletonAnimationHandleExample>();
initialized = true;
}
animationHandle.PlayAnimationForState(stateInfo.shortNameHash, layerIndex);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 16f3a0143bc0dbc4793717b6d2ff94a2
timeCreated: 1545230670
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,164 @@
/******************************************************************************
* 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;
namespace Spine.Unity.Examples {
// This is an example of an animation handle. This is implemented with strings as state names.
// Strings can serve as the identifier when Mecanim is used as the state machine and state source.
// If you don't use Mecanim, using custom ScriptableObjects may be a more efficient way to store information about the state and its connection with specific Spine animations.
// This animation handle implementation also comes with a dummy implementation of transition-handling.
public class SkeletonAnimationHandleExample : MonoBehaviour {
public SkeletonAnimation skeletonAnimation;
public List<StateNameToAnimationReference> statesAndAnimations = new List<StateNameToAnimationReference>();
public List<AnimationTransition> transitions = new List<AnimationTransition>(); // Alternately, an AnimationPair-Animation Dictionary (commented out) can be used for more efficient lookups.
[System.Serializable]
public class StateNameToAnimationReference {
public string stateName;
public AnimationReferenceAsset animation;
}
[System.Serializable]
public class AnimationTransition {
public AnimationReferenceAsset from;
public AnimationReferenceAsset to;
public AnimationReferenceAsset transition;
}
//readonly Dictionary<Spine.AnimationStateData.AnimationPair, Spine.Animation> transitionDictionary = new Dictionary<AnimationStateData.AnimationPair, Animation>(Spine.AnimationStateData.AnimationPairComparer.Instance);
public Spine.Animation TargetAnimation { get; private set; }
void Awake () {
// Initialize AnimationReferenceAssets
foreach (var entry in statesAndAnimations) {
entry.animation.Initialize();
}
foreach (var entry in transitions) {
entry.from.Initialize();
entry.to.Initialize();
entry.transition.Initialize();
}
// Build Dictionary
//foreach (var entry in transitions) {
// transitionDictionary.Add(new AnimationStateData.AnimationPair(entry.from.Animation, entry.to.Animation), entry.transition.Animation);
//}
}
/// <summary>Sets the horizontal flip state of the skeleton based on a nonzero float. If negative, the skeleton is flipped. If positive, the skeleton is not flipped.</summary>
public void SetFlip (float horizontal) {
if (horizontal != 0) {
skeletonAnimation.Skeleton.ScaleX = horizontal > 0 ? 1f : -1f;
}
}
/// <summary>Plays an animation based on the state name.</summary>
public void PlayAnimationForState (string stateShortName, int layerIndex) {
PlayAnimationForState(StringToHash(stateShortName), layerIndex);
}
/// <summary>Plays an animation based on the hash of the state name.</summary>
public void PlayAnimationForState (int shortNameHash, int layerIndex) {
var foundAnimation = GetAnimationForState(shortNameHash);
if (foundAnimation == null)
return;
PlayNewAnimation(foundAnimation, layerIndex);
}
/// <summary>Gets a Spine Animation based on the state name.</summary>
public Spine.Animation GetAnimationForState (string stateShortName) {
return GetAnimationForState(StringToHash(stateShortName));
}
/// <summary>Gets a Spine Animation based on the hash of the state name.</summary>
public Spine.Animation GetAnimationForState (int shortNameHash) {
var foundState = statesAndAnimations.Find(entry => StringToHash(entry.stateName) == shortNameHash);
return (foundState == null) ? null : foundState.animation;
}
/// <summary>Play an animation. If a transition animation is defined, the transition is played before the target animation being passed.</summary>
public void PlayNewAnimation (Spine.Animation target, int layerIndex) {
Spine.Animation transition = null;
Spine.Animation current = null;
current = GetCurrentAnimation(layerIndex);
if (current != null)
transition = TryGetTransition(current, target);
if (transition != null) {
skeletonAnimation.AnimationState.SetAnimation(layerIndex, transition, false);
skeletonAnimation.AnimationState.AddAnimation(layerIndex, target, true, 0f);
} else {
skeletonAnimation.AnimationState.SetAnimation(layerIndex, target, true);
}
this.TargetAnimation = target;
}
/// <summary>Play a non-looping animation once then continue playing the state animation.</summary>
public void PlayOneShot (Spine.Animation oneShot, int layerIndex) {
var state = skeletonAnimation.AnimationState;
state.SetAnimation(0, oneShot, false);
var transition = TryGetTransition(oneShot, TargetAnimation);
if (transition != null)
state.AddAnimation(0, transition, false, 0f);
state.AddAnimation(0, this.TargetAnimation, true, 0f);
}
Spine.Animation TryGetTransition (Spine.Animation from, Spine.Animation to) {
foreach (var transition in transitions) {
if (transition.from.Animation == from && transition.to.Animation == to) {
return transition.transition.Animation;
}
}
return null;
//Spine.Animation foundTransition = null;
//transitionDictionary.TryGetValue(new AnimationStateData.AnimationPair(from, to), out foundTransition);
//return foundTransition;
}
Spine.Animation GetCurrentAnimation (int layerIndex) {
var currentTrackEntry = skeletonAnimation.AnimationState.GetCurrent(layerIndex);
return (currentTrackEntry != null) ? currentTrackEntry.Animation : null;
}
int StringToHash (string s) {
return Animator.StringToHash(s);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dd8d49de34fd0724ca8c1ae3c44afe59
timeCreated: 1545230473
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 39dcbd139c9316f46919f47f9706ca79
folderAsset: yes
timeCreated: 1522686452
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
/******************************************************************************
* 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 {
public class EquipAssetExample : ScriptableObject {
public EquipSystemExample.EquipType equipType;
public Sprite sprite;
public string description;
public int yourStats;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dcf21dc1875a05044835c5a6c969bda4
timeCreated: 1522687338
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
/******************************************************************************
* 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 UnityEngine.UI;
namespace Spine.Unity.Examples {
public class EquipButtonExample : MonoBehaviour {
public EquipAssetExample asset;
public EquipSystemExample equipSystem;
public Image inventoryImage;
void OnValidate () {
MatchImage();
}
void MatchImage () {
if (inventoryImage != null)
inventoryImage.sprite = asset.sprite;
}
void Start () {
MatchImage();
var button = GetComponent<Button>();
button.onClick.AddListener(
delegate { equipSystem.Equip(asset); }
);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d818155d239e98d46bb41e307ba270d4
timeCreated: 1522744049
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,98 @@
/******************************************************************************
* 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 EquipSystemExample : MonoBehaviour, IHasSkeletonDataAsset {
// Implementing IHasSkeletonDataAsset allows Spine attribute drawers to automatically detect this component as a skeleton data source.
public SkeletonDataAsset skeletonDataAsset;
SkeletonDataAsset IHasSkeletonDataAsset.SkeletonDataAsset { get { return this.skeletonDataAsset; } }
public Material sourceMaterial;
public bool applyPMA = true;
public List<EquipHook> equippables = new List<EquipHook>();
public EquipsVisualsComponentExample target;
public Dictionary<EquipAssetExample, Attachment> cachedAttachments = new Dictionary<EquipAssetExample, Attachment>();
[System.Serializable]
public class EquipHook {
public EquipType type;
[SpineSlot]
public string slot;
[SpineSkin]
public string templateSkin;
[SpineAttachment(skinField:"templateSkin")]
public string templateAttachment;
}
public enum EquipType {
Gun,
Goggles
}
public void Equip (EquipAssetExample asset) {
var equipType = asset.equipType;
EquipHook howToEquip = equippables.Find(x => x.type == equipType);
var skeletonData = skeletonDataAsset.GetSkeletonData(true);
int slotIndex = skeletonData.FindSlotIndex(howToEquip.slot);
var attachment = GenerateAttachmentFromEquipAsset(asset, slotIndex, howToEquip.templateSkin, howToEquip.templateAttachment);
target.Equip(slotIndex, howToEquip.templateAttachment, attachment);
}
Attachment GenerateAttachmentFromEquipAsset (EquipAssetExample asset, int slotIndex, string templateSkinName, string templateAttachmentName) {
Attachment attachment;
cachedAttachments.TryGetValue(asset, out attachment);
if (attachment == null) {
var skeletonData = skeletonDataAsset.GetSkeletonData(true);
var templateSkin = skeletonData.FindSkin(templateSkinName);
Attachment templateAttachment = templateSkin.GetAttachment(slotIndex, templateAttachmentName);
attachment = templateAttachment.GetRemappedClone(asset.sprite, sourceMaterial, premultiplyAlpha: this.applyPMA);
cachedAttachments.Add(asset, attachment); // Cache this value for next time this asset is used.
}
return attachment;
}
public void Done () {
target.OptimizeSkin();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6159005f7c3d5fd4ba33cff41eae5531
timeCreated: 1522686506
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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 System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine.Unity.Modules.AttachmentTools;
namespace Spine.Unity.Examples {
public class EquipsVisualsComponentExample : MonoBehaviour {
public SkeletonAnimation skeletonAnimation;
[SpineSkin]
public string templateSkinName;
Spine.Skin equipsSkin;
Spine.Skin collectedSkin;
public Material runtimeMaterial;
public Texture2D runtimeAtlas;
void Start () {
equipsSkin = new Skin("Equips");
// OPTIONAL: Add all the attachments from the template skin.
var templateSkin = skeletonAnimation.Skeleton.Data.FindSkin(templateSkinName);
if (templateSkin != null)
equipsSkin.AddAttachments(templateSkin);
skeletonAnimation.Skeleton.Skin = equipsSkin;
RefreshSkeletonAttachments();
}
public void Equip (int slotIndex, string attachmentName, Attachment attachment) {
equipsSkin.AddAttachment(slotIndex, attachmentName, attachment);
skeletonAnimation.Skeleton.SetSkin(equipsSkin);
RefreshSkeletonAttachments();
}
public void OptimizeSkin () {
// 1. Collect all the attachments of all active skins.
collectedSkin = collectedSkin ?? new Skin("Collected skin");
collectedSkin.Clear();
collectedSkin.AddAttachments(skeletonAnimation.Skeleton.Data.DefaultSkin);
collectedSkin.AddAttachments(equipsSkin);
// 2. Create a repacked skin.
var repackedSkin = collectedSkin.GetRepackedSkin("Repacked skin", skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial, out runtimeMaterial, out runtimeAtlas);
collectedSkin.Clear();
// 3. Use the repacked skin.
skeletonAnimation.Skeleton.Skin = repackedSkin;
RefreshSkeletonAttachments();
}
void RefreshSkeletonAttachments () {
skeletonAnimation.Skeleton.SetSlotsToSetupPose();
skeletonAnimation.AnimationState.Apply(skeletonAnimation.Skeleton); //skeletonAnimation.Update(0);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5732385e4912c444dae078ddc7d04c89
timeCreated: 1522688085
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,137 @@
/******************************************************************************
* 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.Modules.AttachmentTools;
using System.Collections;
namespace Spine.Unity.Examples {
// This is an example script that shows you how to change images on your skeleton using UnityEngine.Sprites.
public class MixAndMatch : MonoBehaviour {
#region Inspector
[SpineSkin]
public string templateAttachmentsSkin = "base";
public Material sourceMaterial; // This will be used as the basis for shader and material property settings.
[Header("Visor")]
public Sprite visorSprite;
[SpineSlot] public string visorSlot;
[SpineAttachment(slotField:"visorSlot", skinField:"baseSkinName")] public string visorKey = "goggles";
[Header("Gun")]
public Sprite gunSprite;
[SpineSlot] public string gunSlot;
[SpineAttachment(slotField:"gunSlot", skinField:"baseSkinName")] public string gunKey = "gun";
[Header("Runtime Repack")]
public bool repack = true;
public BoundingBoxFollower bbFollower;
[Header("Do not assign")]
public Texture2D runtimeAtlas;
public Material runtimeMaterial;
#endregion
Skin customSkin;
void OnValidate () {
if (sourceMaterial == null) {
var skeletonAnimation = GetComponent<SkeletonAnimation>();
if (skeletonAnimation != null)
sourceMaterial = skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial;
}
}
IEnumerator Start () {
yield return new WaitForSeconds(1f); // Delay for one second before applying. For testing.
Apply();
}
void Apply () {
var skeletonAnimation = GetComponent<SkeletonAnimation>();
var skeleton = skeletonAnimation.Skeleton;
// STEP 0: PREPARE SKINS
// Let's prepare a new skin to be our custom skin with equips/customizations. We get a clone so our original skins are unaffected.
customSkin = customSkin ?? new Skin("custom skin"); // This requires that all customizations are done with skin placeholders defined in Spine.
//customSkin = customSkin ?? skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState); // use this if you are not customizing on the default skin.
var templateSkin = skeleton.Data.FindSkin(templateAttachmentsSkin);
// STEP 1: "EQUIP" ITEMS USING SPRITES
// STEP 1.1 Find the original/template attachment.
// Step 1.2 Get a clone of the original/template attachment.
// Step 1.3 Apply the Sprite image to the clone.
// Step 1.4 Add the remapped clone to the new custom skin.
// Let's do this for the visor.
int visorSlotIndex = skeleton.FindSlotIndex(visorSlot); // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster.
Attachment templateAttachment = templateSkin.GetAttachment(visorSlotIndex, visorKey); // STEP 1.1
Attachment newAttachment = templateAttachment.GetRemappedClone(visorSprite, sourceMaterial); // STEP 1.2 - 1.3
customSkin.SetAttachment(visorSlotIndex, visorKey, newAttachment); // STEP 1.4
// And now for the gun.
int gunSlotIndex = skeleton.FindSlotIndex(gunSlot);
Attachment templateGun = templateSkin.GetAttachment(gunSlotIndex, gunKey); // STEP 1.1
Attachment newGun = templateGun.GetRemappedClone(gunSprite, sourceMaterial); // STEP 1.2 - 1.3
if (newGun != null) customSkin.SetAttachment(gunSlotIndex, gunKey, newGun); // STEP 1.4
// customSkin.RemoveAttachment(gunSlotIndex, gunKey); // To remove an item.
// customSkin.Clear()
// Use skin.Clear() To remove all customizations.
// Customizations will fall back to the value in the default skin if it was defined there.
// To prevent fallback from happening, make sure the key is not defined in the default skin.
// STEP 3: APPLY AND CLEAN UP.
// Recommended, preferably at level-load-time: REPACK THE CUSTOM SKIN TO MINIMIZE DRAW CALLS
// IMPORTANT NOTE: the GetRepackedSkin() operation is expensive - if multiple characters
// need to call it every few seconds the overhead will outweigh the draw call benefits.
//
// Repacking requires that you set all source textures/sprites/atlases to be Read/Write enabled in the inspector.
// Combine all the attachment sources into one skin. Usually this means the default skin and the custom skin.
// call Skin.GetRepackedSkin to get a cloned skin with cloned attachments that all use one texture.
if (repack) {
var repackedSkin = new Skin("repacked skin");
repackedSkin.AddAttachments(skeleton.Data.DefaultSkin); // Include the "default" skin. (everything outside of skin placeholders)
repackedSkin.AddAttachments(customSkin); // Include your new custom skin.
repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas); // Pack all the items in the skin.
skeleton.SetSkin(repackedSkin); // Assign the repacked skin to your Skeleton.
if (bbFollower != null) bbFollower.Initialize(true);
} else {
skeleton.SetSkin(customSkin); // Just use the custom skin directly.
}
skeleton.SetSlotsToSetupPose(); // Use the pose from setup pose.
skeletonAnimation.Update(0); // Use the pose in the currently active animation.
Resources.UnloadUnusedAssets();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fdd7c8b428f700c438a6a14addca0346
timeCreated: 1480089275
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,136 @@
/******************************************************************************
* 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.Modules.AttachmentTools;
using System.Collections;
namespace Spine.Unity.Examples {
// This is an example script that shows you how to change images on your skeleton using UnityEngine.Sprites.
public class MixAndMatchGraphic : MonoBehaviour {
#region Inspector
[SpineSkin]
public string baseSkinName = "base";
public Material sourceMaterial; // This will be used as the basis for shader and material property settings.
[Header("Visor")]
public Sprite visorSprite;
[SpineSlot] public string visorSlot;
[SpineAttachment(slotField:"visorSlot", skinField:"baseSkinName")] public string visorKey = "goggles";
[Header("Gun")]
public Sprite gunSprite;
[SpineSlot] public string gunSlot;
[SpineAttachment(slotField:"gunSlot", skinField:"baseSkinName")] public string gunKey = "gun";
[Header("Runtime Repack Required!!")]
public bool repack = true;
[Header("Do not assign")]
public Texture2D runtimeAtlas;
public Material runtimeMaterial;
#endregion
Skin customSkin;
void OnValidate () {
if (sourceMaterial == null) {
var skeletonGraphic = GetComponent<SkeletonGraphic>();
if (skeletonGraphic != null)
sourceMaterial = skeletonGraphic.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial;
}
}
IEnumerator Start () {
yield return new WaitForSeconds(1f); // Delay for 1 second. For testing.
Apply();
}
[ContextMenu("Apply")]
void Apply () {
var skeletonGraphic = GetComponent<SkeletonGraphic>();
var skeleton = skeletonGraphic.Skeleton;
// STEP 0: PREPARE SKINS
// Let's prepare a new skin to be our custom skin with equips/customizations. We get a clone so our original skins are unaffected.
customSkin = customSkin ?? new Skin("custom skin"); // This requires that all customizations are done with skin placeholders defined in Spine.
//customSkin = customSkin ?? skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState); // use this if you are not customizing on the default skin and don't plan to remove
// Next let's get the skin that contains our source attachments. These are the attachments that
var baseSkin = skeleton.Data.FindSkin(baseSkinName);
// STEP 1: "EQUIP" ITEMS USING SPRITES
// STEP 1.1 Find the original attachment.
// Step 1.2 Get a clone of the original attachment.
// Step 1.3 Apply the Sprite image to it.
// Step 1.4 Add the remapped clone to the new custom skin.
// Let's do this for the visor.
int visorSlotIndex = skeleton.FindSlotIndex(visorSlot); // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster.
Attachment baseAttachment = baseSkin.GetAttachment(visorSlotIndex, visorKey); // STEP 1.1
Attachment newAttachment = baseAttachment.GetRemappedClone(visorSprite, sourceMaterial); // STEP 1.2 - 1.3
customSkin.SetAttachment(visorSlotIndex, visorKey, newAttachment); // STEP 1.4
// And now for the gun.
int gunSlotIndex = skeleton.FindSlotIndex(gunSlot);
Attachment baseGun = baseSkin.GetAttachment(gunSlotIndex, gunKey); // STEP 1.1
Attachment newGun = baseGun.GetRemappedClone(gunSprite, sourceMaterial); // STEP 1.2 - 1.3
if (newGun != null) customSkin.SetAttachment(gunSlotIndex, gunKey, newGun); // STEP 1.4
// customSkin.RemoveAttachment(gunSlotIndex, gunKey); // To remove an item.
// customSkin.Clear()
// Use skin.Clear() To remove all customizations.
// Customizations will fall back to the value in the default skin if it was defined there.
// To prevent fallback from happening, make sure the key is not defined in the default skin.
// STEP 3: APPLY AND CLEAN UP.
// Recommended: REPACK THE CUSTOM SKIN TO MINIMIZE DRAW CALLS
// Repacking requires that you set all source textures/sprites/atlases to be Read/Write enabled in the inspector.
// Combine all the attachment sources into one skin. Usually this means the default skin and the custom skin.
// call Skin.GetRepackedSkin to get a cloned skin with cloned attachments that all use one texture.
if (repack) {
var repackedSkin = new Skin("repacked skin");
repackedSkin.AddAttachments(skeleton.Data.DefaultSkin);
repackedSkin.AddAttachments(customSkin);
repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas);
skeleton.SetSkin(repackedSkin);
} else {
skeleton.SetSkin(customSkin);
}
//skeleton.SetSlotsToSetupPose();
skeleton.SetToSetupPose();
skeletonGraphic.Update(0);
skeletonGraphic.OverrideTexture = runtimeAtlas;
Resources.UnloadUnusedAssets();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8e24c5293ec0b444eba7a2680caa925f
timeCreated: 1480089275
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
/******************************************************************************
* 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;
using Spine.Unity;
namespace Spine.Unity.Examples {
public class RaggedySpineboy : MonoBehaviour {
public LayerMask groundMask;
public float restoreDuration = 0.5f;
public Vector2 launchVelocity = new Vector2(50,100);
Spine.Unity.Modules.SkeletonRagdoll2D ragdoll;
Collider2D naturalCollider;
void Start () {
ragdoll = GetComponent<Spine.Unity.Modules.SkeletonRagdoll2D>();
naturalCollider = GetComponent<Collider2D>();
}
void AddRigidbody () {
var rb = gameObject.AddComponent<Rigidbody2D>();
rb.freezeRotation = true;
naturalCollider.enabled = true;
}
void RemoveRigidbody () {
Destroy(GetComponent<Rigidbody2D>());
naturalCollider.enabled = false;
}
void OnMouseUp () {
if (naturalCollider.enabled)
Launch();
}
void Launch () {
RemoveRigidbody();
ragdoll.Apply();
ragdoll.RootRigidbody.velocity = new Vector2(Random.Range(-launchVelocity.x, launchVelocity.x), launchVelocity.y);
StartCoroutine(WaitUntilStopped());
}
IEnumerator Restore () {
Vector3 estimatedPos = ragdoll.EstimatedSkeletonPosition;
Vector3 rbPosition = ragdoll.RootRigidbody.position;
Vector3 skeletonPoint = estimatedPos;
RaycastHit2D hit = Physics2D.Raycast((Vector2)rbPosition, (Vector2)(estimatedPos - rbPosition), Vector3.Distance(estimatedPos, rbPosition), groundMask);
if (hit.collider != null)
skeletonPoint = hit.point;
ragdoll.RootRigidbody.isKinematic = true;
ragdoll.SetSkeletonPosition(skeletonPoint);
yield return ragdoll.SmoothMix(0, restoreDuration);
ragdoll.Remove();
AddRigidbody();
}
IEnumerator WaitUntilStopped () {
yield return new WaitForSeconds(0.5f);
float t = 0;
while (t < 0.5f) {
t = (ragdoll.RootRigidbody.velocity.magnitude > 0.09f) ? 0 : t + Time.deltaTime;
yield return null;
}
StartCoroutine(Restore());
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 849a7739a7df0754882fcb34c09df4c1
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,44 @@
/******************************************************************************
* 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 UnityEngine.SceneManagement;
public class ReloadSceneOnKeyDown : MonoBehaviour {
public KeyCode reloadKey = KeyCode.R;
void Update () {
if (Input.GetKeyDown(reloadKey))
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d655607dd16c7f644a73bd10fc7370b1
timeCreated: 1523294158
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
/******************************************************************************
* 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.Examples {
public class Rotator : MonoBehaviour {
public Vector3 direction = new Vector3(0, 0, 1f);
public float speed = 1f;
void Update () {
transform.Rotate(direction * (speed * Time.deltaTime * 100f));
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 12e291cb54756d04c9dd53ad6e00a126
timeCreated: 1479532891
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 037ce88b9252fd241bd99d71721d9205
folderAsset: yes
timeCreated: 1481879243
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 61e6f96a4b02648479575d8b9127f5ed
timeCreated: 1492782100
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e864d2963143ec04eb4f905e6add115e
timeCreated: 1495176902
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@@ -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;
}
}
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: afde57cc4fd39bb4dbd61b73403ae6a8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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.
*****************************************************************************/

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6e55c8477eccddc4cb5c3551a3945ca7
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2ee7b5e36685e2445a0097de42940987
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

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

View File

@@ -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.");
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8b9ca76eac8062f42b99bbf78e777ee1
timeCreated: 1498053868
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8afb2340fbd3fe14f9f4e07cba073e17
timeCreated: 1523229765
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e1670ee04b19c794db301d734c71bdd6
timeCreated: 1545031871
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1258037ca4297c7428842419a266f7a4
folderAsset: yes
timeCreated: 1502103133
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a5ea35d82fb1b5d4583e89b4343976b6
timeCreated: 1502103123
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7e3501002f468384b80d5853d04e19ca
timeCreated: 1494113429
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 49a62759c814e7a458b9026d504e0898
timeCreated: 1489227143
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 90293750f472d3340b452cec6fea2606
timeCreated: 1495263964
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,71 @@
/******************************************************************************
* 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 {
public class SpawnFromSkeletonDataExample : MonoBehaviour {
public SkeletonDataAsset skeletonDataAsset;
[Range(0, 100)]
public int count = 20;
[SpineAnimation(dataField:"skeletonDataAsset")]
public string startingAnimation;
IEnumerator Start () {
if (skeletonDataAsset == null) yield break;
skeletonDataAsset.GetSkeletonData(false); // Preload SkeletonDataAsset.
yield return new WaitForSeconds(1f); // Pretend stuff is happening.
var spineAnimation = skeletonDataAsset.GetSkeletonData(false).FindAnimation(startingAnimation);
for (int i = 0; i < count; i++) {
var sa = SkeletonAnimation.NewSkeletonAnimationGameObject(skeletonDataAsset); // Spawn a new SkeletonAnimation GameObject.
DoExtraStuff(sa, spineAnimation); // optional stuff for fun.
sa.gameObject.name = i.ToString();
yield return new WaitForSeconds(1f/8f);
}
}
void DoExtraStuff (SkeletonAnimation sa, Spine.Animation spineAnimation) {
sa.transform.localPosition = Random.insideUnitCircle * 6f;
sa.transform.SetParent(this.transform, false);
if (spineAnimation != null) {
sa.Initialize(false);
sa.AnimationState.SetAnimation(0, spineAnimation, true);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7193e2e00836b124191dcae19e6c9741
timeCreated: 1500249330
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
namespace Spine.Unity.Examples {
public class SpawnSkeletonGraphicExample : MonoBehaviour {
public SkeletonDataAsset skeletonDataAsset;
[SpineAnimation(dataField: "skeletonDataAsset")]
public string startingAnimation;
[SpineSkin(dataField: "skeletonDataAsset")]
public string startingSkin = "base";
public Material skeletonGraphicMaterial;
IEnumerator Start () {
if (skeletonDataAsset == null) yield break;
skeletonDataAsset.GetSkeletonData(false); // Preload SkeletonDataAsset.
yield return new WaitForSeconds(1f); // Pretend stuff is happening.
var sg = SkeletonGraphic.NewSkeletonGraphicGameObject(skeletonDataAsset, this.transform, skeletonGraphicMaterial); // Spawn a new SkeletonGraphic GameObject.
sg.gameObject.name = "SkeletonGraphic Instance";
// Extra Stuff
sg.Initialize(false);
sg.Skeleton.SetSkin(startingSkin);
sg.Skeleton.SetSlotsToSetupPose();
sg.AnimationState.SetAnimation(0, startingAnimation, true);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dd4ba29b300e5cc408471ea14fa3551a
timeCreated: 1547045161
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
/******************************************************************************
* 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 {
[ExecuteInEditMode]
[RequireComponent(typeof(SkeletonRenderer))]
public class SpineGauge : MonoBehaviour {
#region Inspector
[Range(0,1)]
public float fillPercent = 0;
public AnimationReferenceAsset fillAnimation;
#endregion
SkeletonRenderer skeletonRenderer;
void Awake () {
skeletonRenderer = GetComponent<SkeletonRenderer>();
}
void Update () {
SetGaugePercent(fillPercent);
}
public void SetGaugePercent (float percent) {
if (skeletonRenderer == null) return;
var skeleton = skeletonRenderer.skeleton; if (skeleton == null) return;
fillAnimation.Animation.PoseSkeleton(skeleton, percent);
skeleton.Update(Time.deltaTime);
skeleton.UpdateWorldTransform();
}
}
}

Some files were not shown because too many files have changed in this diff Show More