1
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7eab8e63d650dc74c80d142cd4b9fe4b
|
||||
timeCreated: 1480095094
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,73 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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 {
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb0837af7345d504db63d0c662fd12dc
|
||||
timeCreated: 1500249349
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,220 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27b3e3370f55c0a438ef0a10c2eba510
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,52 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6df2d8b571e22504284108b691b4a3cd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,245 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
|
||||
//[CreateAssetMenu(menuName = "Spine/SkeletonData Modifiers/Animation Match", order = 200)]
|
||||
public class AnimationMatchModifierAsset : SkeletonDataModifierAsset {
|
||||
|
||||
public bool matchAllAnimations = true;
|
||||
|
||||
public override void Apply (SkeletonData skeletonData) {
|
||||
if (matchAllAnimations)
|
||||
AnimationTools.MatchAnimationTimelines(skeletonData.Animations, skeletonData);
|
||||
}
|
||||
|
||||
public static class AnimationTools {
|
||||
|
||||
#region Filler Timelines
|
||||
/// <summary>
|
||||
/// Matches the animation timelines across the given set of animations.
|
||||
/// This allows unkeyed properties to assume setup pose when animations are naively mixed using Animation.Apply.
|
||||
/// </summary>
|
||||
/// <param name="animations">An enumerable collection animations whose timelines will be matched.</param>
|
||||
/// <param name="skeletonData">The SkeletonData where the animations belong.</param>
|
||||
public static void MatchAnimationTimelines (IEnumerable<Spine.Animation> animations, SkeletonData skeletonData) {
|
||||
if (animations == null) return;
|
||||
if (skeletonData == null) throw new System.ArgumentNullException("skeletonData", "Timelines can't be matched without a SkeletonData source.");
|
||||
|
||||
// Build a reference collection of timelines to match
|
||||
// and a collection of dummy timelines that can be used to fill-in missing items.
|
||||
var timelineDictionary = new Dictionary<int, Spine.Timeline>();
|
||||
foreach (var animation in animations) {
|
||||
foreach (var timeline in animation.Timelines) {
|
||||
if (timeline is EventTimeline) continue;
|
||||
|
||||
int propertyID = timeline.PropertyId;
|
||||
if (!timelineDictionary.ContainsKey(propertyID)) {
|
||||
timelineDictionary.Add(propertyID, GetFillerTimeline(timeline, skeletonData));
|
||||
}
|
||||
}
|
||||
}
|
||||
var idsToMatch = new List<int>(timelineDictionary.Keys);
|
||||
|
||||
// For each animation in the list, check for and add missing timelines.
|
||||
var currentAnimationIDs = new HashSet<int>();
|
||||
foreach (var animation in animations) {
|
||||
currentAnimationIDs.Clear();
|
||||
foreach (var timeline in animation.Timelines) {
|
||||
if (timeline is EventTimeline) continue;
|
||||
currentAnimationIDs.Add(timeline.PropertyId);
|
||||
}
|
||||
|
||||
var animationTimelines = animation.Timelines;
|
||||
foreach (int propertyID in idsToMatch) {
|
||||
if (!currentAnimationIDs.Contains(propertyID))
|
||||
animationTimelines.Add(timelineDictionary[propertyID]);
|
||||
}
|
||||
}
|
||||
|
||||
// These are locals, but sometimes Unity's GC does weird stuff. So let's clean up.
|
||||
timelineDictionary.Clear();
|
||||
timelineDictionary = null;
|
||||
idsToMatch.Clear();
|
||||
idsToMatch = null;
|
||||
currentAnimationIDs.Clear();
|
||||
currentAnimationIDs = null;
|
||||
}
|
||||
|
||||
static Timeline GetFillerTimeline (Timeline timeline, SkeletonData skeletonData) {
|
||||
if (timeline is RotateTimeline)
|
||||
return GetFillerTimeline((RotateTimeline)timeline, skeletonData);
|
||||
if (timeline is TranslateTimeline)
|
||||
return GetFillerTimeline((TranslateTimeline)timeline, skeletonData);
|
||||
if (timeline is ScaleTimeline)
|
||||
return GetFillerTimeline((ScaleTimeline)timeline, skeletonData);
|
||||
if (timeline is ShearTimeline)
|
||||
return GetFillerTimeline((ShearTimeline)timeline, skeletonData);
|
||||
if (timeline is AttachmentTimeline)
|
||||
return GetFillerTimeline((AttachmentTimeline)timeline, skeletonData);
|
||||
if (timeline is ColorTimeline)
|
||||
return GetFillerTimeline((ColorTimeline)timeline, skeletonData);
|
||||
if (timeline is TwoColorTimeline)
|
||||
return GetFillerTimeline((TwoColorTimeline)timeline, skeletonData);
|
||||
if (timeline is DeformTimeline)
|
||||
return GetFillerTimeline((DeformTimeline)timeline, skeletonData);
|
||||
if (timeline is DrawOrderTimeline)
|
||||
return GetFillerTimeline((DrawOrderTimeline)timeline, skeletonData);
|
||||
if (timeline is IkConstraintTimeline)
|
||||
return GetFillerTimeline((IkConstraintTimeline)timeline, skeletonData);
|
||||
if (timeline is TransformConstraintTimeline)
|
||||
return GetFillerTimeline((TransformConstraintTimeline)timeline, skeletonData);
|
||||
if (timeline is PathConstraintPositionTimeline)
|
||||
return GetFillerTimeline((PathConstraintPositionTimeline)timeline, skeletonData);
|
||||
if (timeline is PathConstraintSpacingTimeline)
|
||||
return GetFillerTimeline((PathConstraintSpacingTimeline)timeline, skeletonData);
|
||||
if (timeline is PathConstraintMixTimeline)
|
||||
return GetFillerTimeline((PathConstraintMixTimeline)timeline, skeletonData);
|
||||
return null;
|
||||
}
|
||||
|
||||
static RotateTimeline GetFillerTimeline (RotateTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new RotateTimeline(1);
|
||||
t.BoneIndex = timeline.BoneIndex;
|
||||
t.SetFrame(0, 0, 0);
|
||||
return t;
|
||||
}
|
||||
|
||||
static TranslateTimeline GetFillerTimeline (TranslateTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new TranslateTimeline(1);
|
||||
t.BoneIndex = timeline.BoneIndex;
|
||||
t.SetFrame(0, 0, 0, 0);
|
||||
return t;
|
||||
}
|
||||
|
||||
static ScaleTimeline GetFillerTimeline (ScaleTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new ScaleTimeline(1);
|
||||
t.BoneIndex = timeline.BoneIndex;
|
||||
t.SetFrame(0, 0, 0, 0);
|
||||
return t;
|
||||
}
|
||||
|
||||
static ShearTimeline GetFillerTimeline (ShearTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new ShearTimeline(1);
|
||||
t.BoneIndex = timeline.BoneIndex;
|
||||
t.SetFrame(0, 0, 0, 0);
|
||||
return t;
|
||||
}
|
||||
|
||||
static AttachmentTimeline GetFillerTimeline (AttachmentTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new AttachmentTimeline(1);
|
||||
t.SlotIndex = timeline.SlotIndex;
|
||||
var slotData = skeletonData.Slots.Items[t.SlotIndex];
|
||||
t.SetFrame(0, 0, slotData.AttachmentName);
|
||||
return t;
|
||||
}
|
||||
|
||||
static ColorTimeline GetFillerTimeline (ColorTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new ColorTimeline(1);
|
||||
t.SlotIndex = timeline.SlotIndex;
|
||||
var slotData = skeletonData.Slots.Items[t.SlotIndex];
|
||||
t.SetFrame(0, 0, slotData.R, slotData.G, slotData.B, slotData.A);
|
||||
return t;
|
||||
}
|
||||
|
||||
static TwoColorTimeline GetFillerTimeline (TwoColorTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new TwoColorTimeline(1);
|
||||
t.SlotIndex = timeline.SlotIndex;
|
||||
var slotData = skeletonData.Slots.Items[t.SlotIndex];
|
||||
t.SetFrame(0, 0, slotData.R, slotData.G, slotData.B, slotData.A, slotData.R2, slotData.G2, slotData.B2);
|
||||
return t;
|
||||
}
|
||||
|
||||
static DeformTimeline GetFillerTimeline (DeformTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new DeformTimeline(1);
|
||||
t.SlotIndex = timeline.SlotIndex;
|
||||
t.Attachment = timeline.Attachment;
|
||||
|
||||
if (t.Attachment.IsWeighted()) {
|
||||
t.SetFrame(0, 0, new float[t.Attachment.Vertices.Length]);
|
||||
} else {
|
||||
t.SetFrame(0, 0, t.Attachment.Vertices.Clone() as float[]);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static DrawOrderTimeline GetFillerTimeline (DrawOrderTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new DrawOrderTimeline(1);
|
||||
t.SetFrame(0, 0, null); // null means use setup pose in DrawOrderTimeline.Apply.
|
||||
return t;
|
||||
}
|
||||
|
||||
static IkConstraintTimeline GetFillerTimeline (IkConstraintTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new IkConstraintTimeline(1);
|
||||
var ikConstraintData = skeletonData.IkConstraints.Items[timeline.IkConstraintIndex];
|
||||
t.SetFrame(0, 0, ikConstraintData.Mix, ikConstraintData.Softness, ikConstraintData.BendDirection, ikConstraintData.Compress, ikConstraintData.Stretch);
|
||||
return t;
|
||||
}
|
||||
|
||||
static TransformConstraintTimeline GetFillerTimeline (TransformConstraintTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new TransformConstraintTimeline(1);
|
||||
var data = skeletonData.TransformConstraints.Items[timeline.TransformConstraintIndex];
|
||||
t.SetFrame(0, 0, data.RotateMix, data.TranslateMix, data.ScaleMix, data.ShearMix);
|
||||
return t;
|
||||
}
|
||||
|
||||
static PathConstraintPositionTimeline GetFillerTimeline (PathConstraintPositionTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new PathConstraintPositionTimeline(1);
|
||||
var data = skeletonData.PathConstraints.Items[timeline.PathConstraintIndex];
|
||||
t.SetFrame(0, 0, data.Position);
|
||||
return t;
|
||||
}
|
||||
|
||||
static PathConstraintSpacingTimeline GetFillerTimeline (PathConstraintSpacingTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new PathConstraintSpacingTimeline(1);
|
||||
var data = skeletonData.PathConstraints.Items[timeline.PathConstraintIndex];
|
||||
t.SetFrame(0, 0, data.Spacing);
|
||||
return t;
|
||||
}
|
||||
|
||||
static PathConstraintMixTimeline GetFillerTimeline (PathConstraintMixTimeline timeline, SkeletonData skeletonData) {
|
||||
var t = new PathConstraintMixTimeline(1);
|
||||
var data = skeletonData.PathConstraints.Items[timeline.PathConstraintIndex];
|
||||
t.SetFrame(0, 0, data.RotateMix, data.TranslateMix);
|
||||
return t;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df7d457928e0f4041a439f9847f72290
|
||||
timeCreated: 1537527074
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +0,0 @@
|
||||
AnimationMatchModifierAsset
|
||||
===========================
|
||||
|
||||
This is a SkeletonDataModifierAsset. Add it to a SkeletonDataAsset to apply its effects when its SkeletonData is loaded.
|
||||
|
||||
AnimationMatchModifierAsset processes animations so that their timelines match. This allows them to function with naive Animation Apply systems such as SkeletonMecanim without the need for autoreset functionality.
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4436c0c78cc5ee469089ed864f4e1ea
|
||||
timeCreated: 1537528259
|
||||
licenseType: Pro
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,14 +0,0 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: df7d457928e0f4041a439f9847f72290, type: 3}
|
||||
m_Name: Default Match All Animations
|
||||
m_EditorClassIdentifier:
|
||||
matchAllAnimations: 1
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8623082208cae724e88314ec951691e1
|
||||
timeCreated: 1537527914
|
||||
licenseType: Pro
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,91 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61e6f96a4b02648479575d8b9127f5ed
|
||||
timeCreated: 1492782100
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,62 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
using Spine.Unity.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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e864d2963143ec04eb4f905e6add115e
|
||||
timeCreated: 1495176902
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,81 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using Spine;
|
||||
using Spine.Unity.AttachmentTools;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
/// <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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afde57cc4fd39bb4dbd61b73403ae6a8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,30 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e55c8477eccddc4cb5c3551a3945ca7
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user