Kaynağa Gözat

[ue4] Updated example project to 4.20. Fixed re-import of skeletons, see #1177.

badlogic 7 yıl önce
ebeveyn
işleme
b2479bf7bf

BIN
spine-cocos2dx/example/proj.win32/spine-cocos2d-x.VC.VC.opendb


+ 1 - 1
spine-ue4/Plugins/SpinePlugin/Source/SpineEditorPlugin/Private/SpineAtlasImportFactory.cpp

@@ -51,7 +51,7 @@ USpineAtlasAssetFactory::USpineAtlasAssetFactory (const FObjectInitializer& obje
 	bEditorImport = true;
 	SupportedClass = USpineAtlasAsset::StaticClass();
 	
-	Formats.Add(TEXT("atlas;Spine atlas file"));
+	Formats.Add(TEXT("atlas;Spine Atlas file"));
 }
 
 FText USpineAtlasAssetFactory::GetToolTip () const {

+ 7 - 5
spine-ue4/Plugins/SpinePlugin/Source/SpineEditorPlugin/SpineEditorPlugin.Build.cs

@@ -6,9 +6,11 @@ namespace UnrealBuildTool.Rules
 	{
 		public SpineEditorPlugin(ReadOnlyTargetRules Target) : base(Target)
 		{
-			PublicIncludePaths.AddRange(new string[] { "SpineEditorPlugin/Public", "SpinePlugin/Public/spine-cpp/include" });
-            
-            PrivateIncludePaths.AddRange(new string[] { "SpineEditorPlugin/Private", "SpinePlugin/Public/spine-cpp/include" });
+            PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));
+			PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "../SpinePlugin/Public/spine-cpp/include"));
+
+			PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));
+			PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "../SpinePlugin/Public/spine-cpp/include"));
 
             PublicDependencyModuleNames.AddRange(new string[] {
                 "Core",
@@ -17,12 +19,12 @@ namespace UnrealBuildTool.Rules
                 "UnrealEd",
                 "SpinePlugin"
             });
-            
+
             PublicIncludePathModuleNames.AddRange(new string[] {
                "AssetTools",
                "AssetRegistry"
             });
-            
+
             DynamicallyLoadedModuleNames.AddRange(new string[] {
                "AssetTools",
                "AssetRegistry"

+ 1 - 1
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineAtlasAsset.cpp

@@ -111,7 +111,7 @@ Atlas* USpineAtlasAsset::GetAtlas (bool ForceReload) {
 				page->setRendererObject(atlasPages[j++]);
 		}
 	}
-	return this->atlas;
+	return this->atlas;	
 }
 
 #undef LOCTEXT_NAMESPACE

+ 19 - 2
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonAnimationComponent.cpp

