Formatted source, committed formatter policy.

This commit is contained in:
NathanSweet 2014-10-05 20:29:11 +02:00
parent 7b07557e5b
commit 2902fb2ec9
38 changed files with 1207 additions and 1301 deletions

View File

@ -39,21 +39,21 @@ using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class BasicPlatformerController : MonoBehaviour {
#if !UNITY_4_3 && !UNITY_4_4
#if UNITY_4_5
[Header("Controls")]
#endif
public string XAxis = "Horizontal";
public string YAxis = "Vertical";
public string JumpButton = "Jump";
#if !UNITY_4_3 && !UNITY_4_4
#if UNITY_4_5
[Header("Moving")]
#endif
public float walkSpeed = 4;
public float runSpeed = 10;
public float gravity = 65;
#if !UNITY_4_3 && !UNITY_4_4
#if UNITY_4_5
[Header("Jumping")]
#endif
public float jumpSpeed = 25;
@ -62,13 +62,13 @@ public class BasicPlatformerController : MonoBehaviour {
public float forceCrouchVelocity = 25;
public float forceCrouchDuration = 0.5f;
#if !UNITY_4_3 && !UNITY_4_4
#if UNITY_4_5
[Header("Graphics")]
#endif
public Transform graphicsRoot;
public SkeletonAnimation skeletonAnimation;
#if !UNITY_4_3 && !UNITY_4_4
#if UNITY_4_5
[Header("Animation")]
#endif
public string walkName = "Walk";
@ -78,16 +78,13 @@ public class BasicPlatformerController : MonoBehaviour {
public string fallName = "Fall";
public string crouchName = "Crouch";
#if !UNITY_4_3 && !UNITY_4_4
#if UNITY_4_5
[Header("Audio")]
#endif
public AudioSource jumpAudioSource;
public AudioSource hardfallAudioSource;
public AudioSource footstepAudioSource;
public string footstepEventName = "Footstep";
CharacterController controller;
Vector2 velocity = Vector2.zero;
Vector2 lastVelocity = Vector2.zero;
@ -95,12 +92,9 @@ public class BasicPlatformerController : MonoBehaviour {
float jumpEndTime = 0;
bool jumpInterrupt = false;
float forceCrouchEndTime;
Quaternion flippedRotation = Quaternion.Euler(0, 180, 0);
void Awake()
{
void Awake () {
controller = GetComponent<CharacterController>();
}
@ -109,8 +103,7 @@ public class BasicPlatformerController : MonoBehaviour {
skeletonAnimation.state.Event += HandleEvent;
}
void HandleEvent (Spine.AnimationState state, int trackIndex, Spine.Event e)
{
void HandleEvent (Spine.AnimationState state, int trackIndex, Spine.Event e) {
//play some sound if footstep event fired
if (e.Data.Name == footstepEventName) {
footstepAudioSource.Stop();
@ -118,8 +111,7 @@ public class BasicPlatformerController : MonoBehaviour {
}
}
void Update()
{
void Update () {
//control inputs
float x = Input.GetAxis(XAxis);
float y = Input.GetAxis(YAxis);
@ -129,36 +121,28 @@ public class BasicPlatformerController : MonoBehaviour {
//Calculate control velocity
if (!crouching) {
if (Input.GetButtonDown(JumpButton) && controller.isGrounded)
{
if (Input.GetButtonDown(JumpButton) && controller.isGrounded) {
//jump
jumpAudioSource.Stop();
jumpAudioSource.Play();
velocity.y = jumpSpeed;
jumpEndTime = Time.time + jumpDuration;
}
else if (Time.time < jumpEndTime && Input.GetButtonUp(JumpButton))
{
} else if (Time.time < jumpEndTime && Input.GetButtonUp(JumpButton)) {
jumpInterrupt = true;
}
if (x != 0)
{
if (x != 0) {
//walk or run
velocity.x = Mathf.Abs(x) > 0.6f ? runSpeed : walkSpeed;
velocity.x *= Mathf.Sign(x);
}
if (jumpInterrupt)
{
if (jumpInterrupt) {
//interrupt jump and smoothly cut Y velocity
if (velocity.y > 0)
{
if (velocity.y > 0) {
velocity.y = Mathf.MoveTowards(velocity.y, 0, Time.deltaTime * 100);
}
else
{
} else {
jumpInterrupt = false;
}
}
@ -170,8 +154,7 @@ public class BasicPlatformerController : MonoBehaviour {
//move
controller.Move(new Vector3(velocity.x, velocity.y, 0) * Time.deltaTime);
if (controller.isGrounded)
{
if (controller.isGrounded) {
//cancel out Y velocity if on ground
velocity.y = -gravity * Time.deltaTime;
jumpInterrupt = false;
@ -180,15 +163,12 @@ public class BasicPlatformerController : MonoBehaviour {
Vector2 deltaVelocity = lastVelocity - velocity;
if (!lastGrounded && controller.isGrounded)
{
if (!lastGrounded && controller.isGrounded) {
//detect hard fall
if ((gravity*Time.deltaTime) - deltaVelocity.y > forceCrouchVelocity)
{
if ((gravity * Time.deltaTime) - deltaVelocity.y > forceCrouchVelocity) {
forceCrouchEndTime = Time.time + forceCrouchDuration;
hardfallAudioSource.Play();
}
else{
} else {
//play footstep audio if light fall because why not
footstepAudioSource.Play();
}
@ -196,28 +176,20 @@ public class BasicPlatformerController : MonoBehaviour {
}
//graphics updates
if (controller.isGrounded)
{
if (crouching) //crouch
{
if (controller.isGrounded) {
if (crouching) { //crouch
skeletonAnimation.AnimationName = crouchName;
}
else
{
} else {
if (x == 0) //idle
skeletonAnimation.AnimationName = idleName;
else //move
skeletonAnimation.AnimationName = Mathf.Abs(x) > 0.6f ? runName : walkName;
}
}
else
{
} else {
if (velocity.y > 0) //jump
skeletonAnimation.AnimationName = jumpName;
else //fall
skeletonAnimation.AnimationName = fallName;
}
//flip left or right

View File

@ -39,10 +39,8 @@ using System.Collections;
public class ConstrainedCamera : MonoBehaviour {
public Transform target;
public Vector3 offset;
public Vector3 min;
public Vector3 max;
public float smoothing = 5f;
// Use this for initialization

View File

@ -5,19 +5,15 @@ using System.Collections;
public class SpineboyController : MonoBehaviour {
SkeletonAnimation skeletonAnimation;
public string idleAnimation = "idle";
public string walkAnimation = "walk";
public string runAnimation = "run";
public string hitAnimation = "hit";
public string deathAnimation = "death";
public float walkVelocity = 1;
public float runVelocity = 3;
public int hp = 10;
string currentAnimation = "";
bool hit = false;
bool dead = false;
@ -25,7 +21,6 @@ public class SpineboyController : MonoBehaviour {
skeletonAnimation = GetComponent<SkeletonAnimation>();
}
void Update () {
if (!dead) {
float x = Input.GetAxis("Horizontal");
@ -40,24 +35,20 @@ public class SpineboyController : MonoBehaviour {
if (absX > 0.7f) {
SetAnimation(runAnimation, true);
rigidbody2D.velocity = new Vector2(runVelocity * Mathf.Sign(x), rigidbody2D.velocity.y);
}
else if(absX > 0){
} else if (absX > 0) {
SetAnimation(walkAnimation, true);
rigidbody2D.velocity = new Vector2(walkVelocity * Mathf.Sign(x), rigidbody2D.velocity.y);
}
else{
} else {
SetAnimation(idleAnimation, true);
rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y);
}
}
else{
} else {
if (skeletonAnimation.state.GetCurrent(0).Animation.Name != hitAnimation)
hit = false;
}
}
}
void SetAnimation (string anim, bool loop) {
if (currentAnimation != anim) {
skeletonAnimation.state.SetAnimation(0, anim, loop);
@ -73,8 +64,7 @@ public class SpineboyController : MonoBehaviour {
if (hp == 0) {
SetAnimation(deathAnimation, false);
dead = true;
}
else{
} else {
skeletonAnimation.state.SetAnimation(0, hitAnimation, false);
skeletonAnimation.state.AddAnimation(0, currentAnimation, true, 0);
rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y);

View File

@ -1,6 +1,7 @@
fileFormatVersion: 2
guid: 6bc52290ef03f2846ba38d67e2823598
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
@ -21,7 +22,7 @@ TextureImporter:
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 1024
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1

View File

@ -1,6 +1,7 @@
fileFormatVersion: 2
guid: 12c126994123f12468cf4c5a2684078a
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
@ -21,7 +22,7 @@ TextureImporter:
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 1024
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1

View File

@ -22,7 +22,7 @@ TextureImporter:
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 1024
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1

View File

@ -1,6 +1,7 @@
fileFormatVersion: 2
guid: 803c2e614a63081439fde6276d110661
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
@ -35,6 +36,7 @@ TextureImporter:
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1

View File

@ -1,6 +1,7 @@
fileFormatVersion: 2
guid: 4261719a8f729a644b2dab6113d1b0ea
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
@ -21,7 +22,7 @@ TextureImporter:
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 1024
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
@ -35,6 +36,7 @@ TextureImporter:
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1

View File

@ -1,6 +1,7 @@
fileFormatVersion: 2
guid: 49bb65eefe08e424bbf7a38bc98ec638
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
@ -21,7 +22,7 @@ TextureImporter:
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 1024
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1

View File

@ -40,11 +40,10 @@ using Spine;
public class BoneFollower : MonoBehaviour {
[System.NonSerialized]
public bool valid;
public bool
valid;
public SkeletonRenderer skeletonRenderer;
public Bone bone;
public bool followZPosition = true;
public bool followBoneRotation = true;
@ -59,9 +58,7 @@ public class BoneFollower : MonoBehaviour {
/// <summary>If a bone isn't set, boneName is used to find the bone.</summary>
public String boneName;
public bool resetOnAwake = true;
protected Transform cachedTransform;
protected Transform skeletonTransform;
@ -73,7 +70,8 @@ public class BoneFollower : MonoBehaviour {
bone = null;
cachedTransform = transform;
valid = skeletonRenderer != null && skeletonRenderer.valid;
if (!valid) return;
if (!valid)
return;
skeletonTransform = skeletonRenderer.transform;
skeletonRenderer.OnReset -= HandleResetRenderer;
@ -98,7 +96,6 @@ public class BoneFollower : MonoBehaviour {
DoUpdate();
}
public void DoUpdate () {
if (!valid) {
Reset();
@ -106,13 +103,13 @@ public class BoneFollower : MonoBehaviour {
}
if (bone == null) {
if (boneName == null || boneName.Length == 0) return;
if (boneName == null || boneName.Length == 0)
return;
bone = skeletonRenderer.skeleton.FindBone(boneName);
if (bone == null) {
Debug.LogError("Bone not found: " + boneName, this);
return;
}
else{
} else {
}
}
@ -130,7 +127,8 @@ public class BoneFollower : MonoBehaviour {
} else {
Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, 0f));
if(!followZPosition) targetWorldPosition.z = cachedTransform.position.z;
if (!followZPosition)
targetWorldPosition.z = cachedTransform.position.z;
cachedTransform.position = targetWorldPosition;

View File

@ -27,7 +27,6 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
using System;
using UnityEditor;
using UnityEngine;

View File

@ -27,7 +27,6 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
using System;
using UnityEditor;
using UnityEngine;
@ -36,6 +35,7 @@ using UnityEngine;
public class BoneFollowerInspector : Editor {
private SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation;
BoneFollower component;
void OnEnable () {
skeletonRenderer = serializedObject.FindProperty("skeletonRenderer");
boneName = serializedObject.FindProperty("boneName");
@ -74,8 +74,7 @@ public class BoneFollowerInspector : Editor {
String[] bones = new String[1];
try {
bones = new String[component.skeletonRenderer.skeleton.Data.Bones.Count + 1];
}
catch{
} catch {
}
@ -94,8 +93,7 @@ public class BoneFollowerInspector : Editor {
boneName.stringValue = boneIndex == 0 ? null : bones[boneIndex];
EditorGUILayout.PropertyField(followBoneRotation);
EditorGUILayout.PropertyField(followZPosition);
}
else{
} else {
GUILayout.Label("INVALID");
}

View File

@ -27,7 +27,6 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
using System;
using System.IO;
using UnityEditor;
@ -50,7 +49,8 @@ public class Menus {
var selected = Selection.activeObject;
if (selected != null) {
var assetDir = AssetDatabase.GetAssetPath(selected.GetInstanceID());
if (assetDir.Length > 0 && Directory.Exists(assetDir)) dir = assetDir + "/";
if (assetDir.Length > 0 && Directory.Exists(assetDir))
dir = assetDir + "/";
}
ScriptableObject asset = ScriptableObject.CreateInstance<T>();
AssetDatabase.CreateAsset(asset, dir + name + ".asset");

View File

@ -27,7 +27,6 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
using System;
using UnityEditor;
using UnityEngine;
@ -54,7 +53,8 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector {
base.gui();
SkeletonAnimation component = (SkeletonAnimation)target;
if (!component.valid) return;
if (!component.valid)
return;
//catch case where SetAnimation was used to set track 0 without using AnimationName
if (Application.isPlaying) {

View File

@ -32,10 +32,10 @@
* Automatic import and advanced preview added by Mitch Thompson
* Full irrevocable rights and permissions granted to Esoteric Software
*****************************************************************************/
using System;
using System.Collections.Generic;
using UnityEditor;
#if !UNITY_4_3
using UnityEditor.AnimatedValues;
#endif
@ -73,8 +73,7 @@ public class SkeletonDataAssetInspector : Editor {
EditorApplication.update += Update;
}
catch{
} catch {
}
@ -84,8 +83,7 @@ public class SkeletonDataAssetInspector : Editor {
m_initialized = false;
EditorApplication.update -= Update;
this.DestroyPreviewInstances();
if (this.m_previewUtility != null)
{
if (this.m_previewUtility != null) {
this.m_previewUtility.Cleanup();
this.m_previewUtility = null;
}
@ -171,14 +169,12 @@ public class SkeletonDataAssetInspector : Editor {
StopAnimation();
}
GUI.contentColor = Color.white;
}
else{
} else {
if (GUILayout.Button("\u25BA", GUILayout.Width(24))) {
PlayAnimation(a.Name, true);
}
}
}
else{
} else {
GUILayout.Label("?", GUILayout.Width(24));
}
EditorGUILayout.LabelField(new GUIContent(a.Name, SpineEditorUtilities.Icons.animation), new GUIContent(a.Duration.ToString("f3") + "s" + ("(" + (Mathf.RoundToInt(a.Duration * 30)) + ")").PadLeft(12, ' ')));
@ -205,12 +201,10 @@ public class SkeletonDataAssetInspector : Editor {
private Vector2 previewDir;
private SkeletonAnimation m_skeletonAnimation;
private SkeletonData m_skeletonData;
private static int sliderHash = "Slider".GetHashCode();
private float m_lastTime;
private bool m_playing;
private bool m_requireRefresh;
private Color m_originColor = new Color(0.3f, 0.3f, 0.3f, 1);
private void StopAnimation () {
@ -218,9 +212,9 @@ public class SkeletonDataAssetInspector : Editor {
m_playing = false;
}
List<Spine.Event> m_animEvents = new List<Spine.Event>();
List<float> m_animEventFrames = new List<float>();
private void PlayAnimation (string animName, bool loop) {
m_animEvents.Clear();
m_animEventFrames.Clear();
@ -243,10 +237,8 @@ public class SkeletonDataAssetInspector : Editor {
m_playing = true;
}
private void InitPreview()
{
if (this.m_previewUtility == null)
{
private void InitPreview () {
if (this.m_previewUtility == null) {
this.m_lastTime = Time.realtimeSinceStartup;
this.m_previewUtility = new PreviewRenderUtility(true);
this.m_previewUtility.m_Camera.isOrthoGraphic = true;
@ -256,11 +248,9 @@ public class SkeletonDataAssetInspector : Editor {
}
}
private void CreatePreviewInstances()
{
private void CreatePreviewInstances () {
this.DestroyPreviewInstances();
if (this.m_previewInstance == null)
{
if (this.m_previewInstance == null) {
string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", "");
m_previewInstance = SpineEditorUtilities.SpawnAnimatedSkeleton((SkeletonDataAsset)target, skinName).gameObject;
@ -281,29 +271,25 @@ public class SkeletonDataAssetInspector : Editor {
}
}
private void DestroyPreviewInstances()
{
if (this.m_previewInstance != null)
{
private void DestroyPreviewInstances () {
if (this.m_previewInstance != null) {
DestroyImmediate(this.m_previewInstance);
m_previewInstance = null;
}
m_initialized = false;
}
public override bool HasPreviewGUI ()
{
public override bool HasPreviewGUI () {
//TODO: validate json data
return skeletonJSON.objectReferenceValue != null;
}
Texture m_previewTex = new Texture();
public override void OnInteractivePreviewGUI(Rect r, GUIStyle background)
{
public override void OnInteractivePreviewGUI (Rect r, GUIStyle background) {
this.InitPreview();
if (UnityEngine.Event.current.type == EventType.Repaint)
{
if (UnityEngine.Event.current.type == EventType.Repaint) {
if (m_requireRefresh) {
this.m_previewUtility.BeginPreview(r, background);
this.DoRenderPreview(true);
@ -324,6 +310,7 @@ public class SkeletonDataAssetInspector : Editor {
float m_orthoGoal = 1;
Vector3 m_posGoal = new Vector3(0, 0, -10);
double m_adjustFrameEndTime = 0;
private void AdjustCameraGoals (bool calculateMixTime) {
if (calculateMixTime) {
if (m_skeletonAnimation.state.GetCurrent(0) != null) {
@ -366,8 +353,7 @@ public class SkeletonDataAssetInspector : Editor {
}
}
private void DoRenderPreview(bool drawHandles)
{
private void DoRenderPreview (bool drawHandles) {
GameObject go = this.m_previewInstance;
if (m_requireRefresh) {
@ -375,8 +361,7 @@ public class SkeletonDataAssetInspector : Editor {
if (EditorApplication.isPlaying) {
//do nothing
}
else{
} else {
m_skeletonAnimation.Update((Time.realtimeSinceStartup - m_lastTime));
}
@ -406,11 +391,9 @@ public class SkeletonDataAssetInspector : Editor {
if (m_playing) {
m_requireRefresh = true;
Repaint();
}
else if (m_requireRefresh) {
} else if (m_requireRefresh) {
Repaint();
}
else{
} else {
#if !UNITY_4_3
if (m_showAnimationList.isAnimating)
Repaint();
@ -577,17 +560,14 @@ public class SkeletonDataAssetInspector : Editor {
}
*/
public override GUIContent GetPreviewTitle ()
{
public override GUIContent GetPreviewTitle () {
return new GUIContent("Preview");
}
public override void OnPreviewSettings ()
{
public override void OnPreviewSettings () {
if (!m_initialized) {
GUILayout.HorizontalSlider(0, 0, 2, GUILayout.MaxWidth(64));
}
else{
} else {
float speed = GUILayout.HorizontalSlider(m_skeletonAnimation.timeScale, 0, 2, GUILayout.MaxWidth(64));
//snap to nearest 0.25
@ -601,8 +581,7 @@ public class SkeletonDataAssetInspector : Editor {
//TODO: Fix first-import error
//TODO: Update preview without thumbnail
public override Texture2D RenderStaticPreview (string assetPath, UnityEngine.Object[] subAssets, int width, int height)
{
public override Texture2D RenderStaticPreview (string assetPath, UnityEngine.Object[] subAssets, int width, int height) {
Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false);
this.InitPreview();

View File

@ -27,7 +27,6 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
using System;
using UnityEditor;
using UnityEngine;
@ -64,7 +63,8 @@ public class SkeletonRendererInspector : Editor {
if (!component.valid) {
component.Reset();
component.LateUpdate();
if (!component.valid) return;
if (!component.valid)
return;
}
// Initial skin name.
@ -100,7 +100,8 @@ public class SkeletonRendererInspector : Editor {
if (serializedObject.ApplyModifiedProperties() ||
(Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
) {
if (!Application.isPlaying) ((SkeletonRenderer)target).Reset();
if (!Application.isPlaying)
((SkeletonRenderer)target).Reset();
}
}
}

View File

@ -33,7 +33,6 @@
* Spine Editor Utilities created by Mitch Thompson
* Full irrevocable rights and permissions granted to Esoteric Software
*****************************************************************************/
using UnityEngine;
using UnityEditor;
using System.Collections;
@ -72,7 +71,12 @@ public class SpineEditorUtilities : AssetPostprocessor {
get {
if (_boneMesh == null) {
_boneMesh = new Mesh();
_boneMesh.vertices = new Vector3[4]{Vector3.zero, new Vector3(-0.1f,0.1f,0), Vector3.up, new Vector3(0.1f,0.1f,0)};
_boneMesh.vertices = new Vector3[4] {
Vector3.zero,
new Vector3(-0.1f, 0.1f, 0),
Vector3.up,
new Vector3(0.1f, 0.1f, 0)
};
_boneMesh.uv = new Vector2[4];
_boneMesh.triangles = new int[6]{0,1,2,2,3,0};
_boneMesh.RecalculateBounds();
@ -82,8 +86,8 @@ public class SpineEditorUtilities : AssetPostprocessor {
return _boneMesh;
}
}
internal static Mesh _boneMesh;
internal static Mesh _boneMesh;
public static Material boneMaterial {
get {
@ -101,6 +105,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
return _boneMaterial;
}
}
internal static Material _boneMaterial;
public static void Initialize () {
@ -125,19 +130,13 @@ public class SpineEditorUtilities : AssetPostprocessor {
skeletonUtility = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-skeletonUtility.png");
hingeChain = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-hingeChain.png");
subMeshRenderer = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-subMeshRenderer.png");
}
}
public static string editorPath = "";
public static string editorGUIPath = "";
static Dictionary<int, GameObject> skeletonRendererTable;
static Dictionary<int, SkeletonUtilityBone> skeletonUtilityBoneTable;
public static float defaultScale = 0.01f;
public static float defaultMix = 0.2f;
public static string defaultShader = "Spine/Skeleton";
@ -180,8 +179,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
r.width = 15;
GUI.Label(r, Icons.spine);
}
else if(skeletonUtilityBoneTable.ContainsKey(instanceId)){
} else if (skeletonUtilityBoneTable.ContainsKey(instanceId)) {
Rect r = new Rect(selectionRect);
r.x -= 26;
@ -196,8 +194,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
if (skeletonUtilityBoneTable[instanceId].mode == SkeletonUtilityBone.Mode.Follow) {
GUI.DrawTexture(r, Icons.bone);
}
else{
} else {
GUI.DrawTexture(r, Icons.poseBones);
}
}
@ -280,8 +277,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
GameObject.Destroy(anim.gameObject);
else
GameObject.DestroyImmediate(anim.gameObject);
}
else{
} else {
}
@ -306,11 +302,9 @@ public class SpineEditorUtilities : AssetPostprocessor {
Dictionary<string, object> skeletonInfo = (Dictionary<string, object>)root["skeleton"];
string spineVersion = (string)skeletonInfo["spine"];
//TODO: reject old versions
return true;
}
static SkeletonDataAsset AutoIngestSpineProject (TextAsset spineJson, Object atlasSource = null) {
@ -320,8 +314,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
if (atlasSource != null) {
if (atlasSource.GetType() == typeof(TextAsset)) {
atlasText = (TextAsset)atlasSource;
}
else if(atlasSource.GetType() == typeof(AtlasAsset)){
} else if (atlasSource.GetType() == typeof(AtlasAsset)) {
atlasAsset = (AtlasAsset)atlasSource;
}
}
@ -339,8 +332,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
bool abort = !EditorUtility.DisplayDialog("Atlas not Found", "Expecting " + spineJson.name + ".atlas\n" + "Press OK to select Atlas", "OK", "Abort");
if (abort) {
//do nothing, let it error later
}
else{
} else {
string path = EditorUtility.OpenFilePanel("Find Atlas source...", Path.GetDirectoryName(Application.dataPath) + "/" + assetPath, "txt");
if (path != "") {
path = path.Replace("\\", "/");
@ -436,9 +428,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
return (AtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAsset));
}
static SkeletonDataAsset IngestSpineProject (TextAsset spineJson, AtlasAsset atlasAsset = null) {
string primaryName = Path.GetFileNameWithoutExtension(spineJson.name);
string assetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(spineJson));
string filePath = assetPath + "/" + primaryName + "_SkeletonData.asset";
@ -458,15 +448,13 @@ public class SpineEditorUtilities : AssetPostprocessor {
AssetDatabase.CreateAsset(skelDataAsset, filePath);
AssetDatabase.SaveAssets();
}
else{
} else {
skelDataAsset.Reset();
skelDataAsset.GetSkeletonData(true);
}
return skelDataAsset;
}
else{
} else {
EditorUtility.DisplayDialog("Error!", "Must specify both Spine JSON and Atlas TextAsset", "OK");
return null;
}
@ -475,9 +463,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
[MenuItem("Assets/Spine/Spawn")]
static void SpawnAnimatedSkeleton () {
Object[] arr = Selection.objects;
foreach (Object o in arr) {
string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(o));
string skinName = EditorPrefs.GetString(guid + "_lastSkin", "");
@ -506,7 +492,6 @@ public class SpineEditorUtilities : AssetPostprocessor {
}
public static SkeletonAnimation SpawnAnimatedSkeleton (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
GameObject go = new GameObject(skeletonDataAsset.name.Replace("_SkeletonData", ""), typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
SkeletonAnimation anim = go.GetComponent<SkeletonAnimation>();
anim.skeletonDataAsset = skeletonDataAsset;
@ -548,8 +533,4 @@ public class SpineEditorUtilities : AssetPostprocessor {
return anim;
}
}

View File

@ -42,19 +42,22 @@ public class SkeletonAnimation : SkeletonRenderer {
public Spine.AnimationState state;
public delegate void UpdateBonesDelegate (SkeletonAnimation skeleton);
public UpdateBonesDelegate UpdateLocal;
public UpdateBonesDelegate UpdateWorld;
public UpdateBonesDelegate UpdateComplete;
[SerializeField]
private String _animationName;
private String
_animationName;
public String AnimationName {
get {
TrackEntry entry = state.GetCurrent(0);
return entry == null ? null : entry.Animation.Name;
}
set {
if (_animationName == value) return;
if (_animationName == value)
return;
_animationName = value;
if (value == null || value.Length == 0)
state.ClearTrack(0);
@ -65,7 +68,8 @@ public class SkeletonAnimation : SkeletonRenderer {
public override void Reset () {
base.Reset();
if (!valid) return;
if (!valid)
return;
state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
if (_animationName != null && _animationName.Length > 0) {
@ -79,7 +83,8 @@ public class SkeletonAnimation : SkeletonRenderer {
}
public virtual void Update (float deltaTime) {
if (!valid) return;
if (!valid)
return;
deltaTime *= timeScale;
skeleton.Update(deltaTime);

View File

@ -87,7 +87,8 @@ public class SkeletonDataAsset : ScriptableObject {
stateData = new AnimationStateData(skeletonData);
stateData.DefaultMix = defaultMix;
for (int i = 0, n = fromAnimation.Length; i < n; i++) {
if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) continue;
if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0)
continue;
stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);
}

View File

@ -39,20 +39,18 @@ using Spine;
public class SkeletonRenderer : MonoBehaviour {
public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer);
public SkeletonRendererDelegate OnReset;
public SkeletonRendererDelegate OnReset;
[System.NonSerialized]
public bool valid;
[System.NonSerialized]
public Skeleton skeleton;
public SkeletonDataAsset skeletonDataAsset;
public String initialSkinName;
public bool calculateNormals, calculateTangents;
public float zSpacing;
public bool renderMeshes = true, immutableTriangles;
public bool logErrors = false;
private MeshFilter meshFilter;
private Mesh mesh, mesh1, mesh2;
private bool useMesh1;
@ -66,9 +64,12 @@ public class SkeletonRenderer : MonoBehaviour {
private readonly List<Submesh> submeshes = new List<Submesh>();
public virtual void Reset () {
if (meshFilter != null) meshFilter.sharedMesh = null;
if (mesh != null) DestroyImmediate(mesh);
if (renderer != null) renderer.sharedMaterial = null;
if (meshFilter != null)
meshFilter.sharedMesh = null;
if (mesh != null)
DestroyImmediate(mesh);
if (renderer != null)
renderer.sharedMaterial = null;
mesh = null;
mesh1 = null;
mesh2 = null;
@ -89,7 +90,8 @@ public class SkeletonRenderer : MonoBehaviour {
return;
}
SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false);
if (skeletonData == null) return;
if (skeletonData == null)
return;
valid = true;
meshFilter = GetComponent<MeshFilter>();
@ -100,7 +102,8 @@ public class SkeletonRenderer : MonoBehaviour {
skeleton = new Skeleton(skeletonData);
if (initialSkinName != null && initialSkinName.Length > 0 && initialSkinName != "default")
skeleton.SetSkin(initialSkinName);
if(OnReset != null) OnReset(this);
if (OnReset != null)
OnReset(this);
}
public void Awake () {
@ -116,7 +119,8 @@ public class SkeletonRenderer : MonoBehaviour {
}
public virtual void LateUpdate () {
if (!valid) return;
if (!valid)
return;
// Count vertices and submesh triangles.
int vertexCount = 0;
int submeshTriangleCount = 0, submeshFirstVertex = 0, submeshStartSlotIndex = 0;
@ -137,7 +141,8 @@ public class SkeletonRenderer : MonoBehaviour {
attachmentVertexCount = 4;
attachmentTriangleCount = 6;
} else {
if (!renderMeshes) continue;
if (!renderMeshes)
continue;
if (attachment is MeshAttachment) {
MeshAttachment meshAttachment = (MeshAttachment)attachment;
rendererObject = meshAttachment.RendererObject;
@ -217,7 +222,8 @@ public class SkeletonRenderer : MonoBehaviour {
color.r = (byte)(r * slot.r * regionAttachment.r * color.a);
color.g = (byte)(g * slot.g * regionAttachment.g * color.a);
color.b = (byte)(b * slot.b * regionAttachment.b * color.a);
if (slot.data.additiveBlending) color.a = 0;
if (slot.data.additiveBlending)
color.a = 0;
colors[vertexIndex] = color;
colors[vertexIndex + 1] = color;
colors[vertexIndex + 2] = color;
@ -231,18 +237,21 @@ public class SkeletonRenderer : MonoBehaviour {
vertexIndex += 4;
} else {
if (!renderMeshes) continue;
if (!renderMeshes)
continue;
if (attachment is MeshAttachment) {
MeshAttachment meshAttachment = (MeshAttachment)attachment;
int meshVertexCount = meshAttachment.vertices.Length;
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
if (tempVertices.Length < meshVertexCount)
tempVertices = new float[meshVertexCount];
meshAttachment.ComputeWorldVertices(slot, tempVertices);
color.a = (byte)(a * slot.a * meshAttachment.a);
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
color.g = (byte)(g * slot.g * meshAttachment.g * color.a);
color.b = (byte)(b * slot.b * meshAttachment.b * color.a);
if (slot.data.additiveBlending) color.a = 0;
if (slot.data.additiveBlending)
color.a = 0;
float[] meshUVs = meshAttachment.uvs;
float z = i * zSpacing;
@ -254,14 +263,16 @@ public class SkeletonRenderer : MonoBehaviour {
} else if (attachment is SkinnedMeshAttachment) {
SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment;
int meshVertexCount = meshAttachment.uvs.Length;
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
if (tempVertices.Length < meshVertexCount)
tempVertices = new float[meshVertexCount];
meshAttachment.ComputeWorldVertices(slot, tempVertices);
color.a = (byte)(a * slot.a * meshAttachment.a);
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
color.g = (byte)(g * slot.g * meshAttachment.g * color.a);
color.b = (byte)(b * slot.b * meshAttachment.b * color.a);
if (slot.data.additiveBlending) color.a = 0;
if (slot.data.additiveBlending)
color.a = 0;
float[] meshUVs = meshAttachment.uvs;
float z = i * zSpacing;

View File

@ -32,7 +32,6 @@
* Skeleton Utility created by Mitch Thompson
* Full irrevocable rights and permissions granted to Esoteric Software
*****************************************************************************/
using UnityEngine;
using UnityEditor;
using System.Collections;
@ -72,9 +71,6 @@ public class SkeletonUtilityBoneInspector : Editor {
canCreateHingeChain = CanCreateHingeChain();
}
/// <summary>
/// Evaluates the flags.
/// </summary>
void EvaluateFlags () {
utilityBone = (SkeletonUtilityBone)target;
skeletonUtility = utilityBone.skeletonUtility;
@ -82,8 +78,7 @@ public class SkeletonUtilityBoneInspector : Editor {
if (Selection.objects.Length == 1) {
containsFollows = utilityBone.mode == SkeletonUtilityBone.Mode.Follow;
containsOverrides = utilityBone.mode == SkeletonUtilityBone.Mode.Override;
}
else{
} else {
int boneCount = 0;
foreach (Object o in Selection.objects) {
if (o is GameObject) {
@ -104,8 +99,7 @@ public class SkeletonUtilityBoneInspector : Editor {
}
}
public override void OnInspectorGUI ()
{
public override void OnInspectorGUI () {
serializedObject.Update();
EditorGUI.BeginChangeCheck();
@ -118,8 +112,10 @@ public class SkeletonUtilityBoneInspector : Editor {
EditorGUI.BeginDisabledGroup(multiObject);
{
string str = boneName.stringValue;
if(str == "") str = "<None>";
if(multiObject) str = "<Multiple>";
if (str == "")
str = "<None>";
if (multiObject)
str = "<Multiple>";
GUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Bone");
@ -147,8 +143,7 @@ public class SkeletonUtilityBoneInspector : Editor {
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(flipX);
if (EditorGUI.EndChangeCheck())
{
if (EditorGUI.EndChangeCheck()) {
FlipX(flipX.boolValue);
}
}
@ -188,11 +183,9 @@ public class SkeletonUtilityBoneInspector : Editor {
serializedObject.ApplyModifiedProperties();
}
void FlipX(bool state)
{
void FlipX (bool state) {
utilityBone.FlipX(state);
if (Application.isPlaying == false)
{
if (Application.isPlaying == false) {
skeletonUtility.skeletonAnimation.LateUpdate();
}
}
@ -211,13 +204,11 @@ public class SkeletonUtilityBoneInspector : Editor {
}
void TargetBoneSelected (object obj) {
if (obj == null) {
boneName.stringValue = "";
serializedObject.ApplyModifiedProperties();
}
else{
} else {
Bone bone = (Bone)obj;
boneName.stringValue = bone.Data.Name;
serializedObject.ApplyModifiedProperties();
@ -235,8 +226,7 @@ public class SkeletonUtilityBoneInspector : Editor {
foreach (SkeletonUtilityBone utilBone in newUtilityBones)
SkeletonUtilityInspector.AttachIcon(utilBone);
}
}
else{
} else {
Bone bone = (Bone)obj;
GameObject go = skeletonUtility.SpawnBone(bone, utilityBone.transform, utilityBone.mode, utilityBone.position, utilityBone.rotation, utilityBone.scale);
SkeletonUtilityInspector.AttachIcon(go.GetComponent<SkeletonUtilityBone>());
@ -254,13 +244,17 @@ public class SkeletonUtilityBoneInspector : Editor {
}
bool CanCreateHingeChain () {
if(utilityBone == null) return false;
if(utilityBone.rigidbody != null) return false;
if(utilityBone.bone != null && utilityBone.bone.Children.Count == 0) return false;
if (utilityBone == null)
return false;
if (utilityBone.rigidbody != null)
return false;
if (utilityBone.bone != null && utilityBone.bone.Children.Count == 0)
return false;
Rigidbody[] rigidbodies = utilityBone.GetComponentsInChildren<Rigidbody>();
if(rigidbodies.Length > 0) return false;
if (rigidbodies.Length > 0)
return false;
return true;
}
@ -297,8 +291,7 @@ public class SkeletonUtilityBoneInspector : Editor {
if (utilBone.bone.Data.Length == 0) {
SphereCollider sphere = utilBone.gameObject.AddComponent<SphereCollider>();
sphere.radius = 0.1f;
}
else{
} else {
float length = utilBone.bone.Data.Length;
BoxCollider box = utilBone.gameObject.AddComponent<BoxCollider>();
box.size = new Vector3(length, length / 3, 0.2f);

View File

@ -32,9 +32,9 @@
* Skeleton Utility created by Mitch Thompson
* Full irrevocable rights and permissions granted to Esoteric Software
*****************************************************************************/
using UnityEngine;
using UnityEditor;
#if UNITY_4_3
//nothing
#else
@ -66,7 +66,10 @@ public class SkeletonUtilityInspector : Editor {
typeof(EditorGUIUtility).InvokeMember("SetIconForObject", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[2]{ utilityBone.gameObject, icon});
typeof(EditorGUIUtility).InvokeMember("SetIconForObject", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[2] {
utilityBone.gameObject,
icon
});
}
static void AttachIconsToChildren (Transform root) {
@ -78,8 +81,6 @@ public class SkeletonUtilityInspector : Editor {
}
}
static SkeletonUtilityInspector () {
#if UNITY_4_3
showSlots = false;
@ -89,13 +90,10 @@ public class SkeletonUtilityInspector : Editor {
}
SkeletonUtility skeletonUtility;
Skeleton skeleton;
SkeletonRenderer skeletonRenderer;
Transform transform;
bool isPrefab;
Dictionary<Slot, List<Attachment>> attachmentTable = new Dictionary<Slot, List<Attachment>>();
@ -184,8 +182,7 @@ public class SkeletonUtilityInspector : Editor {
}
}
public override void OnInspectorGUI ()
{
public override void OnInspectorGUI () {
if (isPrefab) {
GUILayout.Label(new GUIContent("Cannot edit Prefabs", SpineEditorUtilities.Icons.warning));
return;
@ -243,8 +240,7 @@ public class SkeletonUtilityInspector : Editor {
if (slot.Attachment == attachment) {
GUI.contentColor = Color.white;
}
else{
} else {
GUI.contentColor = Color.grey;
}
@ -263,8 +259,7 @@ public class SkeletonUtilityInspector : Editor {
if (!isAttached && swap) {
slot.Attachment = attachment;
skeletonRenderer.LateUpdate();
}
else if(isAttached && !swap){
} else if (isAttached && !swap) {
slot.Attachment = null;
skeletonRenderer.LateUpdate();
}

View File

@ -59,6 +59,7 @@ public class SkeletonUtility : MonoBehaviour {
public delegate void SkeletonUtilityDelegate ();
public event SkeletonUtilityDelegate OnReset;
public Transform boneRoot;
@ -78,18 +79,14 @@ public class SkeletonUtility : MonoBehaviour {
[HideInInspector]
public SkeletonRenderer skeletonRenderer;
[HideInInspector]
public SkeletonAnimation skeletonAnimation;
[System.NonSerialized]
public List<SkeletonUtilityBone> utilityBones = new List<SkeletonUtilityBone>();
[System.NonSerialized]
public List<SkeletonUtilityConstraint> utilityConstraints = new List<SkeletonUtilityConstraint>();
// Dictionary<Bone, SkeletonUtilityBone> utilityBoneTable;
protected bool hasTransformBones;
protected bool hasUtilityConstraints;
protected bool needToReprocessBones;
@ -120,8 +117,6 @@ public class SkeletonUtility : MonoBehaviour {
// CollectBones();
}
void OnDisable () {
skeletonRenderer.OnReset -= HandleRendererReset;
@ -207,8 +202,7 @@ public class SkeletonUtility : MonoBehaviour {
}
needToReprocessBones = false;
}
else{
} else {
utilityBones.Clear();
utilityConstraints.Clear();
}

View File

@ -44,37 +44,32 @@ using Spine;
[AddComponentMenu("Spine/SkeletonUtilityBone")]
public class SkeletonUtilityBone : MonoBehaviour {
public enum Mode { Follow, Override }
public enum Mode {
Follow,
Override
}
[System.NonSerialized]
public bool valid;
[System.NonSerialized]
public SkeletonUtility skeletonUtility;
[System.NonSerialized]
public Bone bone;
public Mode mode;
public bool zPosition = true;
public bool position;
public bool rotation;
public bool scale;
public bool flip;
public bool flipX;
[Range(0f,1f)]
public float overrideAlpha = 1;
/// <summary>If a bone isn't set, boneName is used to find the bone.</summary>
public String boneName;
public Transform parentReference;
[HideInInspector]
public bool transformLerpComplete;
protected Transform cachedTransform;
protected Transform skeletonTransform;
@ -83,13 +78,15 @@ public class SkeletonUtilityBone : MonoBehaviour {
return nonUniformScaleWarning;
}
}
private bool nonUniformScaleWarning;
public void Reset () {
bone = null;
cachedTransform = transform;
valid = skeletonUtility != null && skeletonUtility.skeletonRenderer != null && skeletonUtility.skeletonRenderer.valid;
if (!valid) return;
if (!valid)
return;
skeletonTransform = skeletonUtility.transform;
skeletonUtility.OnReset -= HandleOnReset;
@ -109,8 +106,7 @@ public class SkeletonUtilityBone : MonoBehaviour {
skeletonUtility.OnReset += HandleOnReset;
}
void HandleOnReset ()
{
void HandleOnReset () {
Reset();
}
@ -132,7 +128,8 @@ public class SkeletonUtilityBone : MonoBehaviour {
Spine.Skeleton skeleton = skeletonUtility.skeletonRenderer.skeleton;
if (bone == null) {
if (boneName == null || boneName.Length == 0) return;
if (boneName == null || boneName.Length == 0)
return;
bone = skeleton.FindBone(boneName);
if (bone == null) {
Debug.LogError("Bone not found: " + boneName, this);
@ -145,14 +142,12 @@ public class SkeletonUtilityBone : MonoBehaviour {
float skeletonFlipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f;
float flipCompensation = 0;
if (flip && (flipX || ( flipX != bone.flipX)) && bone.parent != null)
{
if (flip && (flipX || (flipX != bone.flipX)) && bone.parent != null) {
flipCompensation = bone.parent.WorldRotation * -2;
}
if (mode == Mode.Follow) {
if (flip)
{
if (flip) {
flipX = bone.flipX;
}
@ -164,15 +159,12 @@ public class SkeletonUtilityBone : MonoBehaviour {
if (rotation) {
if (bone.Data.InheritRotation) {
if (bone.FlipX)
{
if (bone.FlipX) {
cachedTransform.localRotation = Quaternion.Euler(0, 180, bone.rotationIK - flipCompensation);
}
else {
} else {
cachedTransform.localRotation = Quaternion.Euler(0, 0, bone.rotationIK);
}
}
else{
} else {
Vector3 euler = skeletonTransform.rotation.eulerAngles;
cachedTransform.rotation = Quaternion.Euler(euler.x, euler.y, skeletonTransform.rotation.eulerAngles.z + (bone.worldRotation * skeletonFlipRotation));
}
@ -185,8 +177,7 @@ public class SkeletonUtilityBone : MonoBehaviour {
nonUniformScaleWarning = (bone.scaleX != bone.scaleY);
}
}
else if(mode == Mode.Override){
} else if (mode == Mode.Override) {
@ -203,8 +194,7 @@ public class SkeletonUtilityBone : MonoBehaviour {
float angle = Mathf.LerpAngle(bone.Rotation, cachedTransform.localRotation.eulerAngles.z, overrideAlpha) + flipCompensation;
if (flip) {
if ((!flipX && bone.flipX))
{
if ((!flipX && bone.flipX)) {
angle -= flipCompensation;
}
@ -225,12 +215,10 @@ public class SkeletonUtilityBone : MonoBehaviour {
nonUniformScaleWarning = (bone.scaleX != bone.scaleY);
}
if (flip)
{
if (flip) {
bone.flipX = flipX;
}
}
else{
} else {
if (transformLerpComplete)
return;
@ -244,10 +232,8 @@ public class SkeletonUtilityBone : MonoBehaviour {
if (rotation) {
float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(flipX ? Vector3.forward * -1 : Vector3.forward, parentReference.InverseTransformDirection(cachedTransform.up)).eulerAngles.z, overrideAlpha) + flipCompensation;
if (flip)
{
if ((!flipX && bone.flipX))
{
if (flip) {
if ((!flipX && bone.flipX)) {
angle -= flipCompensation;
}
@ -269,8 +255,7 @@ public class SkeletonUtilityBone : MonoBehaviour {
nonUniformScaleWarning = (bone.scaleX != bone.scaleY);
}
if (flip)
{
if (flip) {
bone.flipX = flipX;
}
@ -280,18 +265,13 @@ public class SkeletonUtilityBone : MonoBehaviour {
}
}
public void FlipX(bool state)
{
if (state != flipX)
{
public void FlipX (bool state) {
if (state != flipX) {
flipX = state;
if (flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) > 90)
{
if (flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) > 90) {
skeletonUtility.skeletonAnimation.LateUpdate();
return;
}
else if (!flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) < 90)
{
} else if (!flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) < 90) {
skeletonUtility.skeletonAnimation.LateUpdate();
return;
}

View File

@ -7,14 +7,11 @@ public class SkeletonUtilityEyeConstraint : SkeletonUtilityConstraint {
public float radius = 0.5f;
public Transform target;
public Vector3 targetPosition;
public float speed = 10;
Vector3[] origins;
Vector3 centerPoint;
protected override void OnEnable ()
{
protected override void OnEnable () {
if (!Application.isPlaying)
return;
@ -30,16 +27,14 @@ public class SkeletonUtilityEyeConstraint : SkeletonUtilityConstraint {
centerPoint = centerBounds.center;
}
protected override void OnDisable ()
{
protected override void OnDisable () {
if (!Application.isPlaying)
return;
base.OnDisable();
}
public override void DoUpdate ()
{
public override void DoUpdate () {
if (target != null)
targetPosition = target.position;

View File

@ -38,18 +38,15 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
float hitY;
float lastHitY;
protected override void OnEnable ()
{
protected override void OnEnable () {
base.OnEnable();
}
protected override void OnDisable ()
{
protected override void OnDisable () {
base.OnDisable();
}
public override void DoUpdate()
{
public override void DoUpdate () {
rayOrigin = transform.position + new Vector3(castOffset, castDistance, 0);
hitY = float.MinValue;
@ -63,8 +60,7 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
#else
hit = Physics2D.CircleCast(rayOrigin, castRadius, rayDir, castDistance + groundOffset, groundMask);
#endif
}
else{
} else {
hit = Physics2D.Raycast(rayOrigin, rayDir, castDistance + groundOffset, groundMask);
}
@ -73,20 +69,17 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
if (Application.isPlaying) {
hitY = Mathf.MoveTowards(lastHitY, hitY, adjustSpeed * Time.deltaTime);
}
}
else{
} else {
if (Application.isPlaying)
hitY = Mathf.MoveTowards(lastHitY, transform.position.y, adjustSpeed * Time.deltaTime);
}
}
else{
} else {
RaycastHit hit;
bool validHit = false;
if (useRadius) {
validHit = Physics.SphereCast(rayOrigin, castRadius, rayDir, out hit, castDistance + groundOffset, groundMask);
}
else{
} else {
validHit = Physics.Raycast(rayOrigin, rayDir, out hit, castDistance + groundOffset, groundMask);
}
@ -95,8 +88,7 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
if (Application.isPlaying) {
hitY = Mathf.MoveTowards(lastHitY, hitY, adjustSpeed * Time.deltaTime);
}
}
else{
} else {
if (Application.isPlaying)
hitY = Mathf.MoveTowards(lastHitY, transform.position.y, adjustSpeed * Time.deltaTime);
}
@ -110,7 +102,6 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
utilBone.bone.Y = transform.localPosition.y;
lastHitY = hitY;
}
void OnDrawGizmos () {
@ -123,8 +114,6 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
Gizmos.DrawLine(new Vector3(clearEnd.x - castRadius, clearEnd.y, clearEnd.z), new Vector3(clearEnd.x + castRadius, clearEnd.y, clearEnd.z));
}
Gizmos.color = Color.red;
Gizmos.DrawLine(hitEnd, clearEnd);
}

View File

@ -3,9 +3,7 @@ using System.Collections;
using System.Collections.Generic;
public class SkeletonUtilityKinematicShadow : MonoBehaviour {
public bool hideShadow = true;
Dictionary<Transform, Transform> shadowTable;
GameObject shadowRoot;

View File

@ -3,16 +3,12 @@ using System.Collections;
[ExecuteInEditMode]
public class SkeletonUtilitySubmeshRenderer : MonoBehaviour {
public Renderer parentRenderer;
[System.NonSerialized]
public Mesh mesh;
public int submeshIndex = 0;
public int sortingOrder = 0;
public int sortingLayerID = 0;
public Material hiddenPassMaterial;
Renderer cachedRenderer;
MeshFilter filter;
@ -62,8 +58,7 @@ public class SkeletonUtilitySubmeshRenderer : MonoBehaviour {
if (mesh == null || submeshIndex > mesh.subMeshCount - 1) {
cachedRenderer.enabled = false;
return;
}
else{
} else {
renderer.enabled = true;
}
@ -95,7 +90,6 @@ public class SkeletonUtilitySubmeshRenderer : MonoBehaviour {
cachedRenderer.sharedMaterials = sharedMaterials;
}
cachedRenderer.sortingLayerID = sortingLayerID;
cachedRenderer.sortingOrder = sortingOrder;
}

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<PolicySet name="Spine">
<TextStylePolicy inheritsSet="Mono" inheritsScope="text/plain" scope="text/x-csharp">
<FileWidth>130</FileWidth>
<TabWidth>3</TabWidth>
<IndentWidth>3</IndentWidth>
</TextStylePolicy>
<CSharpFormattingPolicy inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp">
<IndentNamespaceBody>False</IndentNamespaceBody>
<AlignEmbeddedUsingStatements>False</AlignEmbeddedUsingStatements>
<AlignEmbeddedIfStatements>False</AlignEmbeddedIfStatements>
<NamespaceBraceStyle>EndOfLine</NamespaceBraceStyle>
<ClassBraceStyle>EndOfLine</ClassBraceStyle>
<InterfaceBraceStyle>EndOfLine</InterfaceBraceStyle>
<StructBraceStyle>EndOfLine</StructBraceStyle>
<EnumBraceStyle>EndOfLine</EnumBraceStyle>
<MethodBraceStyle>EndOfLine</MethodBraceStyle>
<ConstructorBraceStyle>EndOfLine</ConstructorBraceStyle>
<DestructorBraceStyle>EndOfLine</DestructorBraceStyle>
<ElseIfNewLinePlacement>SameLine</ElseIfNewLinePlacement>
<BeforeMethodCallParentheses>False</BeforeMethodCallParentheses>
<AfterDelegateDeclarationParameterComma>True</AfterDelegateDeclarationParameterComma>
<NewParentheses>False</NewParentheses>
<SpacesBeforeBrackets>False</SpacesBeforeBrackets>
<BlankLinesBeforeUsings>1</BlankLinesBeforeUsings>
<BlankLinesBeforeFirstDeclaration>1</BlankLinesBeforeFirstDeclaration>
</CSharpFormattingPolicy>
</PolicySet>