Merge pull request #294 from Fenrisul/master

Unity 4.3 compatibility pass
This commit is contained in:
Fenrisul 2014-09-22 09:42:16 -07:00
commit bffdfb9cb7
6 changed files with 52 additions and 8 deletions

View File

@ -47,10 +47,12 @@ public class BoneFollowerInspector : Editor {
void FindRenderer(){ void FindRenderer(){
if(skeletonRenderer.objectReferenceValue == null){ if(skeletonRenderer.objectReferenceValue == null){
SkeletonRenderer parentRenderer = component.GetComponentInParent<SkeletonRenderer>(); SkeletonRenderer parentRenderer = SkeletonUtility.GetInParent<SkeletonRenderer>( component.transform );
if(parentRenderer != null){ if(parentRenderer != null){
skeletonRenderer.objectReferenceValue = (UnityEngine.Object)parentRenderer; skeletonRenderer.objectReferenceValue = (UnityEngine.Object)parentRenderer;
} }
} }
} }

View File

@ -88,8 +88,14 @@ public class SpineEditorUtilities : AssetPostprocessor {
public static Material boneMaterial{ public static Material boneMaterial{
get{ get{
if(_boneMaterial == null){ if(_boneMaterial == null){
#if UNITY_4_3
_boneMaterial = new Material(Shader.Find("Particles/Alpha Blended"));
_boneMaterial.SetColor("_TintColor", new Color(0.4f, 0.4f, 0.4f, 0.25f));
#else
_boneMaterial = new Material(Shader.Find("Spine/Bones")); _boneMaterial = new Material(Shader.Find("Spine/Bones"));
_boneMaterial.SetColor("_Color", new Color(0.4f, 0.4f, 0.4f, 0.25f)); _boneMaterial.SetColor("_Color", new Color(0.4f, 0.4f, 0.4f, 0.25f));
#endif
} }
return _boneMaterial; return _boneMaterial;
@ -177,21 +183,22 @@ public class SpineEditorUtilities : AssetPostprocessor {
} }
else if(skeletonUtilityBoneTable.ContainsKey(instanceId)){ else if(skeletonUtilityBoneTable.ContainsKey(instanceId)){
Rect r = new Rect (selectionRect); Rect r = new Rect (selectionRect);
//r.x = r.width - 15;
r.x -= 26; r.x -= 26;
if(skeletonUtilityBoneTable[instanceId] != null){ if(skeletonUtilityBoneTable[instanceId] != null){
if( skeletonUtilityBoneTable[instanceId].transform.childCount == 0 ) if( skeletonUtilityBoneTable[instanceId].transform.childCount == 0 )
r.x += 15; r.x += 13;
r.y += 2;
r.width = 15; r.width = 13;
r.height = 13;
if( skeletonUtilityBoneTable[instanceId].mode == SkeletonUtilityBone.Mode.Follow ){ if( skeletonUtilityBoneTable[instanceId].mode == SkeletonUtilityBone.Mode.Follow ){
GUI.Label(r, Icons.bone); GUI.DrawTexture(r, Icons.bone);
} }
else{ else{
GUI.Label(r, Icons.poseBones); GUI.DrawTexture(r, Icons.poseBones);
} }
} }

View File

@ -41,6 +41,23 @@ using Spine;
[RequireComponent(typeof(SkeletonAnimation))] [RequireComponent(typeof(SkeletonAnimation))]
[ExecuteInEditMode] [ExecuteInEditMode]
public class SkeletonUtility : MonoBehaviour { public class SkeletonUtility : MonoBehaviour {
public static T GetInParent<T>(Transform origin) where T : Component{
#if UNITY_4_3
Transform parent = origin.parent;
while(parent.GetComponent<T>() == null){
parent = parent.parent;
if(parent == null)
return default(T);
}
return parent.GetComponent<T>();
#else
return origin.GetComponentInParent<T>();
#endif
}
public delegate void SkeletonUtilityDelegate(); public delegate void SkeletonUtilityDelegate();
public event SkeletonUtilityDelegate OnReset; public event SkeletonUtilityDelegate OnReset;

View File

@ -97,7 +97,8 @@ public class SkeletonUtilityBone : MonoBehaviour {
} }
void OnEnable(){ void OnEnable(){
skeletonUtility = GetComponentInParent<SkeletonUtility>(); skeletonUtility = SkeletonUtility.GetInParent<SkeletonUtility>(transform);
if(skeletonUtility == null) if(skeletonUtility == null)
return; return;

View File

@ -10,7 +10,7 @@ public abstract class SkeletonUtilityConstraint : MonoBehaviour {
protected virtual void OnEnable(){ protected virtual void OnEnable(){
utilBone = GetComponent<SkeletonUtilityBone>(); utilBone = GetComponent<SkeletonUtilityBone>();
skeletonUtility = GetComponentInParent<SkeletonUtility>(); skeletonUtility = SkeletonUtility.GetInParent<SkeletonUtility>(transform);
skeletonUtility.RegisterConstraint(this); skeletonUtility.RegisterConstraint(this);
} }

View File

@ -4,6 +4,16 @@ using System.Collections;
[RequireComponent(typeof(SkeletonUtilityBone)), ExecuteInEditMode] [RequireComponent(typeof(SkeletonUtilityBone)), ExecuteInEditMode]
public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint { public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
#if UNITY_4_3
public LayerMask groundMask;
public bool use2D = false;
public bool useRadius = false;
public float castRadius = 0.1f;
public float castDistance = 5f;
public float castOffset = 0;
public float groundOffset = 0;
public float adjustSpeed = 5;
#else
[Tooltip("LayerMask for what objects to raycast against")] [Tooltip("LayerMask for what objects to raycast against")]
public LayerMask groundMask; public LayerMask groundMask;
[Tooltip("The 2D")] [Tooltip("The 2D")]
@ -20,6 +30,8 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
public float groundOffset = 0; public float groundOffset = 0;
[Tooltip("How fast the target IK position adjusts to the ground. Use smaller values to prevent snapping")] [Tooltip("How fast the target IK position adjusts to the ground. Use smaller values to prevent snapping")]
public float adjustSpeed = 5; public float adjustSpeed = 5;
#endif
Vector3 rayOrigin; Vector3 rayOrigin;
Vector3 rayDir = new Vector3(0,-1,0); Vector3 rayDir = new Vector3(0,-1,0);
@ -45,7 +57,12 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
RaycastHit2D hit; RaycastHit2D hit;
if(useRadius){ if(useRadius){
#if UNITY_4_3
//NOTE: Unity 4.3.x does not have CircleCast
hit = Physics2D.Raycast(rayOrigin , rayDir, castDistance + groundOffset, groundMask);
#else
hit = Physics2D.CircleCast( rayOrigin, castRadius, rayDir, castDistance + groundOffset, groundMask ); hit = Physics2D.CircleCast( rayOrigin, castRadius, rayDir, castDistance + groundOffset, groundMask );
#endif
} }
else{ else{
hit = Physics2D.Raycast(rayOrigin , rayDir, castDistance + groundOffset, groundMask); hit = Physics2D.Raycast(rayOrigin , rayDir, castDistance + groundOffset, groundMask);