From b6e67121453600e4f294405c3eb79b17e60ab7dd Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 14 Sep 2022 13:55:08 +0200 Subject: [PATCH 1/4] [csharp] Port of commit d6adbe96. Allow calling RegionAttachment#updateRegion when region is null. --- .../src/Attachments/RegionAttachment.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/spine-csharp/src/Attachments/RegionAttachment.cs b/spine-csharp/src/Attachments/RegionAttachment.cs index b0642a13c..0e7197ea7 100644 --- a/spine-csharp/src/Attachments/RegionAttachment.cs +++ b/spine-csharp/src/Attachments/RegionAttachment.cs @@ -93,6 +93,19 @@ namespace Spine { /// Calculates the and using the region and the attachment's transform. Must be called if the /// region, the region's properties, or the transform are changed. public void UpdateRegion () { + float[] uvs = this.uvs; + if (region == null) { + uvs[BLX] = 0; + uvs[BLY] = 0; + uvs[ULX] = 1; + uvs[ULY] = 1; + uvs[URX] = 1; + uvs[URY] = 1; + uvs[BRX] = 1; + uvs[BRY] = 0; + return; + } + float width = Width; float height = Height; float localX2 = width / 2; @@ -142,25 +155,24 @@ namespace Spine { offset[BRX] = localX2Cos - localYSin; offset[BRY] = localYCos + localX2Sin; - float[] uvs = this.uvs; if (rotated) { - uvs[URX] = region.u; - uvs[URY] = region.v2; - uvs[BRX] = region.u; - uvs[BRY] = region.v; uvs[BLX] = region.u2; uvs[BLY] = region.v; uvs[ULX] = region.u2; uvs[ULY] = region.v2; + uvs[URX] = region.u; + uvs[URY] = region.v2; + uvs[BRX] = region.u; + uvs[BRY] = region.v; } else { + uvs[BLX] = region.u2; + uvs[BLY] = region.v2; uvs[ULX] = region.u; uvs[ULY] = region.v2; uvs[URX] = region.u; uvs[URY] = region.v; uvs[BRX] = region.u2; uvs[BRY] = region.v; - uvs[BLX] = region.u2; - uvs[BLY] = region.v2; } } From 899f7d77efcddde36a9b27938720c51ffc6b7528 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Wed, 14 Sep 2022 10:20:57 -0400 Subject: [PATCH 2/4] [monogame] Fixed rendering for sequence attachments. A region attachment with a sequence has its texture region set by `computeWorldVertices`. That must be called before the texture region is assigned to a local. --- spine-monogame/spine-monogame/src/SkeletonRenderer.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spine-monogame/spine-monogame/src/SkeletonRenderer.cs b/spine-monogame/spine-monogame/src/SkeletonRenderer.cs index 17c9c712a..8389ca710 100644 --- a/spine-monogame/spine-monogame/src/SkeletonRenderer.cs +++ b/spine-monogame/spine-monogame/src/SkeletonRenderer.cs @@ -123,18 +123,16 @@ namespace Spine { if (attachment is RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment)attachment; attachmentColorR = regionAttachment.R; attachmentColorG = regionAttachment.G; attachmentColorB = regionAttachment.B; attachmentColorA = regionAttachment.A; - AtlasRegion region = (AtlasRegion)regionAttachment.Region; - textureObject = region.page.rendererObject; - verticesCount = 4; regionAttachment.ComputeWorldVertices(slot, vertices, 0, 2); + verticesCount = 4; indicesCount = 6; indices = quadTriangles; uvs = regionAttachment.UVs; + AtlasRegion region = (AtlasRegion)regionAttachment.Region; + textureObject = region.page.rendererObject; } else if (attachment is MeshAttachment) { MeshAttachment mesh = (MeshAttachment)attachment; attachmentColorR = mesh.R; attachmentColorG = mesh.G; attachmentColorB = mesh.B; attachmentColorA = mesh.A; - AtlasRegion region = (AtlasRegion)mesh.Region; - textureObject = region.page.rendererObject; int vertexCount = mesh.WorldVerticesLength; if (vertices.Length < vertexCount) vertices = new float[vertexCount]; verticesCount = vertexCount >> 1; @@ -142,6 +140,8 @@ namespace Spine { indicesCount = mesh.Triangles.Length; indices = mesh.Triangles; uvs = mesh.UVs; + AtlasRegion region = (AtlasRegion)mesh.Region; + textureObject = region.page.rendererObject; } else if (attachment is ClippingAttachment) { ClippingAttachment clip = (ClippingAttachment)attachment; clipper.ClipStart(slot, clip); From d0002bcbaba035b84d97419a998d31b8889b8ca1 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Wed, 14 Sep 2022 10:28:42 -0400 Subject: [PATCH 3/4] [c] Formatting. --- spine-c/spine-c/src/spine/SkeletonBinary.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-c/spine-c/src/spine/SkeletonBinary.c b/spine-c/spine-c/src/spine/SkeletonBinary.c index 406c7f389..19fff284a 100644 --- a/spine-c/spine-c/src/spine/SkeletonBinary.c +++ b/spine-c/spine-c/src/spine/SkeletonBinary.c @@ -129,7 +129,7 @@ static int readVarint(_dataInput *input, int /*bool*/ optimizePositive) { } } if (!optimizePositive) - value = ((unsigned int) value >> 1) ^ (~(value & 1)); + value = ((unsigned int) value >> 1) ^ (~(value & 1)); return (int) value; } From f1cababc9a76869f4feba6a8b3d9dc18cd0f877c Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 14 Sep 2022 17:14:38 +0200 Subject: [PATCH 4/4] [unity] Added Preferences setting `Reload SkeletonData after Play`, disable to avoid the reloading delay after exiting play-mode. --- CHANGELOG.md | 1 + .../Editor/spine-unity/Editor/Utility/DataReloadHandler.cs | 2 +- .../Spine/Editor/spine-unity/Editor/Utility/Preferences.cs | 7 +++++++ .../Editor/spine-unity/Editor/Windows/SpinePreferences.cs | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f734a218d..fd7e65f30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,7 @@ * Added `SkeletonRootMotion` callback delegates `ProcessRootMotionOverride` and `PhysicsUpdateRootMotionOverride` to customize how root motion is applied. The new property `disableOnOverride` determines whether the callback will be issued in addition or instead of normally applying root motion. Added property `rootMotionScaleRotation` to allow scaling rotational root-motion to match e.g. a 90 degree rotation to a custom target angle. * Added outline shader parameter `Advanced - Opaque Alpha` which can be used to exclude problematic semi-transparent areas, which may receive an undesired large outline color overlay otherwise. * Added Spine Preferences setting `Prefabs` - `Optimize Preview Meshes`. When enabled, Spine prefab preview meshes will be removed in a pre-build step to reduce build size. This increases build time as all prefabs in the project will be processed. Defaults to false to not slow down builds substantially every time. + * Added Spine Preferences setting `Reload SkeletonData after Play`. When enabled, the shared `SkeletonData` of all skeletons in the active scene is reloaded (from the `.json` or `.skel.bytes` file) after exiting play-mode. You can disable this setting to avoid the reloading delay if you can ensure that there are no (accidental) modifications to the shared `SkeletonData` during play-mode (otherwise it would carry over its effect into subsequent plays). Defaults to `true` (the safe setting), which maintains existing behaviour. * **Breaking changes** * Made `SkeletonGraphic.unscaledTime` parameter protected, use the new property `UnscaledTime` instead. 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 d29be7b9e..49d7a7977 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 @@ -60,7 +60,7 @@ namespace Spine.Unity.Editor { } public static void ReloadAllActiveSkeletonsEditMode () { - + if (!Preferences.reloadAfterPlayMode) return; if (EditorApplication.isPaused) return; if (EditorApplication.isPlaying) return; if (EditorApplication.isCompiling) return; 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 2ba3acf23..d4d7c86ca 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 @@ -118,6 +118,9 @@ namespace Spine.Unity.Editor { const string SHOW_HIERARCHY_ICONS_KEY = "SPINE_SHOW_HIERARCHY_ICONS"; public static bool showHierarchyIcons = SpinePreferences.DEFAULT_SHOW_HIERARCHY_ICONS; + const string RELOAD_AFTER_PLAYMODE_KEY = "SPINE_RELOAD_AFTER_PLAYMODE"; + public static bool reloadAfterPlayMode = SpinePreferences.DEFAULT_RELOAD_AFTER_PLAYMODE; + const string SET_TEXTUREIMPORTER_SETTINGS_KEY = "SPINE_SET_TEXTUREIMPORTER_SETTINGS"; public static bool setTextureImporterSettings = SpinePreferences.DEFAULT_SET_TEXTUREIMPORTER_SETTINGS; @@ -185,6 +188,7 @@ namespace Spine.Unity.Editor { defaultZSpacing = EditorPrefs.GetFloat(DEFAULT_ZSPACING_KEY, SpinePreferences.DEFAULT_DEFAULT_ZSPACING); defaultShader = EditorPrefs.GetString(DEFAULT_SHADER_KEY, SpinePreferences.DEFAULT_DEFAULT_SHADER); showHierarchyIcons = EditorPrefs.GetBool(SHOW_HIERARCHY_ICONS_KEY, SpinePreferences.DEFAULT_SHOW_HIERARCHY_ICONS); + reloadAfterPlayMode = EditorPrefs.GetBool(RELOAD_AFTER_PLAYMODE_KEY, SpinePreferences.DEFAULT_RELOAD_AFTER_PLAYMODE); setTextureImporterSettings = EditorPrefs.GetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, SpinePreferences.DEFAULT_SET_TEXTUREIMPORTER_SETTINGS); textureSettingsReference = EditorPrefs.GetString(TEXTURE_SETTINGS_REFERENCE_KEY, SpinePreferences.DEFAULT_TEXTURE_SETTINGS_REFERENCE); blendModeMaterialMultiply = EditorPrefs.GetString(BLEND_MODE_MATERIAL_MULTIPLY_KEY, ""); @@ -207,6 +211,7 @@ namespace Spine.Unity.Editor { newPreferences.defaultZSpacing = EditorPrefs.GetFloat(DEFAULT_ZSPACING_KEY, SpinePreferences.DEFAULT_DEFAULT_ZSPACING); newPreferences.defaultShader = EditorPrefs.GetString(DEFAULT_SHADER_KEY, SpinePreferences.DEFAULT_DEFAULT_SHADER); newPreferences.showHierarchyIcons = EditorPrefs.GetBool(SHOW_HIERARCHY_ICONS_KEY, SpinePreferences.DEFAULT_SHOW_HIERARCHY_ICONS); + newPreferences.reloadAfterPlayMode = EditorPrefs.GetBool(RELOAD_AFTER_PLAYMODE_KEY, SpinePreferences.DEFAULT_RELOAD_AFTER_PLAYMODE); newPreferences.setTextureImporterSettings = EditorPrefs.GetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, SpinePreferences.DEFAULT_SET_TEXTUREIMPORTER_SETTINGS); newPreferences.textureSettingsReference = EditorPrefs.GetString(TEXTURE_SETTINGS_REFERENCE_KEY, SpinePreferences.DEFAULT_TEXTURE_SETTINGS_REFERENCE); newPreferences.autoReloadSceneSkeletons = EditorPrefs.GetBool(AUTO_RELOAD_SCENESKELETONS_KEY, SpinePreferences.DEFAULT_AUTO_RELOAD_SCENESKELETONS); @@ -224,6 +229,7 @@ namespace Spine.Unity.Editor { EditorPrefs.SetFloat(DEFAULT_ZSPACING_KEY, preferences.defaultZSpacing); EditorPrefs.SetString(DEFAULT_SHADER_KEY, preferences.defaultShader); EditorPrefs.SetBool(SHOW_HIERARCHY_ICONS_KEY, preferences.showHierarchyIcons); + EditorPrefs.SetBool(RELOAD_AFTER_PLAYMODE_KEY, preferences.reloadAfterPlayMode); EditorPrefs.SetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, preferences.setTextureImporterSettings); EditorPrefs.SetString(TEXTURE_SETTINGS_REFERENCE_KEY, preferences.textureSettingsReference); EditorPrefs.SetBool(AUTO_RELOAD_SCENESKELETONS_KEY, preferences.autoReloadSceneSkeletons); @@ -253,6 +259,7 @@ namespace Spine.Unity.Editor { } 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.")); + BoolPrefsField(ref reloadAfterPlayMode, RELOAD_AFTER_PLAYMODE_KEY, new GUIContent("Reload SkeletonData after Play", "When enabled, the shared SkeletonData of all skeletons in the active scene is reloaded (from the .json or .skel.bytes file) after exiting play-mode. This may add undesired delays, but prevents (accidental) modifications to the shared SkeletonData during play-mode carrying over its effect into subsequent plays.")); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Auto-Import Settings", EditorStyles.boldLabel); 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 478d8ea03..94c2c0c8c 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 @@ -80,6 +80,9 @@ namespace Spine.Unity.Editor { internal const bool DEFAULT_SHOW_HIERARCHY_ICONS = true; public bool showHierarchyIcons = DEFAULT_SHOW_HIERARCHY_ICONS; + internal const bool DEFAULT_RELOAD_AFTER_PLAYMODE = true; + public bool reloadAfterPlayMode = DEFAULT_RELOAD_AFTER_PLAYMODE; + internal const bool DEFAULT_SET_TEXTUREIMPORTER_SETTINGS = true; public bool setTextureImporterSettings = DEFAULT_SET_TEXTUREIMPORTER_SETTINGS; @@ -258,6 +261,7 @@ namespace Spine.Unity.Editor { } 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 SkeletonData asset inspector are immediately reflected. This may be slow when your scenes have large numbers of SkeletonRenderers or SkeletonGraphic.")); + EditorGUILayout.PropertyField(settings.FindProperty("reloadAfterPlayMode"), new GUIContent("Reload SkeletonData after Play", "When enabled, the shared SkeletonData of all skeletons in the active scene is reloaded (from the .json or .skel.bytes file) after exiting play-mode. This may add undesired delays, but prevents (accidental) modifications to the shared SkeletonData during play-mode carrying over its effect into subsequent plays.")); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Auto-Import Settings", EditorStyles.boldLabel);