mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +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 UnityEditor;
|
||||
using Spine;
|
||||
|
||||
namespace Spine.Unity.Editor {
|
||||
using Icons = SpineEditorUtilities.Icons;
|
||||
@ -44,6 +43,11 @@ namespace Spine.Unity.Editor {
|
||||
public class SkeletonGraphicInspector : UnityEditor.Editor {
|
||||
|
||||
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 skeletonDataAsset, initialSkinName;
|
||||
@ -56,6 +60,7 @@ namespace Spine.Unity.Editor {
|
||||
SkeletonGraphic thisSkeletonGraphic;
|
||||
protected bool isInspectingPrefab;
|
||||
protected bool slotsReapplyRequired = false;
|
||||
protected bool forceReloadQueued = false;
|
||||
|
||||
protected bool TargetIsValid {
|
||||
get {
|
||||
@ -80,6 +85,10 @@ namespace Spine.Unity.Editor {
|
||||
#else
|
||||
isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);
|
||||
#endif
|
||||
SpineEditorUtilities.ConfirmInitialization();
|
||||
|
||||
// Labels
|
||||
SkeletonDataAssetLabel = new GUIContent("SkeletonData Asset", Icons.spine);
|
||||
|
||||
var so = this.serializedObject;
|
||||
thisSkeletonGraphic = target as SkeletonGraphic;
|
||||
@ -115,10 +124,34 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
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;
|
||||
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(color);
|
||||
|
||||
|
||||
@ -82,7 +82,7 @@ namespace Spine.Unity.Editor {
|
||||
const string ReloadButtonString = "Reload";
|
||||
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.miniButtonRight; } }
|
||||
static GUIStyle ReloadButtonStyle { get { return EditorStyles.miniButton; } }
|
||||
|
||||
protected bool TargetIsValid {
|
||||
get {
|
||||
@ -174,9 +174,9 @@ namespace Spine.Unity.Editor {
|
||||
AreAnyMaskMaterialsMissing()) {
|
||||
if (!Application.isPlaying) {
|
||||
if (multi) {
|
||||
foreach (var o in targets) EditorForceInitializeComponent((SkeletonRenderer)o);
|
||||
foreach (var o in targets) SpineEditorUtilities.ReinitializeComponent((SkeletonRenderer)o);
|
||||
} else {
|
||||
EditorForceInitializeComponent((SkeletonRenderer)target);
|
||||
SpineEditorUtilities.ReinitializeComponent((SkeletonRenderer)target);
|
||||
}
|
||||
SceneView.RepaintAll();
|
||||
}
|
||||
@ -188,25 +188,16 @@ namespace Spine.Unity.Editor {
|
||||
if (Event.current.type == EventType.Layout) {
|
||||
if (forceReloadQueued) {
|
||||
forceReloadQueued = false;
|
||||
if (multi) {
|
||||
foreach (var c in targets)
|
||||
EditorForceReloadSkeletonDataAssetAndComponent(c as SkeletonRenderer);
|
||||
} else {
|
||||
EditorForceReloadSkeletonDataAssetAndComponent(target as SkeletonRenderer);
|
||||
foreach (var c in targets) {
|
||||
SpineEditorUtilities.ReloadSkeletonDataAssetAndComponent(c as SkeletonRenderer);
|
||||
}
|
||||
} else {
|
||||
if (multi) {
|
||||
foreach (var c in targets) {
|
||||
var component = c as SkeletonRenderer;
|
||||
if (!component.valid) {
|
||||
EditorForceInitializeComponent(component);
|
||||
if (!component.valid) continue;
|
||||
}
|
||||
foreach (var c in targets) {
|
||||
var component = c as SkeletonRenderer;
|
||||
if (!component.valid) {
|
||||
SpineEditorUtilities.ReinitializeComponent(component);
|
||||
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 (isInspectingPrefab) {
|
||||
if (multi) {
|
||||
foreach (var c in targets) {
|
||||
var component = (SkeletonRenderer)c;
|
||||
MeshFilter meshFilter = component.GetComponent<MeshFilter>();
|
||||
if (meshFilter != null && meshFilter.sharedMesh != null)
|
||||
meshFilter.sharedMesh = null;
|
||||
}
|
||||
} else {
|
||||
var component = (SkeletonRenderer)target;
|
||||
foreach (var c in targets) {
|
||||
var component = (SkeletonRenderer)c;
|
||||
MeshFilter meshFilter = component.GetComponent<MeshFilter>();
|
||||
if (meshFilter != null && meshFilter.sharedMesh != null)
|
||||
meshFilter.sharedMesh = null;
|
||||
@ -286,7 +270,7 @@ namespace Spine.Unity.Editor {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SkeletonDataAssetIsValid(component.skeletonDataAsset)) {
|
||||
if (!SpineEditorUtilities.SkeletonDataAssetIsValid(component.skeletonDataAsset)) {
|
||||
EditorGUILayout.HelpBox("Skeleton Data Asset error. Please check Skeleton Data Asset.", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
@ -535,38 +519,6 @@ namespace Spine.Unity.Editor {
|
||||
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() {
|
||||
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||
foreach (var o in targets) {
|
||||
@ -584,13 +536,13 @@ namespace Spine.Unity.Editor {
|
||||
static void EditorSetMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType)
|
||||
{
|
||||
if (component == null) return;
|
||||
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||
if (!SpineEditorUtilities.SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||
SpineMaskUtilities.EditorInitMaskMaterials(component, component.maskMaterials, maskType);
|
||||
}
|
||||
|
||||
static void EditorDeleteMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType) {
|
||||
if (component == null) return;
|
||||
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||
if (!SpineEditorUtilities.SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||
SpineMaskUtilities.EditorDeleteMaskMaterials(component.maskMaterials, maskType);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -46,6 +46,10 @@
|
||||
#define NEW_PREFERENCES_SETTINGS_PROVIDER
|
||||
#endif
|
||||
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
#define BUILT_IN_SPRITE_MASK_COMPONENT
|
||||
#endif
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
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)
|
||||
{
|
||||
TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user