From d1ea528d419c6827a2a0c6a983203345969cfdb6 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 7 Aug 2019 18:55:16 +0200 Subject: [PATCH] [unity] Fixed Mecanim events for folders. Added preferences entry whether folder name shall be added to called method name or omitted. --- .../Editor/Utility/AssetUtility.cs | 8 ------- .../Editor/Utility/BuildSettings.cs | 4 ---- .../Editor/Utility/DataReloadHandler.cs | 12 ---------- .../spine-unity/Editor/Utility/Icons.cs | 16 -------------- .../Editor/Utility/Instantiation.cs | 16 -------------- .../spine-unity/Editor/Utility/Preferences.cs | 22 +++++++++++++------ .../Editor/Utility/SpineEditorUtilities.cs | 4 ---- .../Editor/Utility/SpineHandles.cs | 16 -------------- .../Editor/Windows/SkeletonBaker.cs | 7 +++++- .../Editor/Windows/SpinePreferences.cs | 19 +++++++++++----- 10 files changed, 35 insertions(+), 89 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs index 4ce8b0c07..6d1587444 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs @@ -39,14 +39,6 @@ #define NEW_PREFAB_SYSTEM #endif -#if UNITY_2018 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEWHIERARCHYWINDOWCALLBACKS -#endif - -#if UNITY_2018_3_OR_NEWER -#define NEW_PREFERENCES_SETTINGS_PROVIDER -#endif - using UnityEngine; using UnityEditor; using System.Collections.Generic; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/BuildSettings.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/BuildSettings.cs index ab49a5921..1a82e4b0e 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/BuildSettings.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/BuildSettings.cs @@ -43,10 +43,6 @@ #define NEWHIERARCHYWINDOWCALLBACKS #endif -#if UNITY_2018_3_OR_NEWER -#define NEW_PREFERENCES_SETTINGS_PROVIDER -#endif - using UnityEngine; using UnityEditor; using System.Collections.Generic; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/DataReloadHandler.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/DataReloadHandler.cs index a489b7a98..34bb21997 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/DataReloadHandler.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/DataReloadHandler.cs @@ -35,18 +35,6 @@ #define NEWPLAYMODECALLBACKS #endif -#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEW_PREFAB_SYSTEM -#endif - -#if UNITY_2018 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEWHIERARCHYWINDOWCALLBACKS -#endif - -#if UNITY_2018_3_OR_NEWER -#define NEW_PREFERENCES_SETTINGS_PROVIDER -#endif - using UnityEngine; using UnityEditor; using System.Collections.Generic; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Icons.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Icons.cs index 0c9aae521..347424f83 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Icons.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Icons.cs @@ -31,22 +31,6 @@ #define SPINE_SKELETONMECANIM -#if UNITY_2017_2_OR_NEWER -#define NEWPLAYMODECALLBACKS -#endif - -#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEW_PREFAB_SYSTEM -#endif - -#if UNITY_2018 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEWHIERARCHYWINDOWCALLBACKS -#endif - -#if UNITY_2018_3_OR_NEWER -#define NEW_PREFERENCES_SETTINGS_PROVIDER -#endif - using UnityEngine; using UnityEditor; using System.Collections.Generic; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Instantiation.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Instantiation.cs index 9dcd7f2c9..9a40f3b9e 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Instantiation.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Instantiation.cs @@ -31,22 +31,6 @@ #define SPINE_SKELETONMECANIM -#if UNITY_2017_2_OR_NEWER -#define NEWPLAYMODECALLBACKS -#endif - -#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEW_PREFAB_SYSTEM -#endif - -#if UNITY_2018 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEWHIERARCHYWINDOWCALLBACKS -#endif - -#if UNITY_2018_3_OR_NEWER -#define NEW_PREFERENCES_SETTINGS_PROVIDER -#endif - using UnityEngine; using UnityEditor; using System.Collections.Generic; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs index a1e733d42..b2a43af17 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs @@ -39,10 +39,6 @@ #define NEW_PREFAB_SYSTEM #endif -#if UNITY_2018 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEWHIERARCHYWINDOWCALLBACKS -#endif - #if UNITY_2018_3_OR_NEWER #define NEW_PREFERENCES_SETTINGS_PROVIDER #endif @@ -139,6 +135,9 @@ namespace Spine.Unity.Editor { const string AUTO_RELOAD_SCENESKELETONS_KEY = "SPINE_AUTO_RELOAD_SCENESKELETONS"; public static bool autoReloadSceneSkeletons = SpinePreferences.DEFAULT_AUTO_RELOAD_SCENESKELETONS; + const string MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY = "SPINE_MECANIM_EVENT_INCLUDE_FOLDERNAME"; + public static bool mecanimEventIncludeFolderName = SpinePreferences.DEFAULT_MECANIM_EVENT_INCLUDE_FOLDERNAME; + static bool preferencesLoaded = false; public static void Load () { @@ -152,6 +151,7 @@ namespace Spine.Unity.Editor { showHierarchyIcons = EditorPrefs.GetBool(SHOW_HIERARCHY_ICONS_KEY, SpinePreferences.DEFAULT_SHOW_HIERARCHY_ICONS); setTextureImporterSettings = EditorPrefs.GetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, SpinePreferences.DEFAULT_SET_TEXTUREIMPORTER_SETTINGS); autoReloadSceneSkeletons = EditorPrefs.GetBool(AUTO_RELOAD_SCENESKELETONS_KEY, SpinePreferences.DEFAULT_AUTO_RELOAD_SCENESKELETONS); + mecanimEventIncludeFolderName = EditorPrefs.GetBool(MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY, SpinePreferences.DEFAULT_MECANIM_EVENT_INCLUDE_FOLDERNAME); atlasTxtImportWarning = EditorPrefs.GetBool(ATLASTXT_WARNING_KEY, SpinePreferences.DEFAULT_ATLASTXT_WARNING); textureImporterWarning = EditorPrefs.GetBool(TEXTUREIMPORTER_WARNING_KEY, SpinePreferences.DEFAULT_TEXTUREIMPORTER_WARNING); @@ -159,7 +159,7 @@ namespace Spine.Unity.Editor { preferencesLoaded = true; } - #if NEW_PREFERENCES_SETTINGS_PROVIDER +#if NEW_PREFERENCES_SETTINGS_PROVIDER public static void CopyOldToNewPreferences(ref SpinePreferences newPreferences) { newPreferences.defaultMix = EditorPrefs.GetFloat(DEFAULT_MIX_KEY, SpinePreferences.DEFAULT_DEFAULT_MIX); newPreferences.defaultScale = EditorPrefs.GetFloat(DEFAULT_SCALE_KEY, SpinePreferences.DEFAULT_DEFAULT_SCALE); @@ -168,6 +168,7 @@ namespace Spine.Unity.Editor { newPreferences.showHierarchyIcons = EditorPrefs.GetBool(SHOW_HIERARCHY_ICONS_KEY, SpinePreferences.DEFAULT_SHOW_HIERARCHY_ICONS); newPreferences.setTextureImporterSettings = EditorPrefs.GetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, SpinePreferences.DEFAULT_SET_TEXTUREIMPORTER_SETTINGS); newPreferences.autoReloadSceneSkeletons = EditorPrefs.GetBool(AUTO_RELOAD_SCENESKELETONS_KEY, SpinePreferences.DEFAULT_AUTO_RELOAD_SCENESKELETONS); + newPreferences.mecanimEventIncludeFolderName = EditorPrefs.GetBool(MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY, SpinePreferences.DEFAULT_MECANIM_EVENT_INCLUDE_FOLDERNAME); newPreferences.atlasTxtImportWarning = EditorPrefs.GetBool(ATLASTXT_WARNING_KEY, SpinePreferences.DEFAULT_ATLASTXT_WARNING); newPreferences.textureImporterWarning = EditorPrefs.GetBool(TEXTUREIMPORTER_WARNING_KEY, SpinePreferences.DEFAULT_TEXTUREIMPORTER_WARNING); } @@ -180,12 +181,13 @@ namespace Spine.Unity.Editor { EditorPrefs.SetBool(SHOW_HIERARCHY_ICONS_KEY, preferences.showHierarchyIcons); EditorPrefs.SetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, preferences.setTextureImporterSettings); EditorPrefs.SetBool(AUTO_RELOAD_SCENESKELETONS_KEY, preferences.autoReloadSceneSkeletons); + EditorPrefs.SetBool(MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY, preferences.mecanimEventIncludeFolderName); EditorPrefs.SetBool(ATLASTXT_WARNING_KEY, preferences.atlasTxtImportWarning); EditorPrefs.SetBool(TEXTUREIMPORTER_WARNING_KEY, preferences.textureImporterWarning); } - #endif +#endif - #if !NEW_PREFERENCES_SETTINGS_PROVIDER +#if !NEW_PREFERENCES_SETTINGS_PROVIDER public static void HandlePreferencesGUI () { if (!preferencesLoaded) Load(); @@ -236,6 +238,12 @@ namespace Spine.Unity.Editor { SpineEditorUtilities.BoolPrefsField(ref defaultInstantiateLoop, DEFAULT_INSTANTIATE_LOOP_KEY, new GUIContent("Default Loop", "Spawn Spine GameObjects with loop enabled.")); } + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Mecanim Settings", EditorStyles.boldLabel); + { + SpineEditorUtilities.BoolPrefsField(ref mecanimEventIncludeFolderName, MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY, new GUIContent("Include Folder Name in Event", "When enabled, Mecanim events will call methods named 'FolderNameEventName', when disabled it will call 'EventName'.")); + } + EditorGUILayout.Space(); EditorGUILayout.LabelField("Handles and Gizmos", EditorStyles.boldLabel); { diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs index beeb6452f..1190d2965 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs @@ -38,10 +38,6 @@ #define NEWPLAYMODECALLBACKS #endif -#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEW_PREFAB_SYSTEM -#endif - #if UNITY_2018 || UNITY_2019 || UNITY_2018_3_OR_NEWER #define NEWHIERARCHYWINDOWCALLBACKS #endif diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineHandles.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineHandles.cs index fa28ede10..1b96feb4c 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineHandles.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineHandles.cs @@ -31,22 +31,6 @@ #define SPINE_SKELETONMECANIM -#if UNITY_2017_2_OR_NEWER -#define NEWPLAYMODECALLBACKS -#endif - -#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEW_PREFAB_SYSTEM -#endif - -#if UNITY_2018 || UNITY_2019 || UNITY_2018_3_OR_NEWER -#define NEWHIERARCHYWINDOWCALLBACKS -#endif - -#if UNITY_2018_3_OR_NEWER -#define NEW_PREFERENCES_SETTINGS_PROVIDER -#endif - using UnityEngine; using UnityEditor; using System.Collections.Generic; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SkeletonBaker.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SkeletonBaker.cs index c77be6187..afffd8490 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SkeletonBaker.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SkeletonBaker.cs @@ -1301,9 +1301,14 @@ namespace Spine.Unity.Editor { var animEvents = new List(); for (int i = 0, n = frames.Length; i < n; i++) { var spineEvent = events[i]; + string eventName = spineEvent.Data.Name; + if (SpineEditorUtilities.Preferences.mecanimEventIncludeFolderName) + eventName = eventName.Replace("/", ""); // calls method FolderNameEventName() + else + eventName = eventName.Substring(eventName.LastIndexOf('/') + 1); // calls method EventName() var unityAnimationEvent = new AnimationEvent { time = frames[i], - functionName = spineEvent.Data.Name, + functionName = eventName, messageOptions = eventOptions }; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs index 2e4107aa7..c9e9e8adf 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs @@ -89,7 +89,10 @@ namespace Spine.Unity.Editor { internal const float DEFAULT_SCENE_ICONS_SCALE = 1f; public const string SCENE_ICONS_SCALE_KEY = "SPINE_SCENE_ICONS_SCALE"; - #if NEW_PREFERENCES_SETTINGS_PROVIDER + public const bool DEFAULT_MECANIM_EVENT_INCLUDE_FOLDERNAME = true; + public bool mecanimEventIncludeFolderName = DEFAULT_MECANIM_EVENT_INCLUDE_FOLDERNAME; + +#if NEW_PREFERENCES_SETTINGS_PROVIDER public static void Load () { SpineHandles.handleScale = EditorPrefs.GetFloat(SCENE_ICONS_SCALE_KEY, DEFAULT_SCENE_ICONS_SCALE); GetOrCreateSettings(); @@ -121,11 +124,11 @@ namespace Spine.Unity.Editor { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(settings.FindProperty("showHierarchyIcons"), new GUIContent("Show Hierarchy Icons", "Show relevant icons on GameObjects with Spine Components on them. Disable this if you have large, complex scenes.")); if (EditorGUI.EndChangeCheck()) { - #if NEWPLAYMODECALLBACKS +#if NEWPLAYMODECALLBACKS SpineEditorUtilities.HierarchyHandler.IconsOnPlaymodeStateChanged(PlayModeStateChange.EnteredEditMode); - #else +#else SpineEditorUtilities.HierarchyHandler.IconsOnPlaymodeStateChanged(); - #endif +#endif } EditorGUILayout.PropertyField(settings.FindProperty("autoReloadSceneSkeletons"), 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.")); @@ -155,6 +158,12 @@ namespace Spine.Unity.Editor { EditorGUILayout.PropertyField(settings.FindProperty("defaultInstantiateLoop"), new GUIContent("Default Loop", "Spawn Spine GameObjects with loop enabled.")); } + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Mecanim Settings", EditorStyles.boldLabel); + { + EditorGUILayout.PropertyField(settings.FindProperty("mecanimEventIncludeFolderName"), new GUIContent("Include Folder Name in Event", "When enabled, Mecanim events will call methods named 'FolderNameEventName', when disabled it will call 'EventName'.")); + } + EditorGUILayout.Space(); EditorGUILayout.LabelField("Handles and Gizmos", EditorStyles.boldLabel); { @@ -179,6 +188,6 @@ namespace Spine.Unity.Editor { } EditorGUIUtility.labelWidth = prevLabelWidth; } - #endif // NEW_PREFERENCES_SETTINGS_PROVIDER +#endif // NEW_PREFERENCES_SETTINGS_PROVIDER } }