mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Basic multi-editing for AtlasAsset, SkeletonDataAsset and BoneFollower.
This commit is contained in:
parent
da5849d1b9
commit
fe25ffda1a
@ -41,7 +41,7 @@ using Spine;
|
|||||||
namespace Spine.Unity.Editor {
|
namespace Spine.Unity.Editor {
|
||||||
using Event = UnityEngine.Event;
|
using Event = UnityEngine.Event;
|
||||||
|
|
||||||
[CustomEditor(typeof(AtlasAsset))]
|
[CustomEditor(typeof(AtlasAsset)), CanEditMultipleObjects]
|
||||||
public class AtlasAssetInspector : UnityEditor.Editor {
|
public class AtlasAssetInspector : UnityEditor.Editor {
|
||||||
SerializedProperty atlasFile, materials;
|
SerializedProperty atlasFile, materials;
|
||||||
AtlasAsset atlasAsset;
|
AtlasAsset atlasAsset;
|
||||||
@ -103,6 +103,11 @@ namespace Spine.Unity.Editor {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
override public void OnInspectorGUI () {
|
override public void OnInspectorGUI () {
|
||||||
|
if (serializedObject.isEditingMultipleObjects) {
|
||||||
|
DrawDefaultInspector();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
atlasAsset = atlasAsset ?? (AtlasAsset)target;
|
atlasAsset = atlasAsset ?? (AtlasAsset)target;
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
@ -114,7 +119,6 @@ namespace Spine.Unity.Editor {
|
|||||||
atlasAsset.GetAtlas();
|
atlasAsset.GetAtlas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (materials.arraySize == 0) {
|
if (materials.arraySize == 0) {
|
||||||
EditorGUILayout.LabelField(new GUIContent("Error: Missing materials", SpineEditorUtilities.Icons.warning));
|
EditorGUILayout.LabelField(new GUIContent("Error: Missing materials", SpineEditorUtilities.Icons.warning));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -43,7 +43,7 @@ namespace Spine.Unity.Editor {
|
|||||||
using Event = UnityEngine.Event;
|
using Event = UnityEngine.Event;
|
||||||
using Icons = SpineEditorUtilities.Icons;
|
using Icons = SpineEditorUtilities.Icons;
|
||||||
|
|
||||||
[CustomEditor(typeof(SkeletonDataAsset))]
|
[CustomEditor(typeof(SkeletonDataAsset)), CanEditMultipleObjects]
|
||||||
public class SkeletonDataAssetInspector : UnityEditor.Editor {
|
public class SkeletonDataAssetInspector : UnityEditor.Editor {
|
||||||
static bool showAnimationStateData = true;
|
static bool showAnimationStateData = true;
|
||||||
static bool showAnimationList = true;
|
static bool showAnimationList = true;
|
||||||
@ -141,6 +141,34 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override public void OnInspectorGUI () {
|
override public void OnInspectorGUI () {
|
||||||
|
if (serializedObject.isEditingMultipleObjects) {
|
||||||
|
using (new SpineInspectorUtility.BoxScope()) {
|
||||||
|
EditorGUILayout.LabelField("SkeletonData", EditorStyles.boldLabel);
|
||||||
|
EditorGUILayout.PropertyField(skeletonJSON, new GUIContent(skeletonJSON.displayName, Icons.spine));
|
||||||
|
EditorGUILayout.PropertyField(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (new SpineInspectorUtility.BoxScope()) {
|
||||||
|
EditorGUILayout.LabelField("Atlas", EditorStyles.boldLabel);
|
||||||
|
#if !SPINE_TK2D
|
||||||
|
EditorGUILayout.PropertyField(atlasAssets, true);
|
||||||
|
#else
|
||||||
|
using (new EditorGUI.DisabledGroupScope(spriteCollection.objectReferenceValue != null)) {
|
||||||
|
EditorGUILayout.PropertyField(atlasAssets, true);
|
||||||
|
}
|
||||||
|
EditorGUILayout.LabelField("spine-tk2d", EditorStyles.boldLabel);
|
||||||
|
EditorGUILayout.PropertyField(spriteCollection, true);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
using (new SpineInspectorUtility.BoxScope()) {
|
||||||
|
EditorGUILayout.LabelField("Mix Settings", EditorStyles.boldLabel);
|
||||||
|
SpineInspectorUtility.PropertyFieldWideLabel(defaultMix, DefaultMixLabel, 160);
|
||||||
|
EditorGUILayout.Space();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Lazy initialization because accessing EditorStyles values in OnEnable during a recompile causes UnityEditor to throw null exceptions. (Unity 5.3.5)
|
// Lazy initialization because accessing EditorStyles values in OnEnable during a recompile causes UnityEditor to throw null exceptions. (Unity 5.3.5)
|
||||||
idlePlayButtonStyle = idlePlayButtonStyle ?? new GUIStyle(EditorStyles.miniButton);
|
idlePlayButtonStyle = idlePlayButtonStyle ?? new GUIStyle(EditorStyles.miniButton);
|
||||||
@ -646,7 +674,10 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool HasPreviewGUI () {
|
public override bool HasPreviewGUI () {
|
||||||
// MITCH: left todo: validate json data
|
if (serializedObject.isEditingMultipleObjects) {
|
||||||
|
// JOHN: Implement multi-preview.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < atlasAssets.arraySize; i++) {
|
for (int i = 0; i < atlasAssets.arraySize; i++) {
|
||||||
var prop = atlasAssets.GetArrayElementAtIndex(i);
|
var prop = atlasAssets.GetArrayElementAtIndex(i);
|
||||||
|
|||||||
@ -32,45 +32,12 @@ using UnityEditor;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Spine.Unity.Editor {
|
namespace Spine.Unity.Editor {
|
||||||
[CustomEditor(typeof(BoneFollower))]
|
[CustomEditor(typeof(BoneFollower)), CanEditMultipleObjects]
|
||||||
public class BoneFollowerInspector : UnityEditor.Editor {
|
public class BoneFollowerInspector : UnityEditor.Editor {
|
||||||
SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation, followLocalScale, followSkeletonFlip;
|
SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation, followLocalScale, followSkeletonFlip;
|
||||||
BoneFollower targetBoneFollower;
|
BoneFollower targetBoneFollower;
|
||||||
bool needsReset;
|
bool needsReset;
|
||||||
|
|
||||||
void OnEnable () {
|
|
||||||
skeletonRenderer = serializedObject.FindProperty("skeletonRenderer");
|
|
||||||
boneName = serializedObject.FindProperty("boneName");
|
|
||||||
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
|
||||||
followZPosition = serializedObject.FindProperty("followZPosition");
|
|
||||||
followLocalScale = serializedObject.FindProperty("followLocalScale");
|
|
||||||
followSkeletonFlip = serializedObject.FindProperty("followSkeletonFlip");
|
|
||||||
|
|
||||||
targetBoneFollower = (BoneFollower)target;
|
|
||||||
if (targetBoneFollower.SkeletonRenderer != null)
|
|
||||||
targetBoneFollower.SkeletonRenderer.Initialize(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnSceneGUI () {
|
|
||||||
if (targetBoneFollower == null) return;
|
|
||||||
var skeletonRendererComponent = targetBoneFollower.skeletonRenderer;
|
|
||||||
if (skeletonRendererComponent == null) return;
|
|
||||||
|
|
||||||
var transform = skeletonRendererComponent.transform;
|
|
||||||
var skeleton = skeletonRendererComponent.skeleton;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(targetBoneFollower.boneName)) {
|
|
||||||
SpineHandles.DrawBones(transform, skeleton);
|
|
||||||
SpineHandles.DrawBoneNames(transform, skeleton);
|
|
||||||
Handles.Label(targetBoneFollower.transform.position, "No bone selected", EditorStyles.helpBox);
|
|
||||||
} else {
|
|
||||||
var targetBone = targetBoneFollower.bone;
|
|
||||||
if (targetBone == null) return;
|
|
||||||
SpineHandles.DrawBoneWireframe(transform, targetBone, SpineHandles.TransformContraintColor);
|
|
||||||
Handles.Label(targetBone.GetWorldPosition(transform), targetBone.Data.Name, SpineHandles.BoneNameStyle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Context Menu Item
|
#region Context Menu Item
|
||||||
[MenuItem ("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject")]
|
[MenuItem ("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject")]
|
||||||
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
||||||
@ -96,7 +63,57 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
void OnEnable () {
|
||||||
|
skeletonRenderer = serializedObject.FindProperty("skeletonRenderer");
|
||||||
|
boneName = serializedObject.FindProperty("boneName");
|
||||||
|
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
||||||
|
followZPosition = serializedObject.FindProperty("followZPosition");
|
||||||
|
followLocalScale = serializedObject.FindProperty("followLocalScale");
|
||||||
|
followSkeletonFlip = serializedObject.FindProperty("followSkeletonFlip");
|
||||||
|
|
||||||
|
targetBoneFollower = (BoneFollower)target;
|
||||||
|
if (targetBoneFollower.SkeletonRenderer != null)
|
||||||
|
targetBoneFollower.SkeletonRenderer.Initialize(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnSceneGUI () {
|
||||||
|
var tbf = target as BoneFollower;
|
||||||
|
var skeletonRendererComponent = tbf.skeletonRenderer;
|
||||||
|
if (skeletonRendererComponent == null) return;
|
||||||
|
|
||||||
|
var transform = skeletonRendererComponent.transform;
|
||||||
|
var skeleton = skeletonRendererComponent.skeleton;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(tbf.boneName)) {
|
||||||
|
SpineHandles.DrawBones(transform, skeleton);
|
||||||
|
SpineHandles.DrawBoneNames(transform, skeleton);
|
||||||
|
Handles.Label(tbf.transform.position, "No bone selected", EditorStyles.helpBox);
|
||||||
|
} else {
|
||||||
|
var targetBone = tbf.bone;
|
||||||
|
if (targetBone == null) return;
|
||||||
|
SpineHandles.DrawBoneWireframe(transform, targetBone, SpineHandles.TransformContraintColor);
|
||||||
|
Handles.Label(targetBone.GetWorldPosition(transform), targetBone.Data.Name, SpineHandles.BoneNameStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override public void OnInspectorGUI () {
|
override public void OnInspectorGUI () {
|
||||||
|
if (serializedObject.isEditingMultipleObjects) {
|
||||||
|
if (needsReset) {
|
||||||
|
needsReset = false;
|
||||||
|
foreach (var o in targets) {
|
||||||
|
var bf = (BoneFollower)o;
|
||||||
|
bf.Initialize();
|
||||||
|
bf.LateUpdate();
|
||||||
|
}
|
||||||
|
SceneView.RepaintAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
DrawDefaultInspector();
|
||||||
|
needsReset |= EditorGUI.EndChangeCheck();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (needsReset) {
|
if (needsReset) {
|
||||||
targetBoneFollower.Initialize();
|
targetBoneFollower.Initialize();
|
||||||
targetBoneFollower.LateUpdate();
|
targetBoneFollower.LateUpdate();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user