mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Fixed remaining obsolete method calls in Editor project part. Uses new API to apply regions as texture sprite slices.
This commit is contained in:
parent
25c5962f11
commit
45f0e32262
@ -2,12 +2,20 @@
|
||||
"name": "spine-unity-editor",
|
||||
"references": [
|
||||
"spine-csharp",
|
||||
"spine-unity"
|
||||
"spine-unity",
|
||||
"Unity.2D.Sprite.Editor"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false
|
||||
"allowUnsafeCode": false,
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.2d.sprite",
|
||||
"expression": "1.0.0",
|
||||
"define": "TEXTUREIMPORTER_SPRITESHEET_OBSOLETE"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -27,9 +27,22 @@
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#if UNITY_6000_3_OR_NEWER
|
||||
#define GET_ASSET_PATH_USES_ENTITY_ID
|
||||
#endif
|
||||
|
||||
//#if UNITY_2022_2_OR_NEWER
|
||||
// note: defined by spine-unity-editor.asmdef file when package is actually found
|
||||
//#define TEXTUREIMPORTER_SPRITESHEET_OBSOLETE
|
||||
//#endif
|
||||
|
||||
//#define BAKE_ALL_BUTTON
|
||||
//#define REGION_BAKING_MESH
|
||||
|
||||
#if TEXTUREIMPORTER_SPRITESHEET_OBSOLETE
|
||||
using UnityEditor.U2D.Sprites;
|
||||
#endif
|
||||
|
||||
using Spine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -39,6 +52,11 @@ using UnityEngine;
|
||||
|
||||
namespace Spine.Unity.Editor {
|
||||
using Event = UnityEngine.Event;
|
||||
#if TEXTUREIMPORTER_SPRITESHEET_OBSOLETE
|
||||
using SpriteDataType = SpriteRect;
|
||||
#else
|
||||
using SpriteDataType = SpriteMetaData;
|
||||
#endif
|
||||
|
||||
[CustomEditor(typeof(SpineAtlasAsset)), CanEditMultipleObjects]
|
||||
public class SpineAtlasAssetInspector : UnityEditor.Editor {
|
||||
@ -142,12 +160,16 @@ namespace Spine.Unity.Editor {
|
||||
EditorGUILayout.PropertyField(textureLoadingMode);
|
||||
EditorGUILayout.PropertyField(onDemandTextureLoader);
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.Space();
|
||||
if (SpineInspectorUtility.LargeCenteredButton(SpineInspectorUtility.TempContent("Set Mipmap Bias to " + SpinePreferences.DEFAULT_MIPMAPBIAS, tooltip: "This may help textures with mipmaps be less blurry when used for 2D sprites."))) {
|
||||
foreach (Material m in atlasAsset.materials) {
|
||||
Texture texture = m.mainTexture;
|
||||
#if GET_ASSET_PATH_USES_ENTITY_ID
|
||||
string texturePath = AssetDatabase.GetAssetPath(texture.GetEntityId());
|
||||
#else
|
||||
string texturePath = AssetDatabase.GetAssetPath(texture.GetInstanceID());
|
||||
#endif
|
||||
TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(texturePath);
|
||||
importer.mipMapBias = SpinePreferences.DEFAULT_MIPMAPBIAS;
|
||||
EditorUtility.SetDirty(texture);
|
||||
@ -324,11 +346,26 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
static public void UpdateSpriteSlices (Texture texture, Atlas atlas) {
|
||||
#if GET_ASSET_PATH_USES_ENTITY_ID
|
||||
string texturePath = AssetDatabase.GetAssetPath(texture.GetEntityId());
|
||||
#else
|
||||
string texturePath = AssetDatabase.GetAssetPath(texture.GetInstanceID());
|
||||
#endif
|
||||
TextureImporter t = (TextureImporter)TextureImporter.GetAtPath(texturePath);
|
||||
t.spriteImportMode = SpriteImportMode.Multiple;
|
||||
#if TEXTUREIMPORTER_SPRITESHEET_OBSOLETE
|
||||
SpriteDataProviderFactories factory = new SpriteDataProviderFactories();
|
||||
factory.Init();
|
||||
ISpriteEditorDataProvider dataProvider = factory.GetSpriteEditorDataProviderFromObject(t);
|
||||
dataProvider.InitSpriteEditorDataProvider();
|
||||
|
||||
// Read existing sprite rects
|
||||
SpriteRect[] spriteRects = dataProvider.GetSpriteRects();
|
||||
List<SpriteRect> sprites = new List<SpriteRect>(spriteRects);
|
||||
#else
|
||||
SpriteMetaData[] spriteSheet = t.spritesheet;
|
||||
List<SpriteMetaData> sprites = new List<SpriteMetaData>(spriteSheet);
|
||||
#endif
|
||||
|
||||
List<AtlasRegion> regions = SpineAtlasAssetInspector.GetRegions(atlas);
|
||||
int updatedCount = 0;
|
||||
@ -366,12 +403,12 @@ namespace Spine.Unity.Editor {
|
||||
spriteRect.y = r.page.height - spriteRect.height - r.y;
|
||||
|
||||
if (spriteNameMatchExists) {
|
||||
SpriteMetaData s = sprites[spriteIndex];
|
||||
SpriteDataType s = sprites[spriteIndex];
|
||||
s.rect = spriteRect;
|
||||
sprites[spriteIndex] = s;
|
||||
updatedCount++;
|
||||
} else {
|
||||
sprites.Add(new SpriteMetaData {
|
||||
sprites.Add(new SpriteDataType {
|
||||
name = r.name,
|
||||
pivot = new Vector2(0.5f, 0.5f),
|
||||
rect = spriteRect
|
||||
@ -381,8 +418,12 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if TEXTUREIMPORTER_SPRITESHEET_OBSOLETE
|
||||
dataProvider.SetSpriteRects(spriteRects);
|
||||
dataProvider.Apply();
|
||||
#else
|
||||
t.spritesheet = sprites.ToArray();
|
||||
#endif
|
||||
EditorUtility.SetDirty(t);
|
||||
AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);
|
||||
EditorGUIUtility.PingObject(texture);
|
||||
|
||||
@ -31,6 +31,10 @@
|
||||
#define NEW_PREFAB_SYSTEM
|
||||
#endif
|
||||
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
#define USE_COLLIDER_COMPOSITE_OPERATION
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
@ -136,7 +140,12 @@ namespace Spine.Unity.Editor {
|
||||
foreach (PolygonCollider2D col in follower.colliderTable.Values) {
|
||||
col.isTrigger = isTrigger.boolValue;
|
||||
col.usedByEffector = usedByEffector.boolValue;
|
||||
#if USE_COLLIDER_COMPOSITE_OPERATION
|
||||
col.compositeOperation = usedByComposite.boolValue ?
|
||||
Collider2D.CompositeOperation.Merge : Collider2D.CompositeOperation.None;
|
||||
#else
|
||||
col.usedByComposite = usedByComposite.boolValue;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,10 @@
|
||||
#define NEW_PREFAB_SYSTEM
|
||||
#endif
|
||||
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
#define USE_COLLIDER_COMPOSITE_OPERATION
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
@ -136,7 +140,12 @@ namespace Spine.Unity.Editor {
|
||||
foreach (PolygonCollider2D col in follower.colliderTable.Values) {
|
||||
col.isTrigger = isTrigger.boolValue;
|
||||
col.usedByEffector = usedByEffector.boolValue;
|
||||
#if USE_COLLIDER_COMPOSITE_OPERATION
|
||||
col.compositeOperation = usedByComposite.boolValue ?
|
||||
Collider2D.CompositeOperation.Merge : Collider2D.CompositeOperation.None;
|
||||
#else
|
||||
col.usedByComposite = usedByComposite.boolValue;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -201,7 +210,7 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
}
|
||||
|
||||
#region Menus
|
||||
#region Menus
|
||||
[MenuItem("CONTEXT/SkeletonRenderer/Add BoundingBoxFollower GameObject")]
|
||||
static void AddBoundingBoxFollowerChild (MenuCommand command) {
|
||||
GameObject go = AddBoundingBoxFollowerChild((SkeletonRenderer)command.context);
|
||||
@ -214,7 +223,7 @@ namespace Spine.Unity.Editor {
|
||||
foreach (GameObject go in objects)
|
||||
Undo.RegisterCreatedObjectUndo(go, "Add BoundingBoxFollower");
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
public static GameObject AddBoundingBoxFollowerChild (SkeletonRenderer skeletonRenderer,
|
||||
BoundingBoxFollower original = null, string name = "BoundingBoxFollower",
|
||||
|
||||
@ -33,6 +33,10 @@
|
||||
#define HINGE_JOINT_NEW_BEHAVIOUR
|
||||
#endif
|
||||
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
#define USE_RIGIDBODY_BODY_TYPE
|
||||
#endif
|
||||
|
||||
using Spine;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
@ -338,7 +342,11 @@ namespace Spine.Unity.Editor {
|
||||
rootFollowerKinematic.transform.parent = normalChainParentObject.transform;
|
||||
Rigidbody2D followerRigidbody = rootFollowerKinematic.AddComponent<Rigidbody2D>();
|
||||
followerRigidbody.mass = mass;
|
||||
#if USE_RIGIDBODY_BODY_TYPE
|
||||
followerRigidbody.bodyType = RigidbodyType2D.Kinematic;
|
||||
#else
|
||||
followerRigidbody.isKinematic = true;
|
||||
#endif
|
||||
rootFollowerKinematic.AddComponent<FollowLocationRigidbody2D>().reference = kinematicParentUtilityBone.transform;
|
||||
rootFollowerKinematic.transform.position = kinematicParentUtilityBone.transform.position;
|
||||
rootFollowerKinematic.transform.rotation = kinematicParentUtilityBone.transform.rotation;
|
||||
|
||||
@ -63,6 +63,10 @@
|
||||
#define HAS_CULL_TRANSPARENT_MESH
|
||||
#endif
|
||||
|
||||
#if UNITY_6000_3_OR_NEWER
|
||||
#define USES_ENTITY_ID
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -605,7 +609,11 @@ namespace Spine.Unity.Editor {
|
||||
skeletonDataAtlasAssets[i].Equals(null) &&
|
||||
skeletonDataAtlasAssets[i].GetInstanceID() != 0
|
||||
) {
|
||||
#if USES_ENTITY_ID
|
||||
skeletonDataAtlasAssets[i] = EditorUtility.EntityIdToObject(skeletonDataAtlasAssets[i].GetEntityId()) as AtlasAssetBase;
|
||||
#else
|
||||
skeletonDataAtlasAssets[i] = EditorUtility.InstanceIDToObject(skeletonDataAtlasAssets[i].GetInstanceID()) as AtlasAssetBase;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,14 +35,18 @@
|
||||
#define NEWPLAYMODECALLBACKS
|
||||
#endif
|
||||
|
||||
#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
#define NEW_PREFAB_SYSTEM
|
||||
#endif
|
||||
|
||||
#if UNITY_2018 || UNITY_2019 || UNITY_2018_3_OR_NEWER
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
#define NEWHIERARCHYWINDOWCALLBACKS
|
||||
#endif
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
#define USES_NAMED_BUILD_TARGETS
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@ -91,35 +95,45 @@ namespace Spine.Unity.Editor {
|
||||
static bool IsInvalidGroup (BuildTargetGroup group) {
|
||||
int gi = (int)group;
|
||||
return
|
||||
gi == 15 || gi == 16
|
||||
||
|
||||
group == BuildTargetGroup.Unknown;
|
||||
gi == 15 || gi == 16 || group == BuildTargetGroup.Unknown;
|
||||
}
|
||||
|
||||
public static bool EnableBuildDefine (string define) {
|
||||
|
||||
bool wasDefineAdded = false;
|
||||
|
||||
#if !USES_NAMED_BUILD_TARGETS
|
||||
Debug.LogWarning("Please ignore errors \"PlayerSettings Validation: Requested build target group doesn't exist\" below");
|
||||
#endif
|
||||
foreach (BuildTargetGroup group in System.Enum.GetValues(typeof(BuildTargetGroup))) {
|
||||
if (IsInvalidGroup(group))
|
||||
continue;
|
||||
|
||||
try {
|
||||
#if USES_NAMED_BUILD_TARGETS
|
||||
var target = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(group);
|
||||
string defines = PlayerSettings.GetScriptingDefineSymbols(target);
|
||||
#else
|
||||
string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
|
||||
#endif
|
||||
if (!defines.Contains(define)) {
|
||||
wasDefineAdded = true;
|
||||
if (defines.EndsWith(";", System.StringComparison.Ordinal))
|
||||
defines += define;
|
||||
else
|
||||
defines += ";" + define;
|
||||
|
||||
#if USES_NAMED_BUILD_TARGETS
|
||||
PlayerSettings.SetScriptingDefineSymbols(target, defines);
|
||||
#else
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(group, defines);
|
||||
#endif
|
||||
}
|
||||
} catch (System.Exception) {
|
||||
}
|
||||
}
|
||||
#if !USES_NAMED_BUILD_TARGETS
|
||||
Debug.LogWarning("Please ignore errors \"PlayerSettings Validation: Requested build target group doesn't exist\" above");
|
||||
|
||||
#endif
|
||||
if (wasDefineAdded) {
|
||||
Debug.LogWarning("Setting Scripting Define Symbol " + define);
|
||||
} else {
|
||||
@ -136,15 +150,23 @@ namespace Spine.Unity.Editor {
|
||||
continue;
|
||||
|
||||
try {
|
||||
#if USES_NAMED_BUILD_TARGETS
|
||||
var target = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(group);
|
||||
string defines = PlayerSettings.GetScriptingDefineSymbols(target);
|
||||
#else
|
||||
string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
|
||||
#endif
|
||||
if (defines.Contains(define)) {
|
||||
wasDefineRemoved = true;
|
||||
if (defines.Contains(define + ";"))
|
||||
defines = defines.Replace(define + ";", "");
|
||||
else
|
||||
defines = defines.Replace(define, "");
|
||||
|
||||
#if USES_NAMED_BUILD_TARGETS
|
||||
PlayerSettings.SetScriptingDefineSymbols(target, defines);
|
||||
#else
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(group, defines);
|
||||
#endif
|
||||
}
|
||||
} catch (System.Exception) {
|
||||
}
|
||||
|
||||
@ -35,6 +35,10 @@
|
||||
#define NEWPLAYMODECALLBACKS
|
||||
#endif
|
||||
|
||||
#if UNITY_2022_2_OR_NEWER
|
||||
#define USE_FIND_OBJECTS_BY_TYPE
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@ -68,7 +72,11 @@ namespace Spine.Unity.Editor {
|
||||
|
||||
HashSet<SkeletonDataAsset> skeletonDataAssetsToReload = new HashSet<SkeletonDataAsset>();
|
||||
|
||||
#if USE_FIND_OBJECTS_BY_TYPE
|
||||
SkeletonRenderer[] activeSkeletonRenderers = GameObject.FindObjectsByType<SkeletonRenderer>(FindObjectsSortMode.None);
|
||||
#else
|
||||
SkeletonRenderer[] activeSkeletonRenderers = GameObject.FindObjectsOfType<SkeletonRenderer>();
|
||||
#endif
|
||||
foreach (SkeletonRenderer sr in activeSkeletonRenderers) {
|
||||
SkeletonDataAsset skeletonDataAsset = sr.skeletonDataAsset;
|
||||
if (skeletonDataAsset != null) skeletonDataAssetsToReload.Add(skeletonDataAsset);
|
||||
@ -79,7 +87,11 @@ namespace Spine.Unity.Editor {
|
||||
// by the instance of the ScriptableObject being destroyed but still assigned.
|
||||
// Here we save the skeletonGraphic.skeletonDataAsset asset path in order
|
||||
// to restore it later.
|
||||
#if USE_FIND_OBJECTS_BY_TYPE
|
||||
SkeletonGraphic[] activeSkeletonGraphics = GameObject.FindObjectsByType<SkeletonGraphic>(FindObjectsSortMode.None);
|
||||
#else
|
||||
SkeletonGraphic[] activeSkeletonGraphics = GameObject.FindObjectsOfType<SkeletonGraphic>();
|
||||
#endif
|
||||
foreach (SkeletonGraphic skeletonGraphic in activeSkeletonGraphics) {
|
||||
SkeletonDataAsset skeletonDataAsset = skeletonGraphic.skeletonDataAsset;
|
||||
if (skeletonDataAsset != null) {
|
||||
@ -106,12 +118,20 @@ namespace Spine.Unity.Editor {
|
||||
if (EditorApplication.isCompiling) return;
|
||||
if (EditorApplication.isPlayingOrWillChangePlaymode) return;
|
||||
|
||||
#if USE_FIND_OBJECTS_BY_TYPE
|
||||
SkeletonRenderer[] activeSkeletonRenderers = GameObject.FindObjectsByType<SkeletonRenderer>(FindObjectsSortMode.None);
|
||||
#else
|
||||
SkeletonRenderer[] activeSkeletonRenderers = GameObject.FindObjectsOfType<SkeletonRenderer>();
|
||||
#endif
|
||||
foreach (SkeletonRenderer renderer in activeSkeletonRenderers) {
|
||||
if (renderer.isActiveAndEnabled && renderer.skeletonDataAsset == skeletonDataAsset) renderer.Initialize(true);
|
||||
}
|
||||
|
||||
#if USE_FIND_OBJECTS_BY_TYPE
|
||||
SkeletonGraphic[] activeSkeletonGraphics = GameObject.FindObjectsByType<SkeletonGraphic>(FindObjectsSortMode.None);
|
||||
#else
|
||||
SkeletonGraphic[] activeSkeletonGraphics = GameObject.FindObjectsOfType<SkeletonGraphic>();
|
||||
#endif
|
||||
foreach (SkeletonGraphic graphic in activeSkeletonGraphics) {
|
||||
if (graphic.isActiveAndEnabled && graphic.skeletonDataAsset == skeletonDataAsset)
|
||||
graphic.Initialize(true);
|
||||
|
||||
@ -39,6 +39,10 @@
|
||||
#define NEWPLAYMODECALLBACKS
|
||||
#endif
|
||||
|
||||
#if UNITY_6000_3_OR_NEWER
|
||||
#define GET_ASSET_PATH_USES_ENTITY_ID
|
||||
#endif
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@ -104,7 +108,11 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
public static bool IsSkeletonTexturePMA (Texture texture, string skeletonName, out bool detectionSucceeded) {
|
||||
#if GET_ASSET_PATH_USES_ENTITY_ID
|
||||
string texturePath = AssetDatabase.GetAssetPath(texture.GetEntityId());
|
||||
#else
|
||||
string texturePath = AssetDatabase.GetAssetPath(texture.GetInstanceID());
|
||||
#endif
|
||||
TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(texturePath);
|
||||
if (importer.alphaIsTransparency != importer.sRGBTexture) {
|
||||
Debug.LogWarning(string.Format("Texture '{0}' at skeleton '{1}' is neither configured correctly for " +
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"name": "com.esotericsoftware.spine.spine-unity",
|
||||
"displayName": "spine-unity Runtime",
|
||||
"description": "This plugin provides the spine-unity runtime core and examples. Spine Examples can be installed via the Samples tab.",
|
||||
"version": "4.3.46",
|
||||
"version": "4.3.47",
|
||||
"unity": "2018.3",
|
||||
"author": {
|
||||
"name": "Esoteric Software",
|
||||
@ -14,7 +14,8 @@
|
||||
"com.unity.modules.animation" : "1.0.0",
|
||||
"com.unity.modules.physics" : "1.0.0",
|
||||
"com.unity.modules.physics2d" : "1.0.0",
|
||||
"com.esotericsoftware.spine.spine-csharp": "4.3.0"
|
||||
"com.esotericsoftware.spine.spine-csharp": "4.3.0",
|
||||
"com.unity.2d.sprite": "1.0.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user