Spine.Unity and Spine.Unity.Editor namespace

This commit is contained in:
pharan 2016-03-24 00:34:22 +08:00
parent 80d8e9e276
commit 9254e18801
15 changed files with 2630 additions and 2603 deletions

View File

@ -38,10 +38,10 @@ using UnityEditor;
using UnityEngine;
using Spine;
namespace Spine.Unity {
namespace Spine.Unity.Editor {
[CustomEditor(typeof(AtlasAsset))]
public class AtlasAssetInspector : Editor {
public class AtlasAssetInspector : UnityEditor.Editor {
private SerializedProperty atlasFile, materials;
private AtlasAsset atlasAsset;
private List<bool> baked;

View File

@ -14,9 +14,9 @@ using UnityEditor.AnimatedValues;
using UnityEngine;
using Spine;
namespace Spine.Unity {
namespace Spine.Unity.Editor {
[CustomEditor(typeof(SkeletonDataAsset))]
public class SkeletonDataAssetInspector : Editor {
public class SkeletonDataAssetInspector : UnityEditor.Editor {
static bool showAnimationStateData = true;
static bool showAnimationList = true;
static bool showSlotList = false;
@ -50,6 +50,7 @@ namespace Spine.Unity {
try {
atlasAssets = serializedObject.FindProperty("atlasAssets");
atlasAssets.isExpanded = true;
skeletonJSON = serializedObject.FindProperty("skeletonJSON");
scale = serializedObject.FindProperty("scale");
fromAnimation = serializedObject.FindProperty("fromAnimation");

View File

@ -1,6 +1,6 @@
using UnityEngine;
namespace Spine {
namespace Spine.Unity.Editor {
public static class AssetDatabaseAvailabilityDetector {
const string MARKER_RESOURCE_NAME = "SpineAssetDatabaseMarker";
private static bool _isMarkerLoaded;

View File

@ -33,8 +33,11 @@ using System;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(BoneFollower))]
public class BoneFollowerInspector : Editor {
namespace Spine.Unity.Editor {
[CustomEditor(typeof(BoneFollower))]
public class BoneFollowerInspector : UnityEditor.Editor {
SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation;
BoneFollower component;
bool needsReset;
@ -84,9 +87,11 @@ public class BoneFollowerInspector : Editor {
}
if (serializedObject.ApplyModifiedProperties() ||
(Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
(UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed")
) {
component.Reset();
}
}
}
}

View File

@ -33,7 +33,7 @@ using System.IO;
using UnityEditor;
using UnityEngine;
namespace Spine.Unity {
namespace Spine.Unity.Editor {
public static class Menus {
[MenuItem("Assets/Create/Spine Atlas")]
static public void CreateAtlas () {

View File

@ -33,7 +33,7 @@ using UnityEditor;
using UnityEngine;
using Spine;
namespace Spine.Unity {
namespace Spine.Unity.Editor {
[CustomEditor(typeof(SkeletonAnimation))]
public class SkeletonAnimationInspector : SkeletonRendererInspector {

View File

@ -6,7 +6,7 @@ using System;
using UnityEditor;
using UnityEngine;
namespace Spine.Unity {
namespace Spine.Unity.Editor {
[CustomEditor(typeof(SkeletonAnimator))]
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
protected SerializedProperty layerMixModes;

View File

@ -43,12 +43,13 @@ using Spine;
/// Color Keys (Maybe one day when Unity supports full FBX standard and provides access with code)
/// InheritScale (Never. Unity and Spine do scaling very differently)
/// Draw Order Keyframes
/// </summary>
public static class SkeletonBaker {
///
namespace Spine.Unity.Editor {
public static class SkeletonBaker {
#region SkeletonAnimator's Mecanim Clips
#if SPINE_SKELETON_ANIMATOR
#if SPINE_SKELETON_ANIMATOR
public static void GenerateMecanimAnimationClips (SkeletonDataAsset skeletonDataAsset) {
//skeletonDataAsset.Clear();
var data = skeletonDataAsset.GetSkeletonData(true);
@ -60,7 +61,7 @@ public static class SkeletonBaker {
string dataPath = AssetDatabase.GetAssetPath(skeletonDataAsset);
string controllerPath = dataPath.Replace("_SkeletonData", "_Controller").Replace(".asset", ".controller");
#if UNITY_5
#if UNITY_5
UnityEditor.Animations.AnimatorController controller;
if (skeletonDataAsset.controller != null) {
@ -78,7 +79,7 @@ public static class SkeletonBaker {
}
}
#else
#else
UnityEditorInternal.AnimatorController controller;
if (skeletonDataAsset.controller != null) {
@ -95,7 +96,7 @@ public static class SkeletonBaker {
controller = (UnityEditorInternal.AnimatorController)UnityEditorInternal.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
}
}
#endif
#endif
skeletonDataAsset.controller = controller;
EditorUtility.SetDirty(skeletonDataAsset);
@ -129,9 +130,9 @@ public static class SkeletonBaker {
//generate new dummy clip
AnimationClip newClip = new AnimationClip();
newClip.name = name;
#if !(UNITY_5)
#if !(UNITY_5)
AnimationUtility.SetAnimationType(newClip, ModelImporterAnimationType.Generic);
#endif
#endif
AssetDatabase.AddObjectToAsset(newClip, controller);
unityAnimationClipTable.Add(name, newClip);
}
@ -169,7 +170,7 @@ public static class SkeletonBaker {
static bool HasFlag (this UnityEngine.Object o, HideFlags flagToCheck) {
return (o.hideFlags & flagToCheck) == flagToCheck;
}
#endif
#endif
#endregion
#region Baking
@ -191,32 +192,32 @@ public static class SkeletonBaker {
var skeletonData = skeletonDataAsset.GetSkeletonData(true);
bool hasAnimations = bakeAnimations && skeletonData.Animations.Count > 0;
#if UNITY_5
#if UNITY_5
UnityEditor.Animations.AnimatorController controller = null;
#else
#else
UnityEditorInternal.AnimatorController controller = null;
#endif
#endif
if (hasAnimations) {
string controllerPath = outputPath + "/" + skeletonDataAsset.skeletonJSON.name + " Controller.controller";
bool newAnimContainer = false;
var runtimeController = AssetDatabase.LoadAssetAtPath(controllerPath, typeof(RuntimeAnimatorController));
#if UNITY_5
#if UNITY_5
if (runtimeController != null) {
controller = (UnityEditor.Animations.AnimatorController)runtimeController;
} else {
controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
newAnimContainer = true;
}
#else
#else
if (runtimeController != null) {
controller = (UnityEditorInternal.AnimatorController)runtimeController;
} else {
controller = UnityEditorInternal.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
newAnimContainer = true;
}
#endif
#endif
var existingClipTable = new Dictionary<string, AnimationClip>();
var unusedClipNames = new List<string>();
@ -261,11 +262,11 @@ public static class SkeletonBaker {
unusedClipNames.Remove(clip.name);
} else {
AssetDatabase.AddObjectToAsset(clip, controller);
#if UNITY_5
#if UNITY_5
controller.AddMotion(clip);
#else
#else
UnityEditorInternal.AnimatorController.AddAnimationClipToController(controller, clip);
#endif
#endif
}
}
@ -779,11 +780,11 @@ public static class SkeletonBaker {
AnimationUtility.SetAnimationEvents(clip, new AnimationEvent[0]);
}
#if UNITY_5
#if UNITY_5
#else
#else
AnimationUtility.SetAnimationType(clip, ModelImporterAnimationType.Generic);
#endif
#endif
clip.name = name;
@ -1472,15 +1473,18 @@ public static class SkeletonBaker {
#endregion
static void SetAnimationSettings (AnimationClip clip, AnimationClipSettings settings) {
#if UNITY_5
#if UNITY_5
AnimationUtility.SetAnimationClipSettings(clip, settings);
#else
#else
MethodInfo methodInfo = typeof(AnimationUtility).GetMethod("SetAnimationClipSettings", BindingFlags.Static | BindingFlags.NonPublic);
methodInfo.Invoke(null, new object[] { clip, settings });
EditorUtility.SetDirty(clip);
#endif
#endif
}
}
}

View File

@ -33,10 +33,10 @@ using System;
using UnityEditor;
using UnityEngine;
namespace Spine.Unity {
namespace Spine.Unity.Editor {
[CustomEditor(typeof(SkeletonRenderer))]
public class SkeletonRendererInspector : Editor {
public class SkeletonRendererInspector : UnityEditor.Editor {
protected static bool advancedFoldout;
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, separatorSlotNames, front, zSpacing;

View File

@ -6,14 +6,12 @@
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Spine;
public struct SpineDrawerValuePair {
namespace Spine.Unity.Editor {
public struct SpineDrawerValuePair {
public string str;
public SerializedProperty property;
@ -21,9 +19,9 @@ public struct SpineDrawerValuePair {
this.str = val;
this.property = property;
}
}
}
public abstract class SpineTreeItemDrawerBase<T> : PropertyDrawer where T:SpineAttributeBase {
public abstract class SpineTreeItemDrawerBase<T> : PropertyDrawer where T:SpineAttributeBase {
protected SkeletonDataAsset skeletonDataAsset;
internal const string NoneLabel = "<None>";
@ -93,10 +91,10 @@ public abstract class SpineTreeItemDrawerBase<T> : PropertyDrawer where T:SpineA
return 18;
}
}
}
[CustomPropertyDrawer(typeof(SpineSlot))]
public class SpineSlotDrawer : SpineTreeItemDrawerBase<SpineSlot> {
[CustomPropertyDrawer(typeof(SpineSlot))]
public class SpineSlotDrawer : SpineTreeItemDrawerBase<SpineSlot> {
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSlot targetAttribute, SkeletonData data) {
for (int i = 0; i < data.Slots.Count; i++) {
@ -133,10 +131,10 @@ public class SpineSlotDrawer : SpineTreeItemDrawerBase<SpineSlot> {
}
}
}
}
[CustomPropertyDrawer(typeof(SpineSkin))]
public class SpineSkinDrawer : SpineTreeItemDrawerBase<SpineSkin> {
[CustomPropertyDrawer(typeof(SpineSkin))]
public class SpineSkinDrawer : SpineTreeItemDrawerBase<SpineSkin> {
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSkin targetAttribute, SkeletonData data) {
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
@ -149,10 +147,10 @@ public class SpineSkinDrawer : SpineTreeItemDrawerBase<SpineSkin> {
}
}
}
}
[CustomPropertyDrawer(typeof(SpineAnimation))]
public class SpineAnimationDrawer : SpineTreeItemDrawerBase<SpineAnimation> {
[CustomPropertyDrawer(typeof(SpineAnimation))]
public class SpineAnimationDrawer : SpineTreeItemDrawerBase<SpineAnimation> {
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineAnimation targetAttribute, SkeletonData data) {
var animations = skeletonDataAsset.GetAnimationStateData().SkeletonData.Animations;
@ -166,10 +164,10 @@ public class SpineAnimationDrawer : SpineTreeItemDrawerBase<SpineAnimation> {
}
}
}
}
[CustomPropertyDrawer(typeof(SpineEvent))]
public class SpineEventNameDrawer : SpineTreeItemDrawerBase<SpineEvent> {
[CustomPropertyDrawer(typeof(SpineEvent))]
public class SpineEventNameDrawer : SpineTreeItemDrawerBase<SpineEvent> {
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineEvent targetAttribute, SkeletonData data) {
var events = skeletonDataAsset.GetSkeletonData(false).Events;
for (int i = 0; i < events.Count; i++) {
@ -179,10 +177,10 @@ public class SpineEventNameDrawer : SpineTreeItemDrawerBase<SpineEvent> {
}
}
}
}
[CustomPropertyDrawer(typeof(SpineAttachment))]
public class SpineAttachmentDrawer : SpineTreeItemDrawerBase<SpineAttachment> {
[CustomPropertyDrawer(typeof(SpineAttachment))]
public class SpineAttachmentDrawer : SpineTreeItemDrawerBase<SpineAttachment> {
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineAttachment targetAttribute, SkeletonData data) {
List<Skin> validSkins = new List<Skin>();
SkeletonRenderer skeletonRenderer = null;
@ -276,10 +274,10 @@ public class SpineAttachmentDrawer : SpineTreeItemDrawerBase<SpineAttachment> {
}
}
}
}
[CustomPropertyDrawer(typeof(SpineBone))]
public class SpineBoneDrawer : SpineTreeItemDrawerBase<SpineBone> {
[CustomPropertyDrawer(typeof(SpineBone))]
public class SpineBoneDrawer : SpineTreeItemDrawerBase<SpineBone> {
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineBone targetAttribute, SkeletonData data) {
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
@ -292,10 +290,10 @@ public class SpineBoneDrawer : SpineTreeItemDrawerBase<SpineBone> {
}
}
}
}
[CustomPropertyDrawer(typeof(SpineAtlasRegion))]
public class SpineAtlasRegionDrawer : PropertyDrawer {
[CustomPropertyDrawer(typeof(SpineAtlasRegion))]
public class SpineAtlasRegionDrawer : PropertyDrawer {
Component component;
SerializedProperty atlasProp;
@ -353,4 +351,6 @@ public class SpineAtlasRegionDrawer : PropertyDrawer {
pair.property.serializedObject.ApplyModifiedProperties();
}
}
}

View File

@ -35,6 +35,7 @@
* Spine Editor Utilities created by Mitch Thompson
* Full irrevocable rights and permissions granted to Esoteric Software
*****************************************************************************/
#define SPINE_SKELETONANIMATOR
using UnityEngine;
using UnityEditor;
using System.Collections;
@ -45,8 +46,10 @@ using System.Linq;
using System.Reflection;
using Spine;
[InitializeOnLoad]
public class SpineEditorUtilities : AssetPostprocessor {
namespace Spine.Unity.Editor {
[InitializeOnLoad]
public class SpineEditorUtilities : AssetPostprocessor {
public static class Icons {
public static Texture2D skeleton;
@ -100,13 +103,13 @@ public class SpineEditorUtilities : AssetPostprocessor {
public static Material boneMaterial {
get {
if (_boneMaterial == null) {
#if UNITY_4_3
#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
#else
_boneMaterial = new Material(Shader.Find("Spine/Bones"));
_boneMaterial.SetColor("_Color", new Color(0.4f, 0.4f, 0.4f, 0.25f));
#endif
#endif
}
@ -191,6 +194,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
Initialize();
}
#region Hierarchy Icon
static void HierarchyWindowChanged () {
skeletonRendererTable.Clear();
skeletonUtilityBoneTable.Clear();
@ -254,6 +258,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
}
}
#endregion
static void OnPostprocessAllAssets (string[] imported, string[] deleted, string[] moved, string[] movedFromAssetPaths) {
if (imported.Length == 0)
@ -469,14 +474,6 @@ public class SpineEditorUtilities : AssetPostprocessor {
}
}
static void UpdateMecanimClips (SkeletonDataAsset skeletonDataAsset) {
if (skeletonDataAsset.controller == null)
return;
SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
}
static bool CheckForValidAtlas (string atlasPath) {
return false;
//////////////DEPRECATED - always check for new atlas data now
@ -932,7 +929,8 @@ public class SpineEditorUtilities : AssetPostprocessor {
}
}
[MenuItem("Assets/Spine/Instantiate (SkeletonAnimation)")]
#region SkeletonAnimation Menu
[MenuItem("Assets/Spine/Instantiate (SkeletonAnimation)", false, 10)]
static void InstantiateSkeletonAnimation () {
Object[] arr = Selection.objects;
foreach (Object o in arr) {
@ -944,7 +942,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
}
}
[MenuItem("Assets/Spine/Instantiate (SkeletonAnimation)", true)]
[MenuItem("Assets/Spine/Instantiate (SkeletonAnimation)", true, 10)]
static bool ValidateInstantiateSkeletonAnimation () {
Object[] arr = Selection.objects;
@ -1013,8 +1011,18 @@ public class SpineEditorUtilities : AssetPostprocessor {
return anim;
}
#endregion
[MenuItem("Assets/Spine/Instantiate (Mecanim)")]
#region SkeletonAnimator
#if SPINE_SKELETONANIMATOR
static void UpdateMecanimClips (SkeletonDataAsset skeletonDataAsset) {
if (skeletonDataAsset.controller == null)
return;
SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
}
[MenuItem("Assets/Spine/Instantiate (Mecanim)", false, 100)]
static void InstantiateSkeletonAnimator () {
Object[] arr = Selection.objects;
foreach (Object o in arr) {
@ -1026,7 +1034,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
}
}
[MenuItem("Assets/Spine/Instantiate (SkeletonAnimation)", true)]
[MenuItem("Assets/Spine/Instantiate (Mecanim)", true, 100)]
static bool ValidateInstantiateSkeletonAnimator () {
Object[] arr = Selection.objects;
@ -1099,7 +1107,10 @@ public class SpineEditorUtilities : AssetPostprocessor {
return anim;
}
#endif
#endregion
#region Spine Preferences
static bool preferencesLoaded = false;
[PreferenceItem("Spine")]
@ -1127,7 +1138,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
DisableTK2D();
GUILayout.EndHorizontal();
}
#endregion
//TK2D Support
const string SPINE_TK2D_DEFINE = "SPINE_TK2D";
@ -1206,4 +1217,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
return new BoundingBoxAttachment(name);
}
}
}
}

View File

@ -35,7 +35,7 @@ using UnityEditor;
using System.Reflection;
using System;
namespace Spine.Unity {
namespace Spine.Unity.Editor {
public static class SpineInspectorUtility {
public static string Pluralize (int n, string singular, string plural) {
@ -100,5 +100,4 @@ namespace Spine.Unity {
}
#endregion
}
}

View File

@ -33,8 +33,10 @@ using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(BoundingBoxFollower))]
public class BoundingBoxFollowerInspector : Editor {
namespace Spine.Unity.Editor {
[CustomEditor(typeof(BoundingBoxFollower))]
public class BoundingBoxFollowerInspector : UnityEditor.Editor {
SerializedProperty skeletonRenderer, slotName;
BoundingBoxFollower follower;
bool needToReset = false;
@ -81,4 +83,6 @@ public class BoundingBoxFollowerInspector : Editor {
collider.enabled = EditorGUILayout.ToggleLeft(new GUIContent(!isPlaceholder ? name : name + " [" + kp.Key.Name + "]", isPlaceholder ? SpineEditorUtilities.Icons.skinPlaceholder : SpineEditorUtilities.Icons.boundingBox), collider.enabled);
}
}
}
}

View File

@ -37,7 +37,7 @@ using UnityEngine;
using System.Collections;
using Spine;
namespace Spine {
namespace Spine.Unity {
/// <summary>
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
/// The routine will pause until the AnimationState.TrackEntry fires its Complete event.</summary>

View File

@ -37,7 +37,7 @@ using UnityEngine;
using System.Collections;
using Spine;
namespace Spine {
namespace Spine.Unity {
/// <summary>
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
/// The routine will pause until the AnimationState fires an event matching the given event name or EventData reference.</summary>