Browse Source

Merge pull request #294 from Fenrisul/master

Unity 4.3 compatibility pass
Fenrisul 11 years ago
parent
commit
bffdfb9cb7

+ 3 - 1
spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs

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

+ 12 - 5
spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs

@@ -88,8 +88,14 @@ public class SpineEditorUtilities : AssetPostprocessor {
 		public static Material boneMaterial{
 			get{
 				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.SetColor("_Color", new Color(0.4f, 0.4f, 0.4f, 0.25f));
+#endif
+
 				}
 
 				return _boneMaterial;
@@ -177,21 +183,22 @@ public class SpineEditorUtilities : AssetPostprocessor {
 		}
 		else if(skeletonUtilityBoneTable.ContainsKey(instanceId)){
 			Rect r = new Rect (selectionRect); 
-			//r.x = r.width - 15;
 			r.x -= 26;
 
 			if(skeletonUtilityBoneTable[instanceId] != null){
 				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 ){
-					GUI.Label(r, Icons.bone);
+					GUI.DrawTexture(r, Icons.bone);
 				}
 				else{
-					GUI.Label(r, Icons.poseBones);
+					GUI.DrawTexture(r, Icons.poseBones);
 				}
 			}
 

+ 17 - 0
spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs

@@ -41,6 +41,23 @@ using Spine;
 [RequireComponent(typeof(SkeletonAnimation))]
 [ExecuteInEditMode]
 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 event SkeletonUtilityDelegate OnReset;
 

+ 2 - 1
spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs

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

+ 1 - 1
spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityConstraint.cs

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

+ 17 - 0
spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityGroundConstraint.cs

@@ -4,6 +4,16 @@ using System.Collections;
 [RequireComponent(typeof(SkeletonUtilityBone)), ExecuteInEditMode]
 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")]
 	public LayerMask groundMask;
 	[Tooltip("The 2D")]
@@ -20,6 +30,8 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
 	public float groundOffset = 0;
 	[Tooltip("How fast the target IK position adjusts to the ground.  Use smaller values to prevent snapping")]
 	public float adjustSpeed = 5;
+#endif
+
 
 	Vector3 rayOrigin;
 	Vector3 rayDir = new Vector3(0,-1,0);
@@ -45,7 +57,12 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint {
 			RaycastHit2D hit;
 
 			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 );
+#endif
 			}
 			else{
 				hit = Physics2D.Raycast(rayOrigin , rayDir, castDistance + groundOffset, groundMask);