mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[unity] Added SkeletonDataAsset 'Reload' button for SkeletonGraphic. See #1704.
This commit is contained in:
parent
3a1dcd651a
commit
06bd6a90bd
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using Spine;
|
|
||||||
|
|
||||||
namespace Spine.Unity.Editor {
|
namespace Spine.Unity.Editor {
|
||||||
using Icons = SpineEditorUtilities.Icons;
|
using Icons = SpineEditorUtilities.Icons;
|
||||||
@ -44,6 +43,11 @@ namespace Spine.Unity.Editor {
|
|||||||
public class SkeletonGraphicInspector : UnityEditor.Editor {
|
public class SkeletonGraphicInspector : UnityEditor.Editor {
|
||||||
|
|
||||||
const string SeparatorSlotNamesFieldName = "separatorSlotNames";
|
const string SeparatorSlotNamesFieldName = "separatorSlotNames";
|
||||||
|
const string ReloadButtonString = "Reload";
|
||||||
|
protected GUIContent SkeletonDataAssetLabel;
|
||||||
|
static GUILayoutOption reloadButtonWidth;
|
||||||
|
static GUILayoutOption ReloadButtonWidth { get { return reloadButtonWidth = reloadButtonWidth ?? GUILayout.Width(GUI.skin.label.CalcSize(new GUIContent(ReloadButtonString)).x + 20); } }
|
||||||
|
static GUIStyle ReloadButtonStyle { get { return EditorStyles.miniButton; } }
|
||||||
|
|
||||||
SerializedProperty material, color;
|
SerializedProperty material, color;
|
||||||
SerializedProperty skeletonDataAsset, initialSkinName;
|
SerializedProperty skeletonDataAsset, initialSkinName;
|
||||||
@ -56,6 +60,7 @@ namespace Spine.Unity.Editor {
|
|||||||
SkeletonGraphic thisSkeletonGraphic;
|
SkeletonGraphic thisSkeletonGraphic;
|
||||||
protected bool isInspectingPrefab;
|
protected bool isInspectingPrefab;
|
||||||
protected bool slotsReapplyRequired = false;
|
protected bool slotsReapplyRequired = false;
|
||||||
|
protected bool forceReloadQueued = false;
|
||||||
|
|
||||||
protected bool TargetIsValid {
|
protected bool TargetIsValid {
|
||||||
get {
|
get {
|
||||||
@ -80,6 +85,10 @@ namespace Spine.Unity.Editor {
|
|||||||
#else
|
#else
|
||||||
isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);
|
isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);
|
||||||
#endif
|
#endif
|
||||||
|
SpineEditorUtilities.ConfirmInitialization();
|
||||||
|
|
||||||
|
// Labels
|
||||||
|
SkeletonDataAssetLabel = new GUIContent("SkeletonData Asset", Icons.spine);
|
||||||
|
|
||||||
var so = this.serializedObject;
|
var so = this.serializedObject;
|
||||||
thisSkeletonGraphic = target as SkeletonGraphic;
|
thisSkeletonGraphic = target as SkeletonGraphic;
|
||||||
@ -115,10 +124,34 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void OnInspectorGUI () {
|
public override void OnInspectorGUI () {
|
||||||
|
|
||||||
|
if (UnityEngine.Event.current.type == EventType.Layout) {
|
||||||
|
if (forceReloadQueued) {
|
||||||
|
forceReloadQueued = false;
|
||||||
|
foreach (var c in targets) {
|
||||||
|
SpineEditorUtilities.ReloadSkeletonDataAssetAndComponent(c as SkeletonGraphic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach (var c in targets) {
|
||||||
|
var component = c as SkeletonGraphic;
|
||||||
|
if (!component.IsValid) {
|
||||||
|
SpineEditorUtilities.ReinitializeComponent(component);
|
||||||
|
if (!component.IsValid) continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool wasChanged = false;
|
bool wasChanged = false;
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(skeletonDataAsset);
|
using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
|
||||||
|
SpineInspectorUtility.PropertyFieldFitLabel(skeletonDataAsset, SkeletonDataAssetLabel);
|
||||||
|
if (GUILayout.Button(ReloadButtonString, ReloadButtonStyle, ReloadButtonWidth))
|
||||||
|
forceReloadQueued = true;
|
||||||
|
}
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(material);
|
EditorGUILayout.PropertyField(material);
|
||||||
EditorGUILayout.PropertyField(color);
|
EditorGUILayout.PropertyField(color);
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,7 @@ namespace Spine.Unity.Editor {
|
|||||||
const string ReloadButtonString = "Reload";
|
const string ReloadButtonString = "Reload";
|
||||||
static GUILayoutOption reloadButtonWidth;
|
static GUILayoutOption reloadButtonWidth;
|
||||||
static GUILayoutOption ReloadButtonWidth { get { return reloadButtonWidth = reloadButtonWidth ?? GUILayout.Width(GUI.skin.label.CalcSize(new GUIContent(ReloadButtonString)).x + 20); } }
|
static GUILayoutOption ReloadButtonWidth { get { return reloadButtonWidth = reloadButtonWidth ?? GUILayout.Width(GUI.skin.label.CalcSize(new GUIContent(ReloadButtonString)).x + 20); } }
|
||||||
static GUIStyle ReloadButtonStyle { get { return EditorStyles.miniButtonRight; } }
|
static GUIStyle ReloadButtonStyle { get { return EditorStyles.miniButton; } }
|
||||||
|
|
||||||
protected bool TargetIsValid {
|
protected bool TargetIsValid {
|
||||||
get {
|
get {
|
||||||
@ -174,9 +174,9 @@ namespace Spine.Unity.Editor {
|
|||||||
AreAnyMaskMaterialsMissing()) {
|
AreAnyMaskMaterialsMissing()) {
|
||||||
if (!Application.isPlaying) {
|
if (!Application.isPlaying) {
|
||||||
if (multi) {
|
if (multi) {
|
||||||
foreach (var o in targets) EditorForceInitializeComponent((SkeletonRenderer)o);
|
foreach (var o in targets) SpineEditorUtilities.ReinitializeComponent((SkeletonRenderer)o);
|
||||||
} else {
|
} else {
|
||||||
EditorForceInitializeComponent((SkeletonRenderer)target);
|
SpineEditorUtilities.ReinitializeComponent((SkeletonRenderer)target);
|
||||||
}
|
}
|
||||||
SceneView.RepaintAll();
|
SceneView.RepaintAll();
|
||||||
}
|
}
|
||||||
@ -188,25 +188,16 @@ namespace Spine.Unity.Editor {
|
|||||||
if (Event.current.type == EventType.Layout) {
|
if (Event.current.type == EventType.Layout) {
|
||||||
if (forceReloadQueued) {
|
if (forceReloadQueued) {
|
||||||
forceReloadQueued = false;
|
forceReloadQueued = false;
|
||||||
if (multi) {
|
foreach (var c in targets) {
|
||||||
foreach (var c in targets)
|
SpineEditorUtilities.ReloadSkeletonDataAssetAndComponent(c as SkeletonRenderer);
|
||||||
EditorForceReloadSkeletonDataAssetAndComponent(c as SkeletonRenderer);
|
|
||||||
} else {
|
|
||||||
EditorForceReloadSkeletonDataAssetAndComponent(target as SkeletonRenderer);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (multi) {
|
foreach (var c in targets) {
|
||||||
foreach (var c in targets) {
|
var component = c as SkeletonRenderer;
|
||||||
var component = c as SkeletonRenderer;
|
if (!component.valid) {
|
||||||
if (!component.valid) {
|
SpineEditorUtilities.ReinitializeComponent(component);
|
||||||
EditorForceInitializeComponent(component);
|
if (!component.valid) continue;
|
||||||
if (!component.valid) continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
var component = (SkeletonRenderer)target;
|
|
||||||
if (!component.valid)
|
|
||||||
EditorForceInitializeComponent(component);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,15 +232,8 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
#if NO_PREFAB_MESH
|
#if NO_PREFAB_MESH
|
||||||
if (isInspectingPrefab) {
|
if (isInspectingPrefab) {
|
||||||
if (multi) {
|
foreach (var c in targets) {
|
||||||
foreach (var c in targets) {
|
var component = (SkeletonRenderer)c;
|
||||||
var component = (SkeletonRenderer)c;
|
|
||||||
MeshFilter meshFilter = component.GetComponent<MeshFilter>();
|
|
||||||
if (meshFilter != null && meshFilter.sharedMesh != null)
|
|
||||||
meshFilter.sharedMesh = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var component = (SkeletonRenderer)target;
|
|
||||||
MeshFilter meshFilter = component.GetComponent<MeshFilter>();
|
MeshFilter meshFilter = component.GetComponent<MeshFilter>();
|
||||||
if (meshFilter != null && meshFilter.sharedMesh != null)
|
if (meshFilter != null && meshFilter.sharedMesh != null)
|
||||||
meshFilter.sharedMesh = null;
|
meshFilter.sharedMesh = null;
|
||||||
@ -286,7 +270,7 @@ namespace Spine.Unity.Editor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SkeletonDataAssetIsValid(component.skeletonDataAsset)) {
|
if (!SpineEditorUtilities.SkeletonDataAssetIsValid(component.skeletonDataAsset)) {
|
||||||
EditorGUILayout.HelpBox("Skeleton Data Asset error. Please check Skeleton Data Asset.", MessageType.Error);
|
EditorGUILayout.HelpBox("Skeleton Data Asset error. Please check Skeleton Data Asset.", MessageType.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -535,38 +519,6 @@ namespace Spine.Unity.Editor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EditorForceReloadSkeletonDataAssetAndComponent (SkeletonRenderer component) {
|
|
||||||
if (component == null) return;
|
|
||||||
|
|
||||||
// Clear all and reload.
|
|
||||||
if (component.skeletonDataAsset != null) {
|
|
||||||
foreach (AtlasAssetBase aa in component.skeletonDataAsset.atlasAssets) {
|
|
||||||
if (aa != null) aa.Clear();
|
|
||||||
}
|
|
||||||
component.skeletonDataAsset.Clear();
|
|
||||||
}
|
|
||||||
component.skeletonDataAsset.GetSkeletonData(true);
|
|
||||||
|
|
||||||
// Reinitialize.
|
|
||||||
EditorForceInitializeComponent(component);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void EditorForceInitializeComponent (SkeletonRenderer component) {
|
|
||||||
if (component == null) return;
|
|
||||||
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
|
||||||
component.Initialize(true);
|
|
||||||
|
|
||||||
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
|
||||||
SpineMaskUtilities.EditorAssignSpriteMaskMaterials(component);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
component.LateUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool SkeletonDataAssetIsValid (SkeletonDataAsset asset) {
|
|
||||||
return asset != null && asset.GetSkeletonData(quiet: true) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AreAnyMaskMaterialsMissing() {
|
bool AreAnyMaskMaterialsMissing() {
|
||||||
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
foreach (var o in targets) {
|
foreach (var o in targets) {
|
||||||
@ -584,13 +536,13 @@ namespace Spine.Unity.Editor {
|
|||||||
static void EditorSetMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType)
|
static void EditorSetMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType)
|
||||||
{
|
{
|
||||||
if (component == null) return;
|
if (component == null) return;
|
||||||
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
if (!SpineEditorUtilities.SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||||
SpineMaskUtilities.EditorInitMaskMaterials(component, component.maskMaterials, maskType);
|
SpineMaskUtilities.EditorInitMaskMaterials(component, component.maskMaterials, maskType);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EditorDeleteMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType) {
|
static void EditorDeleteMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType) {
|
||||||
if (component == null) return;
|
if (component == null) return;
|
||||||
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
if (!SpineEditorUtilities.SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||||
SpineMaskUtilities.EditorDeleteMaskMaterials(component.maskMaterials, maskType);
|
SpineMaskUtilities.EditorDeleteMaskMaterials(component.maskMaterials, maskType);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -46,6 +46,10 @@
|
|||||||
#define NEW_PREFERENCES_SETTINGS_PROVIDER
|
#define NEW_PREFERENCES_SETTINGS_PROVIDER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if UNITY_2017_1_OR_NEWER
|
||||||
|
#define BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
|
#endif
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -189,6 +193,51 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ReloadSkeletonDataAssetAndComponent (SkeletonRenderer component) {
|
||||||
|
if (component == null) return;
|
||||||
|
ReloadSkeletonDataAsset(component.skeletonDataAsset);
|
||||||
|
ReinitializeComponent(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ReloadSkeletonDataAssetAndComponent (SkeletonGraphic component) {
|
||||||
|
if (component == null) return;
|
||||||
|
ReloadSkeletonDataAsset(component.skeletonDataAsset);
|
||||||
|
// Reinitialize.
|
||||||
|
ReinitializeComponent(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ReloadSkeletonDataAsset (SkeletonDataAsset skeletonDataAsset) {
|
||||||
|
if (skeletonDataAsset != null) {
|
||||||
|
foreach (AtlasAssetBase aa in skeletonDataAsset.atlasAssets) {
|
||||||
|
if (aa != null) aa.Clear();
|
||||||
|
}
|
||||||
|
skeletonDataAsset.Clear();
|
||||||
|
}
|
||||||
|
skeletonDataAsset.GetSkeletonData(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ReinitializeComponent (SkeletonRenderer component) {
|
||||||
|
if (component == null) return;
|
||||||
|
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||||
|
component.Initialize(true);
|
||||||
|
|
||||||
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
|
SpineMaskUtilities.EditorAssignSpriteMaskMaterials(component);
|
||||||
|
#endif
|
||||||
|
component.LateUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ReinitializeComponent (SkeletonGraphic component) {
|
||||||
|
if (component == null) return;
|
||||||
|
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||||
|
component.Initialize(true);
|
||||||
|
component.LateUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool SkeletonDataAssetIsValid (SkeletonDataAsset asset) {
|
||||||
|
return asset != null && asset.GetSkeletonData(quiet: true) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IssueWarningsForUnrecommendedTextureSettings(string texturePath)
|
public static bool IssueWarningsForUnrecommendedTextureSettings(string texturePath)
|
||||||
{
|
{
|
||||||
TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath);
|
TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user