|
@@ -27,14 +27,37 @@
|
|
|
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
*****************************************************************************/
|
|
|
|
|
|
+//#define SPINE_ALLOW_UNSAFE // note: this define can be set via Edit - Preferences - Spine.
|
|
|
+
|
|
|
+#if UNITY_2021_2_OR_NEWER
|
|
|
+#define TEXT_ASSET_HAS_GET_DATA_BYTES
|
|
|
+#endif
|
|
|
+
|
|
|
+#if SPINE_ALLOW_UNSAFE && TEXT_ASSET_HAS_GET_DATA_BYTES
|
|
|
+#define UNSAFE_DIRECT_ACCESS_TEXT_ASSET_DATA
|
|
|
+#endif
|
|
|
+
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
+using Unity.Collections;
|
|
|
using UnityEngine;
|
|
|
-
|
|
|
using CompatibilityProblemInfo = Spine.Unity.SkeletonDataCompatibility.CompatibilityProblemInfo;
|
|
|
|
|
|
namespace Spine.Unity {
|
|
|
+#if UNSAFE_DIRECT_ACCESS_TEXT_ASSET_DATA
|
|
|
+ public static class TextAssetExtensions {
|
|
|
+ public static Stream GetStreamUnsafe (this TextAsset textAsset) {
|
|
|
+ NativeArray<byte> dataNativeArray = textAsset.GetData<byte>();
|
|
|
+ return dataNativeArray.GetUnmanagedMemoryStream();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static unsafe UnmanagedMemoryStream GetUnmanagedMemoryStream<T> (this NativeArray<T> nativeArray) where T : struct {
|
|
|
+ return new UnmanagedMemoryStream((byte*)global::Unity.Collections.LowLevel.Unsafe.
|
|
|
+ NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(nativeArray), nativeArray.Length);
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
|
|
|
[CreateAssetMenu(fileName = "New SkeletonDataAsset", menuName = "Spine/SkeletonData Asset")]
|
|
|
public class SkeletonDataAsset : ScriptableObject {
|
|
@@ -188,9 +211,13 @@ namespace Spine.Unity {
|
|
|
SkeletonData loadedSkeletonData = null;
|
|
|
|
|
|
try {
|
|
|
- if (hasBinaryExtension)
|
|
|
+ if (hasBinaryExtension) {
|
|
|
+#if UNSAFE_DIRECT_ACCESS_TEXT_ASSET_DATA
|
|
|
+ loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.GetStreamUnsafe(), attachmentLoader, skeletonDataScale);
|
|
|
+#else
|
|
|
loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.bytes, attachmentLoader, skeletonDataScale);
|
|
|
- else
|
|
|
+#endif
|
|
|
+ } else
|
|
|
loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.text, attachmentLoader, skeletonDataScale);
|
|
|
} catch (Exception ex) {
|
|
|
if (!quiet)
|
|
@@ -287,6 +314,13 @@ namespace Spine.Unity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ internal static SkeletonData ReadSkeletonData (Stream assetStream, AttachmentLoader attachmentLoader, float scale) {
|
|
|
+ SkeletonBinary binary = new SkeletonBinary(attachmentLoader) {
|
|
|
+ Scale = scale
|
|
|
+ };
|
|
|
+ return binary.ReadSkeletonData(assetStream);
|
|
|
+ }
|
|
|
+
|
|
|
internal static SkeletonData ReadSkeletonData (string text, AttachmentLoader attachmentLoader, float scale) {
|
|
|
StringReader input = new StringReader(text);
|
|
|
SkeletonJson json = new SkeletonJson(attachmentLoader) {
|