Useful SkeletonGraphic editor messages.

This commit is contained in:
pharan 2016-03-05 03:51:06 +08:00
parent a3311a8d6b
commit fa66c7a15a
2 changed files with 31 additions and 41 deletions

View File

@ -13,7 +13,7 @@ public class SkeletonGraphicInspector : Editor {
SerializedProperty material_, color_; SerializedProperty material_, color_;
SerializedProperty skeletonDataAsset_, initialSkinName_; SerializedProperty skeletonDataAsset_, initialSkinName_;
SerializedProperty startingAnimation_, startingLoop_, timeScale_, freeze_; SerializedProperty startingAnimation_, startingLoop_, timeScale_, freeze_;
#if !PREUNITY_5_2 #if !PREUNITY_5_2
SerializedProperty raycastTarget_; SerializedProperty raycastTarget_;
SkeletonGraphic thisSkeletonGraphic; SkeletonGraphic thisSkeletonGraphic;
@ -38,17 +38,12 @@ public class SkeletonGraphicInspector : Editor {
freeze_ = so.FindProperty("freeze"); freeze_ = so.FindProperty("freeze");
} }
public override void OnInspectorGUI () { public override void OnInspectorGUI () {
var s = thisSkeletonGraphic;
s.skeletonDataAsset = SkeletonGraphicInspector.ObjectField<SkeletonDataAsset>(skeletonDataAsset_);
s.material = SkeletonGraphicInspector.ObjectField<Material>(material_);
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
thisSkeletonGraphic.color = EditorGUILayout.ColorField(color_.displayName, color_.colorValue);
if (EditorGUI.EndChangeCheck()) EditorGUILayout.PropertyField(skeletonDataAsset_);
SkeletonGraphicInspector.ForceUpdateHack(thisSkeletonGraphic.transform); EditorGUILayout.PropertyField(material_);
EditorGUILayout.PropertyField(color_);
if (thisSkeletonGraphic.skeletonDataAsset == null) { if (thisSkeletonGraphic.skeletonDataAsset == null) {
EditorGUILayout.HelpBox("You need to assign a SkeletonDataAsset first.", MessageType.Info); EditorGUILayout.HelpBox("You need to assign a SkeletonDataAsset first.", MessageType.Info);
@ -62,38 +57,23 @@ public class SkeletonGraphicInspector : Editor {
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.LabelField("Animation", EditorStyles.boldLabel); EditorGUILayout.LabelField("Animation", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(startingAnimation_); EditorGUILayout.PropertyField(startingAnimation_);
s.startingLoop = SkeletonGraphicInspector.BoolField(startingLoop_); EditorGUILayout.PropertyField(startingLoop_);
s.timeScale = EditorGUILayout.FloatField(timeScale_.displayName, timeScale_.floatValue); EditorGUILayout.PropertyField(timeScale_);
EditorGUILayout.Space(); EditorGUILayout.Space();
s.freeze = SkeletonGraphicInspector.BoolField(freeze_); EditorGUILayout.PropertyField(freeze_);
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.LabelField("UI", EditorStyles.boldLabel); EditorGUILayout.LabelField("UI", EditorStyles.boldLabel);
s.raycastTarget = SkeletonGraphicInspector.BoolField(raycastTarget_); EditorGUILayout.PropertyField(raycastTarget_);
} bool wasChanged = EditorGUI.EndChangeCheck();
#region HAX - Thanks, Unity if (wasChanged) {
// colors weren't updating in realtime in the custom inspector. serializedObject.ApplyModifiedProperties();
// Why the hell do I have to do this??
/// <summary>Use this when scene repaint and proper explicit update methods don't work.</summary>
public static void ForceUpdateHack (Transform t) {
var origValue = t.localScale;
t.localScale = new Vector3(11f, 22f, 33f);
t.localScale = origValue;
} }
// Hack for Unity 5.3 problem with PropertyField
public static T ObjectField<T> (SerializedProperty property) where T : UnityEngine.Object {
return (T)EditorGUILayout.ObjectField(property.displayName, property.objectReferenceValue, typeof(T), false);
} }
public static bool BoolField (SerializedProperty property) {
return EditorGUILayout.Toggle(property.displayName, property.boolValue);
}
#endregion
#region Menus #region Menus
[MenuItem ("CONTEXT/SkeletonGraphic/Match RectTransform with Mesh Bounds")] [MenuItem("CONTEXT/SkeletonGraphic/Match RectTransform with Mesh Bounds")]
static void MatchRectTransformWithBounds (MenuCommand command) { static void MatchRectTransformWithBounds (MenuCommand command) {
var skeletonGraphic = (SkeletonGraphic)command.context; var skeletonGraphic = (SkeletonGraphic)command.context;
var mesh = skeletonGraphic.SpineMeshGenerator.LastGeneratedMesh; var mesh = skeletonGraphic.SpineMeshGenerator.LastGeneratedMesh;
@ -112,8 +92,12 @@ public class SkeletonGraphicInspector : Editor {
public static Material DefaultSkeletonGraphicMaterial { public static Material DefaultSkeletonGraphicMaterial {
get { get {
var guids = AssetDatabase.FindAssets("SkeletonGraphicDefault t:material"); if (guids.Length <= 0) return null; var guids = AssetDatabase.FindAssets("SkeletonGraphicDefault t:material");
var firstAssetPath = AssetDatabase.GUIDToAssetPath(guids[0]); if (string.IsNullOrEmpty(firstAssetPath)) return null; if (guids.Length <= 0)
return null;
var firstAssetPath = AssetDatabase.GUIDToAssetPath(guids[0]);
if (string.IsNullOrEmpty(firstAssetPath))
return null;
var firstMaterial = AssetDatabase.LoadAssetAtPath<Material>(firstAssetPath); var firstMaterial = AssetDatabase.LoadAssetAtPath<Material>(firstAssetPath);
return firstMaterial; return firstMaterial;
} }
@ -204,6 +188,8 @@ public class SkeletonGraphicInspector : Editor {
graphic.material = SkeletonGraphicInspector.DefaultSkeletonGraphicMaterial; graphic.material = SkeletonGraphicInspector.DefaultSkeletonGraphicMaterial;
return go; return go;
} }
#endregion #endregion
#endif
#endif
} }

View File

@ -89,6 +89,10 @@ public class SkeletonGraphic : MaskableGraphic {
protected override void Reset () { protected override void Reset () {
base.Reset(); base.Reset();
if (canvas == null) {
Debug.LogWarningFormat("SkeletonGraphic requires a Canvas to be visible. Move this GameObject ({0}) in the Hierarchy so it becomes a child of a Canvas.", gameObject.name);
}
if (material == null || material.shader != Shader.Find("Spine/SkeletonGraphic (Premultiply Alpha)")) { if (material == null || material.shader != Shader.Find("Spine/SkeletonGraphic (Premultiply Alpha)")) {
Debug.LogWarning("SkeletonGraphic works best with the SkeletonGraphic material."); Debug.LogWarning("SkeletonGraphic works best with the SkeletonGraphic material.");
} }