mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 01:06:00 +08:00
[ue] Remove PostLoadAssetRegistryTags usage for compatibility with UE 4.27
This commit is contained in:
parent
b9b9a836e0
commit
f540dd4985
@ -73,7 +73,7 @@ int main(void) {
|
|||||||
String atlasFile("/Users/badlogic/Desktop/basemodel-male/basemodel-male.atlas");
|
String atlasFile("/Users/badlogic/Desktop/basemodel-male/basemodel-male.atlas");
|
||||||
String skeletonFile("/Users/badlogic/Desktop/basemodel-male/basemodel-male.skel");
|
String skeletonFile("/Users/badlogic/Desktop/basemodel-male/basemodel-male.skel");
|
||||||
String animation = "";
|
String animation = "";
|
||||||
String skin = "BasicBody";
|
String skin = "BasicBody";
|
||||||
|
|
||||||
float scale = 0.1f;
|
float scale = 0.1f;
|
||||||
SFMLTextureLoader textureLoader;
|
SFMLTextureLoader textureLoader;
|
||||||
@ -104,10 +104,10 @@ int main(void) {
|
|||||||
|
|
||||||
AnimationStateData stateData(skeletonData);
|
AnimationStateData stateData(skeletonData);
|
||||||
SkeletonDrawable drawable(skeletonData, &stateData);
|
SkeletonDrawable drawable(skeletonData, &stateData);
|
||||||
drawable.skeleton->updateWorldTransform();
|
drawable.skeleton->updateWorldTransform();
|
||||||
drawable.skeleton->setPosition(320, 590);
|
drawable.skeleton->setPosition(320, 590);
|
||||||
if (animation.length() > 0) drawable.state->setAnimation(0, animation, true);
|
if (animation.length() > 0) drawable.state->setAnimation(0, animation, true);
|
||||||
if (skin.length() > 0) drawable.skeleton->setSkin(skin);
|
if (skin.length() > 0) drawable.skeleton->setSkin(skin);
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - testbed");
|
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - testbed");
|
||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(60);
|
||||||
|
|||||||
@ -44,38 +44,32 @@ void USpineAtlasAsset::SetAtlasFileName(const FName &AtlasFileName) {
|
|||||||
importData->UpdateFilenameOnly(AtlasFileName.ToString());
|
importData->UpdateFilenameOnly(AtlasFileName.ToString());
|
||||||
TArray<FString> files;
|
TArray<FString> files;
|
||||||
importData->ExtractFilenames(files);
|
importData->ExtractFilenames(files);
|
||||||
if (files.Num() > 0) atlasFileName = FName(*files[0]);
|
if (files.Num() > 0)
|
||||||
|
atlasFileName = FName(*files[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void USpineAtlasAsset::PostInitProperties() {
|
void USpineAtlasAsset::PostInitProperties() {
|
||||||
if (!HasAnyFlags(RF_ClassDefaultObject)) importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
if (!HasAnyFlags(RF_ClassDefaultObject))
|
||||||
|
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||||
Super::PostInitProperties();
|
Super::PostInitProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
void USpineAtlasAsset::Serialize(FArchive &Ar) {
|
void USpineAtlasAsset::Serialize(FArchive &Ar) {
|
||||||
Super::Serialize(Ar);
|
Super::Serialize(Ar);
|
||||||
if (Ar.IsLoading() && Ar.UE4Ver() < VER_UE4_ASSET_IMPORT_DATA_AS_JSON && !importData)
|
if (Ar.IsLoading() && Ar.UE4Ver() < VER_UE4_ASSET_IMPORT_DATA_AS_JSON &&
|
||||||
|
!importData)
|
||||||
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void USpineAtlasAsset::PostLoadAssetRegistryTags(const FAssetData &InAssetData,
|
|
||||||
TArray<FAssetRegistryTag> &OutTagsAndValuesToUpdate) const {
|
|
||||||
// FIXME: this is a massive hack. It will set the PackageFlags of the FAssetData
|
|
||||||
// in the AssetRegistry to PKG_FilterEditorOnly so the content browser displays it.
|
|
||||||
// This is necessary in UE 5.3 due to a regression in ContentBrowserAssetDataCore::IsPrimaryAsset
|
|
||||||
// See https://github.com/EsotericSoftware/spine-runtimes/issues/2368
|
|
||||||
FAssetData &MutableAssetData = const_cast<FAssetData &>(InAssetData);
|
|
||||||
// MutableAssetData.PackageFlags = EPackageFlags::PKG_FilterEditorOnly;
|
|
||||||
UObject::PostLoadAssetRegistryTags(MutableAssetData, OutTagsAndValuesToUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FName USpineAtlasAsset::GetAtlasFileName() const {
|
FName USpineAtlasAsset::GetAtlasFileName() const {
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
TArray<FString> files;
|
TArray<FString> files;
|
||||||
if (importData) importData->ExtractFilenames(files);
|
if (importData)
|
||||||
if (files.Num() > 0) return FName(*files[0]);
|
importData->ExtractFilenames(files);
|
||||||
|
if (files.Num() > 0)
|
||||||
|
return FName(*files[0]);
|
||||||
else
|
else
|
||||||
return atlasFileName;
|
return atlasFileName;
|
||||||
#else
|
#else
|
||||||
@ -107,7 +101,8 @@ Atlas *USpineAtlasAsset::GetAtlas() {
|
|||||||
}
|
}
|
||||||
std::string t = TCHAR_TO_UTF8(*rawData);
|
std::string t = TCHAR_TO_UTF8(*rawData);
|
||||||
|
|
||||||
atlas = new (__FILE__, __LINE__) Atlas(t.c_str(), strlen(t.c_str()), "", nullptr);
|
atlas = new (__FILE__, __LINE__)
|
||||||
|
Atlas(t.c_str(), strlen(t.c_str()), "", nullptr);
|
||||||
Vector<AtlasPage *> &pages = atlas->getPages();
|
Vector<AtlasPage *> &pages = atlas->getPages();
|
||||||
for (size_t i = 0, n = pages.size(), j = 0; i < n; i++) {
|
for (size_t i = 0, n = pages.size(), j = 0; i < n; i++) {
|
||||||
AtlasPage *page = pages[i];
|
AtlasPage *page = pages[i];
|
||||||
|
|||||||
@ -28,11 +28,11 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "SpineSkeletonDataAsset.h"
|
#include "SpineSkeletonDataAsset.h"
|
||||||
#include "SpinePlugin.h"
|
|
||||||
#include "Runtime/Core/Public/Misc/MessageDialog.h"
|
|
||||||
#include "EditorFramework/AssetImportData.h"
|
#include "EditorFramework/AssetImportData.h"
|
||||||
#include "spine/spine.h"
|
#include "Runtime/Core/Public/Misc/MessageDialog.h"
|
||||||
|
#include "SpinePlugin.h"
|
||||||
#include "spine/Version.h"
|
#include "spine/Version.h"
|
||||||
|
#include "spine/spine.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define LOCTEXT_NAMESPACE "Spine"
|
#define LOCTEXT_NAMESPACE "Spine"
|
||||||
@ -42,8 +42,10 @@ using namespace spine;
|
|||||||
FName USpineSkeletonDataAsset::GetSkeletonDataFileName() const {
|
FName USpineSkeletonDataAsset::GetSkeletonDataFileName() const {
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
TArray<FString> files;
|
TArray<FString> files;
|
||||||
if (importData) importData->ExtractFilenames(files);
|
if (importData)
|
||||||
if (files.Num() > 0) return FName(*files[0]);
|
importData->ExtractFilenames(files);
|
||||||
|
if (files.Num() > 0)
|
||||||
|
return FName(*files[0]);
|
||||||
else
|
else
|
||||||
return skeletonDataFileName;
|
return skeletonDataFileName;
|
||||||
#else
|
#else
|
||||||
@ -53,21 +55,27 @@ FName USpineSkeletonDataAsset::GetSkeletonDataFileName() const {
|
|||||||
|
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
|
|
||||||
void USpineSkeletonDataAsset::SetSkeletonDataFileName(const FName &SkeletonDataFileName) {
|
void USpineSkeletonDataAsset::SetSkeletonDataFileName(
|
||||||
|
const FName &SkeletonDataFileName) {
|
||||||
importData->UpdateFilenameOnly(SkeletonDataFileName.ToString());
|
importData->UpdateFilenameOnly(SkeletonDataFileName.ToString());
|
||||||
TArray<FString> files;
|
TArray<FString> files;
|
||||||
importData->ExtractFilenames(files);
|
importData->ExtractFilenames(files);
|
||||||
if (files.Num() > 0) this->skeletonDataFileName = FName(*files[0]);
|
if (files.Num() > 0)
|
||||||
|
this->skeletonDataFileName = FName(*files[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void USpineSkeletonDataAsset::PostInitProperties() {
|
void USpineSkeletonDataAsset::PostInitProperties() {
|
||||||
if (!HasAnyFlags(RF_ClassDefaultObject)) importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
if (!HasAnyFlags(RF_ClassDefaultObject))
|
||||||
|
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||||
Super::PostInitProperties();
|
Super::PostInitProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
void USpineSkeletonDataAsset::GetAssetRegistryTags(TArray<FAssetRegistryTag> &OutTags) const {
|
void USpineSkeletonDataAsset::GetAssetRegistryTags(
|
||||||
|
TArray<FAssetRegistryTag> &OutTags) const {
|
||||||
if (importData) {
|
if (importData) {
|
||||||
OutTags.Add(FAssetRegistryTag(SourceFileTagName(), importData->GetSourceData().ToJson(), FAssetRegistryTag::TT_Hidden));
|
OutTags.Add(FAssetRegistryTag(SourceFileTagName(),
|
||||||
|
importData->GetSourceData().ToJson(),
|
||||||
|
FAssetRegistryTag::TT_Hidden));
|
||||||
}
|
}
|
||||||
|
|
||||||
Super::GetAssetRegistryTags(OutTags);
|
Super::GetAssetRegistryTags(OutTags);
|
||||||
@ -75,29 +83,20 @@ void USpineSkeletonDataAsset::GetAssetRegistryTags(TArray<FAssetRegistryTag> &Ou
|
|||||||
|
|
||||||
void USpineSkeletonDataAsset::Serialize(FArchive &Ar) {
|
void USpineSkeletonDataAsset::Serialize(FArchive &Ar) {
|
||||||
Super::Serialize(Ar);
|
Super::Serialize(Ar);
|
||||||
if (Ar.IsLoading() && Ar.UE4Ver() < VER_UE4_ASSET_IMPORT_DATA_AS_JSON && !importData)
|
if (Ar.IsLoading() && Ar.UE4Ver() < VER_UE4_ASSET_IMPORT_DATA_AS_JSON &&
|
||||||
|
!importData)
|
||||||
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||||
LoadInfo();
|
LoadInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void USpineSkeletonDataAsset::PostLoadAssetRegistryTags(const FAssetData &InAssetData,
|
|
||||||
// FIXME: this is a massive hack. It will set the PackageFlags of the FAssetData
|
|
||||||
// in the AssetRegistry to PKG_FilterEditorOnly so the content browser displays it.
|
|
||||||
// This is necessary in UE 5.3 due to a regression in ContentBrowserAssetDataCore::IsPrimaryAsset
|
|
||||||
// See https://github.com/EsotericSoftware/spine-runtimes/issues/2368
|
|
||||||
TArray<FAssetRegistryTag> &OutTagsAndValuesToUpdate) const {
|
|
||||||
FAssetData &MutableAssetData = const_cast<FAssetData &>(InAssetData);
|
|
||||||
// MutableAssetData.PackageFlags = EPackageFlags::PKG_FilterEditorOnly;
|
|
||||||
UObject::PostLoadAssetRegistryTags(MutableAssetData, OutTagsAndValuesToUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void USpineSkeletonDataAsset::ClearNativeData() {
|
void USpineSkeletonDataAsset::ClearNativeData() {
|
||||||
for (auto &pair : atlasToNativeData) {
|
for (auto &pair : atlasToNativeData) {
|
||||||
if (pair.Value.skeletonData) delete pair.Value.skeletonData;
|
if (pair.Value.skeletonData)
|
||||||
if (pair.Value.animationStateData) delete pair.Value.animationStateData;
|
delete pair.Value.skeletonData;
|
||||||
|
if (pair.Value.animationStateData)
|
||||||
|
delete pair.Value.animationStateData;
|
||||||
}
|
}
|
||||||
atlasToNativeData.Empty();
|
atlasToNativeData.Empty();
|
||||||
}
|
}
|
||||||
@ -110,15 +109,20 @@ void USpineSkeletonDataAsset::BeginDestroy() {
|
|||||||
|
|
||||||
class SP_API NullAttachmentLoader : public AttachmentLoader {
|
class SP_API NullAttachmentLoader : public AttachmentLoader {
|
||||||
public:
|
public:
|
||||||
virtual RegionAttachment *newRegionAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence) {
|
virtual RegionAttachment *newRegionAttachment(Skin &skin, const String &name,
|
||||||
|
const String &path,
|
||||||
|
Sequence *sequence) {
|
||||||
return new (__FILE__, __LINE__) RegionAttachment(name);
|
return new (__FILE__, __LINE__) RegionAttachment(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual MeshAttachment *newMeshAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence) {
|
virtual MeshAttachment *newMeshAttachment(Skin &skin, const String &name,
|
||||||
|
const String &path,
|
||||||
|
Sequence *sequence) {
|
||||||
return new (__FILE__, __LINE__) MeshAttachment(name);
|
return new (__FILE__, __LINE__) MeshAttachment(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual BoundingBoxAttachment *newBoundingBoxAttachment(Skin &skin, const String &name) {
|
virtual BoundingBoxAttachment *newBoundingBoxAttachment(Skin &skin,
|
||||||
|
const String &name) {
|
||||||
return new (__FILE__, __LINE__) BoundingBoxAttachment(name);
|
return new (__FILE__, __LINE__) BoundingBoxAttachment(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,12 +134,12 @@ public:
|
|||||||
return new (__FILE__, __LINE__) PointAttachment(name);
|
return new (__FILE__, __LINE__) PointAttachment(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ClippingAttachment *newClippingAttachment(Skin &skin, const String &name) {
|
virtual ClippingAttachment *newClippingAttachment(Skin &skin,
|
||||||
|
const String &name) {
|
||||||
return new (__FILE__, __LINE__) ClippingAttachment(name);
|
return new (__FILE__, __LINE__) ClippingAttachment(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void configureAttachment(Attachment *attachment) {
|
virtual void configureAttachment(Attachment *attachment) {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void USpineSkeletonDataAsset::SetRawData(TArray<uint8> &Data) {
|
void USpineSkeletonDataAsset::SetRawData(TArray<uint8> &Data) {
|
||||||
@ -148,7 +152,8 @@ void USpineSkeletonDataAsset::SetRawData(TArray<uint8> &Data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool checkVersion(const char *version) {
|
static bool checkVersion(const char *version) {
|
||||||
if (!version) return false;
|
if (!version)
|
||||||
|
return false;
|
||||||
char *result = (char *) (strstr(version, SPINE_VERSION_STRING) - version);
|
char *result = (char *) (strstr(version, SPINE_VERSION_STRING) - version);
|
||||||
return result == 0;
|
return result == 0;
|
||||||
}
|
}
|
||||||
@ -156,9 +161,11 @@ static bool checkVersion(const char *version) {
|
|||||||
static bool checkJson(const char *jsonData) {
|
static bool checkJson(const char *jsonData) {
|
||||||
Json json(jsonData);
|
Json json(jsonData);
|
||||||
Json *skeleton = Json::getItem(&json, "skeleton");
|
Json *skeleton = Json::getItem(&json, "skeleton");
|
||||||
if (!skeleton) return false;
|
if (!skeleton)
|
||||||
|
return false;
|
||||||
const char *version = Json::getString(skeleton, "spine", 0);
|
const char *version = Json::getString(skeleton, "spine", 0);
|
||||||
if (!version) return false;
|
if (!version)
|
||||||
|
return false;
|
||||||
|
|
||||||
return checkVersion(version);
|
return checkVersion(version);
|
||||||
}
|
}
|
||||||
@ -168,9 +175,7 @@ struct BinaryInput {
|
|||||||
const unsigned char *end;
|
const unsigned char *end;
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned char readByte(BinaryInput *input) {
|
static unsigned char readByte(BinaryInput *input) { return *input->cursor++; }
|
||||||
return *input->cursor++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int readVarint(BinaryInput *input, bool optimizePositive) {
|
static int readVarint(BinaryInput *input, bool optimizePositive) {
|
||||||
unsigned char b = readByte(input);
|
unsigned char b = readByte(input);
|
||||||
@ -184,7 +189,8 @@ static int readVarint(BinaryInput *input, bool optimizePositive) {
|
|||||||
if (b & 0x80) {
|
if (b & 0x80) {
|
||||||
b = readByte(input);
|
b = readByte(input);
|
||||||
value |= (b & 0x7F) << 21;
|
value |= (b & 0x7F) << 21;
|
||||||
if (b & 0x80) value |= (readByte(input) & 0x7F) << 28;
|
if (b & 0x80)
|
||||||
|
value |= (readByte(input) & 0x7F) << 28;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,23 +230,39 @@ static bool checkBinary(const char *binaryData, int length) {
|
|||||||
void USpineSkeletonDataAsset::LoadInfo() {
|
void USpineSkeletonDataAsset::LoadInfo() {
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
int dataLen = rawData.Num();
|
int dataLen = rawData.Num();
|
||||||
if (dataLen == 0) return;
|
if (dataLen == 0)
|
||||||
|
return;
|
||||||
NullAttachmentLoader loader;
|
NullAttachmentLoader loader;
|
||||||
SkeletonData *skeletonData = nullptr;
|
SkeletonData *skeletonData = nullptr;
|
||||||
if (skeletonDataFileName.GetPlainNameString().Contains(TEXT(".json"))) {
|
if (skeletonDataFileName.GetPlainNameString().Contains(TEXT(".json"))) {
|
||||||
SkeletonJson *json = new (__FILE__, __LINE__) SkeletonJson(&loader);
|
SkeletonJson *json = new (__FILE__, __LINE__) SkeletonJson(&loader);
|
||||||
if (checkJson((const char *) rawData.GetData())) skeletonData = json->readSkeletonData((const char *) rawData.GetData());
|
if (checkJson((const char *) rawData.GetData()))
|
||||||
|
skeletonData = json->readSkeletonData((const char *) rawData.GetData());
|
||||||
if (!skeletonData) {
|
if (!skeletonData) {
|
||||||
FMessageDialog::Debugf(FText::FromString(FString("Couldn't load skeleton data and/or atlas. Please ensure the version of your exported data matches your runtime version.\n\n") + skeletonDataFileName.GetPlainNameString() + FString("\n\n") + UTF8_TO_TCHAR(json->getError().buffer())));
|
FMessageDialog::Debugf(FText::FromString(
|
||||||
UE_LOG(SpineLog, Error, TEXT("Couldn't load skeleton data and atlas: %s"), UTF8_TO_TCHAR(json->getError().buffer()));
|
FString("Couldn't load skeleton data and/or atlas. Please ensure the "
|
||||||
|
"version of your exported data matches your runtime "
|
||||||
|
"version.\n\n") +
|
||||||
|
skeletonDataFileName.GetPlainNameString() + FString("\n\n") +
|
||||||
|
UTF8_TO_TCHAR(json->getError().buffer())));
|
||||||
|
UE_LOG(SpineLog, Error, TEXT("Couldn't load skeleton data and atlas: %s"),
|
||||||
|
UTF8_TO_TCHAR(json->getError().buffer()));
|
||||||
}
|
}
|
||||||
delete json;
|
delete json;
|
||||||
} else {
|
} else {
|
||||||
SkeletonBinary *binary = new (__FILE__, __LINE__) SkeletonBinary(&loader);
|
SkeletonBinary *binary = new (__FILE__, __LINE__) SkeletonBinary(&loader);
|
||||||
if (checkBinary((const char *) rawData.GetData(), (int) rawData.Num())) skeletonData = binary->readSkeletonData((const unsigned char *) rawData.GetData(), (int) rawData.Num());
|
if (checkBinary((const char *) rawData.GetData(), (int) rawData.Num()))
|
||||||
|
skeletonData = binary->readSkeletonData(
|
||||||
|
(const unsigned char *) rawData.GetData(), (int) rawData.Num());
|
||||||
if (!skeletonData) {
|
if (!skeletonData) {
|
||||||
FMessageDialog::Debugf(FText::FromString(FString("Couldn't load skeleton data and/or atlas. Please ensure the version of your exported data matches your runtime version.\n\n") + skeletonDataFileName.GetPlainNameString() + FString("\n\n") + UTF8_TO_TCHAR(binary->getError().buffer())));
|
FMessageDialog::Debugf(FText::FromString(
|
||||||
UE_LOG(SpineLog, Error, TEXT("Couldn't load skeleton data and atlas: %s"), UTF8_TO_TCHAR(binary->getError().buffer()));
|
FString("Couldn't load skeleton data and/or atlas. Please ensure the "
|
||||||
|
"version of your exported data matches your runtime "
|
||||||
|
"version.\n\n") +
|
||||||
|
skeletonDataFileName.GetPlainNameString() + FString("\n\n") +
|
||||||
|
UTF8_TO_TCHAR(binary->getError().buffer())));
|
||||||
|
UE_LOG(SpineLog, Error, TEXT("Couldn't load skeleton data and atlas: %s"),
|
||||||
|
UTF8_TO_TCHAR(binary->getError().buffer()));
|
||||||
}
|
}
|
||||||
delete binary;
|
delete binary;
|
||||||
}
|
}
|
||||||
@ -256,10 +278,12 @@ void USpineSkeletonDataAsset::LoadInfo() {
|
|||||||
Slots.Add(UTF8_TO_TCHAR(skeletonData->getSlots()[i]->getName().buffer()));
|
Slots.Add(UTF8_TO_TCHAR(skeletonData->getSlots()[i]->getName().buffer()));
|
||||||
Animations.Empty();
|
Animations.Empty();
|
||||||
for (int i = 0; i < skeletonData->getAnimations().size(); i++)
|
for (int i = 0; i < skeletonData->getAnimations().size(); i++)
|
||||||
Animations.Add(UTF8_TO_TCHAR(skeletonData->getAnimations()[i]->getName().buffer()));
|
Animations.Add(
|
||||||
|
UTF8_TO_TCHAR(skeletonData->getAnimations()[i]->getName().buffer()));
|
||||||
Events.Empty();
|
Events.Empty();
|
||||||
for (int i = 0; i < skeletonData->getEvents().size(); i++)
|
for (int i = 0; i < skeletonData->getEvents().size(); i++)
|
||||||
Events.Add(UTF8_TO_TCHAR(skeletonData->getEvents()[i]->getName().buffer()));
|
Events.Add(
|
||||||
|
UTF8_TO_TCHAR(skeletonData->getEvents()[i]->getName().buffer()));
|
||||||
delete skeletonData;
|
delete skeletonData;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -277,28 +301,46 @@ SkeletonData *USpineSkeletonDataAsset::GetSkeletonData(Atlas *Atlas) {
|
|||||||
int dataLen = rawData.Num();
|
int dataLen = rawData.Num();
|
||||||
if (skeletonDataFileName.GetPlainNameString().Contains(TEXT(".json"))) {
|
if (skeletonDataFileName.GetPlainNameString().Contains(TEXT(".json"))) {
|
||||||
SkeletonJson *json = new (__FILE__, __LINE__) SkeletonJson(Atlas);
|
SkeletonJson *json = new (__FILE__, __LINE__) SkeletonJson(Atlas);
|
||||||
if (checkJson((const char *) rawData.GetData())) skeletonData = json->readSkeletonData((const char *) rawData.GetData());
|
if (checkJson((const char *) rawData.GetData()))
|
||||||
|
skeletonData = json->readSkeletonData((const char *) rawData.GetData());
|
||||||
if (!skeletonData) {
|
if (!skeletonData) {
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
FMessageDialog::Debugf(FText::FromString(FString("Couldn't load skeleton data and/or atlas. Please ensure the version of your exported data matches your runtime version.\n\n") + skeletonDataFileName.GetPlainNameString() + FString("\n\n") + UTF8_TO_TCHAR(json->getError().buffer())));
|
FMessageDialog::Debugf(FText::FromString(
|
||||||
|
FString("Couldn't load skeleton data and/or atlas. Please ensure "
|
||||||
|
"the version of your exported data matches your runtime "
|
||||||
|
"version.\n\n") +
|
||||||
|
skeletonDataFileName.GetPlainNameString() + FString("\n\n") +
|
||||||
|
UTF8_TO_TCHAR(json->getError().buffer())));
|
||||||
#endif
|
#endif
|
||||||
UE_LOG(SpineLog, Error, TEXT("Couldn't load skeleton data and atlas: %s"), UTF8_TO_TCHAR(json->getError().buffer()));
|
UE_LOG(SpineLog, Error,
|
||||||
|
TEXT("Couldn't load skeleton data and atlas: %s"),
|
||||||
|
UTF8_TO_TCHAR(json->getError().buffer()));
|
||||||
}
|
}
|
||||||
delete json;
|
delete json;
|
||||||
} else {
|
} else {
|
||||||
SkeletonBinary *binary = new (__FILE__, __LINE__) SkeletonBinary(Atlas);
|
SkeletonBinary *binary = new (__FILE__, __LINE__) SkeletonBinary(Atlas);
|
||||||
if (checkBinary((const char *) rawData.GetData(), (int) rawData.Num())) skeletonData = binary->readSkeletonData((const unsigned char *) rawData.GetData(), (int) rawData.Num());
|
if (checkBinary((const char *) rawData.GetData(), (int) rawData.Num()))
|
||||||
|
skeletonData = binary->readSkeletonData(
|
||||||
|
(const unsigned char *) rawData.GetData(), (int) rawData.Num());
|
||||||
if (!skeletonData) {
|
if (!skeletonData) {
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
FMessageDialog::Debugf(FText::FromString(FString("Couldn't load skeleton data and/or atlas. Please ensure the version of your exported data matches your runtime version.\n\n") + skeletonDataFileName.GetPlainNameString() + FString("\n\n") + UTF8_TO_TCHAR(binary->getError().buffer())));
|
FMessageDialog::Debugf(FText::FromString(
|
||||||
|
FString("Couldn't load skeleton data and/or atlas. Please ensure "
|
||||||
|
"the version of your exported data matches your runtime "
|
||||||
|
"version.\n\n") +
|
||||||
|
skeletonDataFileName.GetPlainNameString() + FString("\n\n") +
|
||||||
|
UTF8_TO_TCHAR(binary->getError().buffer())));
|
||||||
#endif
|
#endif
|
||||||
UE_LOG(SpineLog, Error, TEXT("Couldn't load skeleton data and atlas: %s"), UTF8_TO_TCHAR(binary->getError().buffer()));
|
UE_LOG(SpineLog, Error,
|
||||||
|
TEXT("Couldn't load skeleton data and atlas: %s"),
|
||||||
|
UTF8_TO_TCHAR(binary->getError().buffer()));
|
||||||
}
|
}
|
||||||
delete binary;
|
delete binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skeletonData) {
|
if (skeletonData) {
|
||||||
animationStateData = new (__FILE__, __LINE__) AnimationStateData(skeletonData);
|
animationStateData =
|
||||||
|
new (__FILE__, __LINE__) AnimationStateData(skeletonData);
|
||||||
SetMixes(animationStateData);
|
SetMixes(animationStateData);
|
||||||
atlasToNativeData.Add(Atlas, {skeletonData, animationStateData});
|
atlasToNativeData.Add(Atlas, {skeletonData, animationStateData});
|
||||||
}
|
}
|
||||||
@ -318,14 +360,17 @@ void USpineSkeletonDataAsset::SetMixes(AnimationStateData *animationStateData) {
|
|||||||
animationStateData->setDefaultMix(DefaultMix);
|
animationStateData->setDefaultMix(DefaultMix);
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationStateData *USpineSkeletonDataAsset::GetAnimationStateData(Atlas *atlas) {
|
AnimationStateData *
|
||||||
if (!atlasToNativeData.Contains(atlas)) return nullptr;
|
USpineSkeletonDataAsset::GetAnimationStateData(Atlas *atlas) {
|
||||||
|
if (!atlasToNativeData.Contains(atlas))
|
||||||
|
return nullptr;
|
||||||
AnimationStateData *data = atlasToNativeData[atlas].animationStateData;
|
AnimationStateData *data = atlasToNativeData[atlas].animationStateData;
|
||||||
SetMixes(data);
|
SetMixes(data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USpineSkeletonDataAsset::SetMix(const FString &from, const FString &to, float mix) {
|
void USpineSkeletonDataAsset::SetMix(const FString &from, const FString &to,
|
||||||
|
float mix) {
|
||||||
FSpineAnimationStateMixData data;
|
FSpineAnimationStateMixData data;
|
||||||
data.From = from;
|
data.From = from;
|
||||||
data.To = to;
|
data.To = to;
|
||||||
@ -338,7 +383,8 @@ void USpineSkeletonDataAsset::SetMix(const FString &from, const FString &to, flo
|
|||||||
|
|
||||||
float USpineSkeletonDataAsset::GetMix(const FString &from, const FString &to) {
|
float USpineSkeletonDataAsset::GetMix(const FString &from, const FString &to) {
|
||||||
for (auto &data : MixData) {
|
for (auto &data : MixData) {
|
||||||
if (data.From.Equals(from) && data.To.Equals(to)) return data.Mix;
|
if (data.From.Equals(from) && data.To.Equals(to))
|
||||||
|
return data.Mix;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,6 +71,5 @@ protected:
|
|||||||
|
|
||||||
virtual void PostInitProperties() override;
|
virtual void PostInitProperties() override;
|
||||||
virtual void Serialize(FArchive &Ar) override;
|
virtual void Serialize(FArchive &Ar) override;
|
||||||
virtual void PostLoadAssetRegistryTags(const FAssetData &InAssetData, TArray<FAssetRegistryTag> &OutTagsAndValuesToUpdate) const override;
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
@ -114,9 +114,9 @@ protected:
|
|||||||
class UAssetImportData *importData = nullptr;
|
class UAssetImportData *importData = nullptr;
|
||||||
|
|
||||||
virtual void PostInitProperties() override;
|
virtual void PostInitProperties() override;
|
||||||
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag> &OutTags) const override;
|
virtual void
|
||||||
|
GetAssetRegistryTags(TArray<FAssetRegistryTag> &OutTags) const override;
|
||||||
virtual void Serialize(FArchive &Ar) override;
|
virtual void Serialize(FArchive &Ar) override;
|
||||||
virtual void PostLoadAssetRegistryTags(const FAssetData &InAssetData, TArray<FAssetRegistryTag> &OutTagsAndValuesToUpdate) const override;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void LoadInfo();
|
void LoadInfo();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user