This commit is contained in:
badlogic 2018-12-05 15:50:37 +01:00
commit c43b2b49e7

View File

@ -33,6 +33,15 @@
// Original contribution by: Mitch Thompson
#define SPINE_SKELETONMECANIM
#if UNITY_2017_2_OR_NEWER
#define NEWPLAYMODECALLBACKS
#endif
#if UNITY_2018 || UNITY_2019
#define NEWHIERARCHYWINDOWCALLBACKS
#endif
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
@ -192,7 +201,7 @@ namespace Spine.Unity.Editor {
EditorApplication.hierarchyWindowItemOnGUI += HierarchyHandler.HandleDragAndDrop;
// Hierarchy Icons
#if UNITY_2017_2_OR_NEWER
#if NEWPLAYMODECALLBACKS
EditorApplication.playModeStateChanged -= HierarchyHandler.IconsOnPlaymodeStateChanged;
EditorApplication.playModeStateChanged += HierarchyHandler.IconsOnPlaymodeStateChanged;
HierarchyHandler.IconsOnPlaymodeStateChanged(PlayModeStateChange.EnteredEditMode);
@ -204,7 +213,7 @@ namespace Spine.Unity.Editor {
// Data Refresh Edit Mode.
// This prevents deserialized SkeletonData from persisting from play mode to edit mode.
#if UNITY_2017_2_OR_NEWER
#if NEWPLAYMODECALLBACKS
EditorApplication.playModeStateChanged -= DataReloadHandler.OnPlaymodeStateChanged;
EditorApplication.playModeStateChanged += DataReloadHandler.OnPlaymodeStateChanged;
DataReloadHandler.OnPlaymodeStateChanged(PlayModeStateChange.EnteredEditMode);
@ -256,6 +265,10 @@ namespace Spine.Unity.Editor {
const string SET_TEXTUREIMPORTER_SETTINGS_KEY = "SPINE_SET_TEXTUREIMPORTER_SETTINGS";
public static bool setTextureImporterSettings = DEFAULT_SET_TEXTUREIMPORTER_SETTINGS;
const bool DEFAULT_ATLASTXT_WARNING = true;
const string ATLASTXT_WARNING_KEY = "SPINE_ATLASTXT_WARNING";
public static bool atlasTxtImportWarning = DEFAULT_SET_TEXTUREIMPORTER_SETTINGS;
internal const float DEFAULT_MIPMAPBIAS = -0.5f;
public const float DEFAULT_SCENE_ICONS_SCALE = 1f;
@ -275,6 +288,7 @@ namespace Spine.Unity.Editor {
showHierarchyIcons = EditorPrefs.GetBool(SHOW_HIERARCHY_ICONS_KEY, DEFAULT_SHOW_HIERARCHY_ICONS);
setTextureImporterSettings = EditorPrefs.GetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, DEFAULT_SET_TEXTUREIMPORTER_SETTINGS);
autoReloadSceneSkeletons = EditorPrefs.GetBool(AUTO_RELOAD_SCENESKELETONS_KEY, DEFAULT_AUTO_RELOAD_SCENESKELETONS);
atlasTxtImportWarning = EditorPrefs.GetBool(ATLASTXT_WARNING_KEY, DEFAULT_ATLASTXT_WARNING);
SpineHandles.handleScale = EditorPrefs.GetFloat(SCENE_ICONS_SCALE_KEY, DEFAULT_SCENE_ICONS_SCALE);
preferencesLoaded = true;
@ -288,28 +302,20 @@ namespace Spine.Unity.Editor {
showHierarchyIcons = EditorGUILayout.Toggle(new GUIContent("Show Hierarchy Icons", "Show relevant icons on GameObjects with Spine Components on them. Disable this if you have large, complex scenes."), showHierarchyIcons);
if (EditorGUI.EndChangeCheck()) {
EditorPrefs.SetBool(SHOW_HIERARCHY_ICONS_KEY, showHierarchyIcons);
#if UNITY_2017_2_OR_NEWER
#if NEWPLAYMODECALLBACKS
HierarchyHandler.IconsOnPlaymodeStateChanged(PlayModeStateChange.EnteredEditMode);
#else
HierarchyHandler.IconsOnPlaymodeStateChanged();
#endif
}
autoReloadSceneSkeletons = EditorGUILayout.Toggle(new GUIContent("Auto-reload scene components", "Reloads Skeleton components in the scene whenever their SkeletonDataAsset is modified. This makes it so changes in the SkeletonDataAsset inspector are immediately reflected. This may be slow when your scenes have large numbers of SkeletonRenderers or SkeletonGraphic."), autoReloadSceneSkeletons);
BoolPrefsField(ref autoReloadSceneSkeletons, AUTO_RELOAD_SCENESKELETONS_KEY, new GUIContent("Auto-reload scene components", "Reloads Skeleton components in the scene whenever their SkeletonDataAsset is modified. This makes it so changes in the SkeletonDataAsset inspector are immediately reflected. This may be slow when your scenes have large numbers of SkeletonRenderers or SkeletonGraphic."));
EditorGUILayout.Separator();
EditorGUILayout.LabelField("Auto-Import Settings", EditorStyles.boldLabel);
EditorGUI.BeginChangeCheck();
defaultMix = EditorGUILayout.FloatField("Default Mix", defaultMix);
if (EditorGUI.EndChangeCheck())
EditorPrefs.SetFloat(DEFAULT_MIX_KEY, defaultMix);
EditorGUI.BeginChangeCheck();
defaultScale = EditorGUILayout.FloatField("Default SkeletonData Scale", defaultScale);
if (EditorGUI.EndChangeCheck())
EditorPrefs.SetFloat(DEFAULT_SCALE_KEY, defaultScale);
{
SpineEditorUtilities.FloatPrefsField(ref defaultMix, DEFAULT_MIX_KEY, new GUIContent("Default Mix", "The Default Mix Duration for newly imported SkeletonDataAssets."), min: 0);
SpineEditorUtilities.FloatPrefsField(ref defaultScale, DEFAULT_SCALE_KEY, new GUIContent("Default SkeletonData Scale", "The Default skeleton import scale for newly imported SkeletonDataAssets."), min: 0.0000001f);
EditorGUI.BeginChangeCheck();
var shader = (EditorGUILayout.ObjectField("Default Shader", Shader.Find(defaultShader), typeof(Shader), false) as Shader);
@ -317,27 +323,24 @@ namespace Spine.Unity.Editor {
if (EditorGUI.EndChangeCheck())
EditorPrefs.SetString(DEFAULT_SHADER_KEY, defaultShader);
EditorGUI.BeginChangeCheck();
setTextureImporterSettings = EditorGUILayout.Toggle(new GUIContent("Apply Atlas Texture Settings", "Apply the recommended settings for Texture Importers."), showHierarchyIcons);
if (EditorGUI.EndChangeCheck()) {
EditorPrefs.SetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, showHierarchyIcons);
SpineEditorUtilities.BoolPrefsField(ref setTextureImporterSettings, SET_TEXTUREIMPORTER_SETTINGS_KEY, new GUIContent("Apply Atlas Texture Settings", "Apply the recommended settings for Texture Importers."));
SpineEditorUtilities.BoolPrefsField(ref atlasTxtImportWarning, ATLASTXT_WARNING_KEY, new GUIContent("Atlas Extension Warning", "Log a warning and recommendation whenever a `.atlas` file is found."));
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Editor Instantiation", EditorStyles.boldLabel);
{
EditorGUI.BeginChangeCheck();
defaultZSpacing = EditorGUILayout.Slider("Default Slot Z-Spacing", defaultZSpacing, -0.1f, 0f);
if (EditorGUI.EndChangeCheck())
EditorPrefs.SetFloat(DEFAULT_ZSPACING_KEY, defaultZSpacing);
EditorGUI.BeginChangeCheck();
defaultInstantiateLoop = EditorGUILayout.Toggle(new GUIContent("Default Loop", "Spawn Spine GameObjects with loop enabled."), defaultInstantiateLoop);
if (EditorGUI.EndChangeCheck())
EditorPrefs.SetBool(DEFAULT_INSTANTIATE_LOOP_KEY, defaultInstantiateLoop);
SpineEditorUtilities.BoolPrefsField(ref defaultInstantiateLoop, DEFAULT_INSTANTIATE_LOOP_KEY, new GUIContent("Default Loop", "Spawn Spine GameObjects with loop enabled."));
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Handles and Gizmos", EditorStyles.boldLabel);
{
EditorGUI.BeginChangeCheck();
SpineHandles.handleScale = EditorGUILayout.Slider("Editor Bone Scale", SpineHandles.handleScale, 0.01f, 2f);
SpineHandles.handleScale = Mathf.Max(0.01f, SpineHandles.handleScale);
@ -345,6 +348,8 @@ namespace Spine.Unity.Editor {
EditorPrefs.SetFloat(SCENE_ICONS_SCALE_KEY, SpineHandles.handleScale);
SceneView.RepaintAll();
}
}
GUILayout.Space(20);
@ -359,8 +364,26 @@ namespace Spine.Unity.Editor {
}
}
static void BoolPrefsField (ref bool currentValue, string editorPrefsKey, GUIContent label) {
EditorGUI.BeginChangeCheck();
currentValue = EditorGUILayout.Toggle(label, currentValue);
if (EditorGUI.EndChangeCheck())
EditorPrefs.SetBool(editorPrefsKey, currentValue);
}
static void FloatPrefsField (ref float currentValue, string editorPrefsKey, GUIContent label, float min = float.NegativeInfinity, float max = float.PositiveInfinity) {
EditorGUI.BeginChangeCheck();
currentValue = EditorGUILayout.DelayedFloatField(label, currentValue);
if (EditorGUI.EndChangeCheck()) {
currentValue = Mathf.Clamp(currentValue, min, max);
EditorPrefs.SetFloat(editorPrefsKey, currentValue);
}
}
public static class DataReloadHandler {
#if UNITY_2017_2_OR_NEWER
#if NEWPLAYMODECALLBACKS
internal static void OnPlaymodeStateChanged (PlayModeStateChange stateChange) {
#else
internal static void OnPlaymodeStateChanged () {
@ -597,6 +620,11 @@ namespace Spine.Unity.Editor {
foreach (string str in imported) {
string extension = Path.GetExtension(str).ToLower();
switch (extension) {
case ".atlas":
if (SpineEditorUtilities.Preferences.atlasTxtImportWarning) {
Debug.LogWarningFormat("`{0}` : If this file is a Spine atlas, please change its extension to `.atlas.txt`. This is to allow Unity to recognize it and avoid filename collisions. You can also set this file extension when exporting from the Spine editor.", str);
}
break;
case ".txt":
if (str.EndsWith(".atlas.txt", System.StringComparison.Ordinal))
atlasPaths.Add(str);
@ -1473,7 +1501,7 @@ namespace Spine.Unity.Editor {
static Dictionary<int, SkeletonUtilityBone> skeletonUtilityBoneTable = new Dictionary<int, SkeletonUtilityBone>();
static Dictionary<int, BoundingBoxFollower> boundingBoxFollowerTable = new Dictionary<int, BoundingBoxFollower>();
#if UNITY_2017_2_OR_NEWER
#if NEWPLAYMODECALLBACKS
internal static void IconsOnPlaymodeStateChanged (PlayModeStateChange stateChange) {
#else
internal static void IconsOnPlaymodeStateChanged () {
@ -1482,7 +1510,7 @@ namespace Spine.Unity.Editor {
skeletonUtilityBoneTable.Clear();
boundingBoxFollowerTable.Clear();
#if UNITY_2018
#if NEWHIERARCHYWINDOWCALLBACKS
EditorApplication.hierarchyChanged -= IconsOnChanged;
#else
EditorApplication.hierarchyWindowChanged -= IconsOnChanged;
@ -1490,7 +1518,7 @@ namespace Spine.Unity.Editor {
EditorApplication.hierarchyWindowItemOnGUI -= IconsOnGUI;
if (!Application.isPlaying && Preferences.showHierarchyIcons) {
#if UNITY_2018
#if NEWHIERARCHYWINDOWCALLBACKS
EditorApplication.hierarchyChanged += IconsOnChanged;
#else
EditorApplication.hierarchyWindowChanged += IconsOnChanged;