Skip to content

Commit

Permalink
[unity] On-demand loading: Fixed a bug of editor not always resetting…
Browse files Browse the repository at this point in the history
… textures when exiting play mode.
  • Loading branch information
HaraldCsaszar committed Nov 21, 2023
1 parent 97a03e0 commit 7eea8ce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Expand Up @@ -45,9 +45,18 @@ namespace Spine.Unity.Editor {
using PlaceholderMaterialMapping = AddressablesTextureLoader.PlaceholderMaterialMapping;
using PlaceholderTextureMapping = AddressablesTextureLoader.PlaceholderTextureMapping;

[InitializeOnLoad]
[CustomEditor(typeof(AddressablesTextureLoader)), CanEditMultipleObjects]
public class AddressablesTextureLoaderInspector : GenericTextureLoaderInspector {

// Note: This static ctor ensures the generic base class method RegisterPlayModeChangedCallbacks is
// definitely called via InitializeOnLoad. Otherwise problems arose where the base class static ctor code
// is not executed (related to being a generic class).
static AddressablesTextureLoaderInspector () {
// The call below is necessary, otherwise the static GenericTextureLoaderInspector ctor is not called.
GenericTextureLoaderInspector.RegisterPlayModeChangedCallbacks();
}

public class AddressablesMethodImplementations : StaticMethodImplementations {
public override string LoaderSuffix { get { return "_Addressable"; } }

Expand Down
Expand Up @@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.addressables",
"displayName": "Spine Addressables Extensions [Experimental]",
"description": "This experimental plugin provides integration of Addressables on-demand texture loading for the spine-unity runtime.\nPlease be sure to test this package first and create backups of your project before using.\n\nUsage: First declare your target Material textures as addressable. Then select the SpineAtlasAsset, right-click the SpineAtlasAsset Inspector heading and select 'Add Addressables Loader'. This generates an 'AddressableTextureLoader' asset providing configuration parameters and sets up low-resolution placeholder textures which are automatically assigned in a pre-build step when building your game executable.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime (via the spine-unity unitypackage), version 4.1.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)",
"version": "4.1.0-preview.2",
"version": "4.1.0-preview.3",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",
Expand Down
Expand Up @@ -71,9 +71,15 @@ public abstract class GenericOnDemandTextureLoaderInspector<TargetReference, Tex
/// Called via InitializeOnLoad attribute upon Editor startup or compilation.
/// </summary>
static GenericOnDemandTextureLoaderInspector () {
RegisterPlayModeChangedCallbacks();
}

public static void RegisterPlayModeChangedCallbacks () {
#if NEWPLAYMODECALLBACKS
EditorApplication.playModeStateChanged -= OnPlaymodeChanged;
EditorApplication.playModeStateChanged += OnPlaymodeChanged;
#else
EditorApplication.playmodeStateChanged -= OnPlaymodeChanged;
EditorApplication.playmodeStateChanged += OnPlaymodeChanged;
#endif
}
Expand Down
Expand Up @@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.on-demand-loading",
"displayName": "Spine On-Demand Loading Extensions [Experimental]",
"description": "This experimental plugin provides a generic basic implementation of on-demand texture loading for the spine-unity runtime. You might want to use the available com.esotericsoftware.spine.addressables package which depends on this package.\nPlease be sure to test this package first and create backups of your project before using.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime (via the spine-unity unitypackage), version 4.1.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)",
"version": "4.1.0-preview.2",
"version": "4.1.0-preview.3",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",
Expand Down

0 comments on commit 7eea8ce

Please sign in to comment.