init
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using Spine.Unity;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27b3e3370f55c0a438ef0a10c2eba510
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
52
Assets/Spine Examples/Scripts/Getting Started Scripts/ConstrainedCamera.cs
Executable file
52
Assets/Spine Examples/Scripts/Getting Started Scripts/ConstrainedCamera.cs
Executable file
@@ -0,0 +1,52 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6df2d8b571e22504284108b691b4a3cd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
66
Assets/Spine Examples/Scripts/Getting Started Scripts/Raptor.cs
Executable file
66
Assets/Spine Examples/Scripts/Getting Started Scripts/Raptor.cs
Executable file
@@ -0,0 +1,66 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using Spine.Unity;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
10
Assets/Spine Examples/Scripts/Getting Started Scripts/Raptor.cs.meta
Executable file
10
Assets/Spine Examples/Scripts/Getting Started Scripts/Raptor.cs.meta
Executable file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b0d38dc0b91fb443a41838d475ae49b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Spine Examples/Scripts/Getting Started Scripts/SpineBeginnerTwo.cs
Executable file
109
Assets/Spine Examples/Scripts/Getting Started Scripts/SpineBeginnerTwo.cs
Executable file
@@ -0,0 +1,109 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using Spine.Unity;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a57fe3aaf2b1f964182d90c5546754d1
|
||||
timeCreated: 1452593662
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Spine Examples/Scripts/Getting Started Scripts/SpineBlinkPlayer.cs
Executable file
51
Assets/Spine Examples/Scripts/Getting Started Scripts/SpineBlinkPlayer.cs
Executable file
@@ -0,0 +1,51 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using Spine.Unity;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a5ef44bf3e0d864794c0da71c84363d
|
||||
timeCreated: 1455509353
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
public class SpineboyBeginnerInput : MonoBehaviour {
|
||||
#region Inspector
|
||||
public string horizontalAxis = "Horizontal";
|
||||
public string attackButton = "Fire1";
|
||||
public string aimButton = "Fire2";
|
||||
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(aimButton))
|
||||
model.StartAim();
|
||||
if (Input.GetButtonUp(aimButton))
|
||||
model.StopAim();
|
||||
|
||||
if (Input.GetButtonDown(jumpButton))
|
||||
model.TryJump();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f685123e0610c347a7b2c03c8a19535
|
||||
timeCreated: 1452595430
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
124
Assets/Spine Examples/Scripts/Getting Started Scripts/SpineboyBeginnerModel.cs
Executable file
124
Assets/Spine Examples/Scripts/Getting Started Scripts/SpineboyBeginnerModel.cs
Executable file
@@ -0,0 +1,124 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
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.
|
||||
public event System.Action StartAimEvent; // Lets other scripts know when Spineboy is aiming.
|
||||
public event System.Action StopAimEvent; // Lets other scripts know when Spineboy is no longer aiming.
|
||||
|
||||
#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 StartAim () {
|
||||
if (StartAimEvent != null) StartAimEvent(); // Fire the "StartAimEvent" event.
|
||||
}
|
||||
|
||||
public void StopAim () {
|
||||
if (StopAimEvent != null) StopAimEvent(); // Fire the "StopAimEvent" 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f999dde27e9711a45b0ee1b0d25217ec
|
||||
timeCreated: 1452594812
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
167
Assets/Spine Examples/Scripts/Getting Started Scripts/SpineboyBeginnerView.cs
Executable file
167
Assets/Spine Examples/Scripts/Getting Started Scripts/SpineboyBeginnerView.cs
Executable file
@@ -0,0 +1,167 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using Spine.Unity;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
public class SpineboyBeginnerView : MonoBehaviour {
|
||||
|
||||
#region Inspector
|
||||
[Header("Components")]
|
||||
public SpineboyBeginnerModel model;
|
||||
public SkeletonAnimation skeletonAnimation;
|
||||
|
||||
public AnimationReferenceAsset run, idle, aim, 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;
|
||||
model.StartAimEvent += StartPlayingAim;
|
||||
model.StopAimEvent += StopPlayingAim;
|
||||
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 shootTrack = skeletonAnimation.AnimationState.SetAnimation(1, shoot, false);
|
||||
shootTrack.AttachmentThreshold = 1f;
|
||||
shootTrack.MixDuration = 0f;
|
||||
skeletonAnimation.state.AddEmptyAnimation(1, 0.5f, 0.1f);
|
||||
|
||||
// Play the aim animation on track 2 to aim at the mouse target.
|
||||
var aimTrack = skeletonAnimation.AnimationState.SetAnimation(2, aim, false);
|
||||
aimTrack.AttachmentThreshold = 1f;
|
||||
aimTrack.MixDuration = 0f;
|
||||
skeletonAnimation.state.AddEmptyAnimation(2, 0.5f, 0.1f);
|
||||
|
||||
gunSource.pitch = GetRandomPitch(gunsoundPitchOffset);
|
||||
gunSource.Play();
|
||||
//gunParticles.randomSeed = (uint)Random.Range(0, 100);
|
||||
gunParticles.Play();
|
||||
}
|
||||
|
||||
public void StartPlayingAim () {
|
||||
// Play the aim animation on track 2 to aim at the mouse target.
|
||||
var aimTrack = skeletonAnimation.AnimationState.SetAnimation(2, aim, true);
|
||||
aimTrack.AttachmentThreshold = 1f;
|
||||
aimTrack.MixDuration = 0f;
|
||||
}
|
||||
|
||||
public void StopPlayingAim () {
|
||||
skeletonAnimation.state.AddEmptyAnimation(2, 0.5f, 0.1f);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b59f510ae90fd1a419f19ed805e6e229
|
||||
timeCreated: 1452594730
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, 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 Camera cam;
|
||||
|
||||
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 = cam.ScreenToWorldPoint(mousePosition);
|
||||
var skeletonSpacePoint = skeletonAnimation.transform.InverseTransformPoint(worldMousePosition);
|
||||
skeletonSpacePoint.x *= skeletonAnimation.Skeleton.ScaleX;
|
||||
skeletonSpacePoint.y *= skeletonAnimation.Skeleton.ScaleY;
|
||||
bone.SetLocalPosition(skeletonSpacePoint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af275876c7b01264b85161629a9bc217
|
||||
timeCreated: 1489915484
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE 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
|
||||
* THE SPINE RUNTIMES, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69a52bf79b7e78e4cb1dfd2d2e698c2d
|
||||
timeCreated: 1524024687
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user