@@ -104,11 +104,27 @@ void USpineSkeletonAnimationComponent::InternalTick(float DeltaTime, bool CallDe
 }
 
 void USpineSkeletonAnimationComponent::CheckState () {
-	if (lastAtlas != Atlas || lastData != SkeletonData) {
+	bool needsUpdate = lastAtlas != Atlas || lastData != SkeletonData;
+
+	if (!needsUpdate) {
+		// Are we doing a re-import? Then check if the underlying spine-cpp data
+		// has changed.
+		if (lastAtlas && lastAtlas == Atlas && lastData && lastData == SkeletonData) {
+			spine::Atlas* atlas = Atlas->GetAtlas(false);
+			if (lastSpineAtlas != atlas) {
+				needsUpdate = true;
+			}
+			if (skeleton && skeleton->getData() != SkeletonData->GetSkeletonData(atlas)) {
+				needsUpdate = true;
+			}
+		}
+	}
+
+	if (needsUpdate) {
 		DisposeState();
 		
 		if (Atlas && SkeletonData) {
-			spine::SkeletonData *data = SkeletonData->GetSkeletonData(Atlas->GetAtlas(false), false);
+			spine::SkeletonData *data = SkeletonData->GetSkeletonData(Atlas->GetAtlas(false), true);
 			if (data) {
 				skeleton = new (__FILE__, __LINE__) Skeleton(data);
 				AnimationStateData* stateData = SkeletonData->GetAnimationStateData(Atlas->GetAtlas(false));
@@ -120,6 +136,7 @@ void USpineSkeletonAnimationComponent::CheckState () {
 		}
 		
 		lastAtlas = Atlas;
+		lastSpineAtlas = Atlas ? Atlas->GetAtlas(false) : nullptr;
 		lastData = SkeletonData;
 	}
 }

+ 18 - 1
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp

@@ -200,7 +200,23 @@ void USpineSkeletonComponent::InternalTick(float DeltaTime, bool CallDelegates)
 }
 
 void USpineSkeletonComponent::CheckState () {
-	if (lastAtlas != Atlas || lastData != SkeletonData) {
+	bool needsUpdate = lastAtlas != Atlas || lastData != SkeletonData;
+
+	if (!needsUpdate) {
+		// Are we doing a re-import? Then check if the underlying spine-cpp data
+		// has changed.
+		if (lastAtlas && lastAtlas == Atlas && lastData && lastData == SkeletonData) {
+			spine::Atlas* atlas = Atlas->GetAtlas(false);
+			if (lastSpineAtlas != atlas) {
+				needsUpdate = true;
+			}
+			if (skeleton && skeleton->getData() != SkeletonData->GetSkeletonData(atlas)) {
+				needsUpdate = true;
+			}
+		}
+	}
+
+	if (needsUpdate) {
 		DisposeState();
 		
 		if (Atlas && SkeletonData) {
@@ -209,6 +225,7 @@ void USpineSkeletonComponent::CheckState () {
 		}
 		
 		lastAtlas = Atlas;
+		lastSpineAtlas = Atlas ? Atlas->GetAtlas(false) : nullptr;
 		lastData = SkeletonData;
 	}
 }

+ 2 - 1
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonDataAsset.cpp

@@ -97,7 +97,7 @@ void USpineSkeletonDataAsset::BeginDestroy () {
 }
 
 SkeletonData* USpineSkeletonDataAsset::GetSkeletonData (Atlas* Atlas, bool ForceReload) {
-	if (!skeletonData || ForceReload) {
+	if (!skeletonData || lastAtlas != Atlas || ForceReload) {
 		if (skeletonData) {
 			delete skeletonData;
 			skeletonData = nullptr;
@@ -126,6 +126,7 @@ SkeletonData* USpineSkeletonDataAsset::GetSkeletonData (Atlas* Atlas, bool Force
 		}
 		if (animationStateData) {
 			delete animationStateData;
+			animationStateData = nullptr;
 			GetAnimationStateData(Atlas);
 		}
 		lastAtlas = Atlas;

+ 1 - 0
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h

@@ -114,5 +114,6 @@ protected:
 
 	spine::Skeleton* skeleton;
 	USpineAtlasAsset* lastAtlas = nullptr;
+	spine::Atlas* lastSpineAtlas = nullptr;
 	USpineSkeletonDataAsset* lastData = nullptr;	
 };

+ 14 - 5
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/SpinePlugin.Build.cs

@@ -1,17 +1,26 @@
 // Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
 
+using System;
+using System.IO;
+
 namespace UnrealBuildTool.Rules
 {
 	public class SpinePlugin : ModuleRules
 	{
 		public SpinePlugin(ReadOnlyTargetRules Target) : base(Target)
 		{
-			PublicIncludePaths.AddRange(new string[] { "SpinePlugin/Public", "SpinePlugin/Public/spine-cpp/include" });
-            PrivateIncludePaths.AddRange(new string[] { "SpinePlugin/Private", "SpinePlugin/Public/spine-cpp/include" });
+			PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));
+			PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public/spine-cpp/include"));
+
+			PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));
+			PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Public/spine-cpp/include"));
+
             PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "RHI", "RenderCore", "ShaderCore", "ProceduralMeshComponent", "UMG", "Slate", "SlateCore" });
-			Definitions.Add("SPINE_UE4");
-			// In Unreal 4.20+, comment the above line, uncomment the below line
-			// PublicDefinitions.Add("SPINE_UE4");
+			PublicDefinitions.Add("SPINE_UE4");
+
+			// For UE 4.19 and below comment the line above and uncomment the line
+			// below.
+			// Definitions.Add("SPINE_UE4");
 		}
 	}
 }

+ 1 - 1
spine-ue4/SpineUE4.uproject

@@ -1,6 +1,6 @@
 {
 	"FileVersion": 3,
-	"EngineAssociation": "4.18",
+	"EngineAssociation": "4.20",
 	"Category": "",
 	"Description": "",
 	"Modules": [