Forráskód Böngészése

Merge branch '4.0' into 4.1-beta

Harald Csaszar 3 éve
szülő
commit
b2c45b7fde

+ 7 - 0
spine-unity/Assets/Spine Examples/Scripts/MaterialReplacementExample.cs

@@ -47,6 +47,13 @@ namespace Spine.Unity.Examples {
 		MaterialPropertyBlock mpb;
 
 		void Start () {
+			// Use the code below to programmatically query the original material.
+			// Note: using MeshRenderer.material will fail since it creates an instance copy of the Material,
+			// MeshRenderer.sharedMaterial might also fail when called too early or when no Attachments
+			// are visible in the initial first frame.
+			if (originalMaterial == null)
+				originalMaterial = skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial;
+
 			previousEnabled = replacementEnabled;
 			SetReplacementEnabled(replacementEnabled);
 			mpb = new MaterialPropertyBlock();

+ 17 - 7
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs

@@ -1,8 +1,8 @@
 /******************************************************************************
  * Spine Runtimes License Agreement
- * Last updated September 24, 2021. Replaces all prior versions.
+ * Last updated January 1, 2020. Replaces all prior versions.
  *
- * Copyright (c) 2013-2021, Esoteric Software LLC
+ * Copyright (c) 2013-2020, Esoteric Software LLC
  *
  * Integration of the Spine Runtimes into software or otherwise creating
  * derivative works of the Spine Runtimes is permitted under the terms and
@@ -27,6 +27,7 @@
  * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *****************************************************************************/
 
+
 #if UNITY_2018_1_OR_NEWER
 #define HAS_BUILD_PROCESS_WITH_REPORT
 #endif
@@ -50,7 +51,7 @@ namespace Spine.Unity.Editor {
 #if HAS_ON_POSTPROCESS_PREFAB
 		static List<string> prefabsToRestore = new List<string>();
 #endif
-		static Dictionary<string, Texture> spriteAtlasTexturesToRestore = new Dictionary<string, Texture>();
+		static Dictionary<string, string> spriteAtlasTexturesToRestore = new Dictionary<string, string>();
 
 		internal static void PreprocessBuild () {
 			isBuilding = true;
@@ -70,14 +71,18 @@ namespace Spine.Unity.Editor {
 
 #if HAS_ON_POSTPROCESS_PREFAB
 		internal static void PreprocessSpinePrefabMeshes () {
+			AssetDatabase.StartAssetEditing();
+			prefabsToRestore.Clear();
 			var prefabAssets = AssetDatabase.FindAssets("t:Prefab");
 			foreach (var asset in prefabAssets) {
 				string assetPath = AssetDatabase.GUIDToAssetPath(asset);
-				GameObject g = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
-				if (SpineEditorUtilities.CleanupSpinePrefabMesh(g)) {
+				GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
+				if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) {
 					prefabsToRestore.Add(assetPath);
 				}
+				EditorUtility.UnloadUnusedAssetsImmediate();
 			}
+			AssetDatabase.StopAssetEditing();
 			if (prefabAssets.Length > 0)
 				AssetDatabase.SaveAssets();
 		}
@@ -93,15 +98,19 @@ namespace Spine.Unity.Editor {
 		}
 #endif
 		internal static void PreprocessSpriteAtlases () {
+			AssetDatabase.StartAssetEditing();
+			spriteAtlasTexturesToRestore.Clear();
 			var spriteAtlasAssets = AssetDatabase.FindAssets("t:SpineSpriteAtlasAsset");
 			foreach (var asset in spriteAtlasAssets) {
 				string assetPath = AssetDatabase.GUIDToAssetPath(asset);
 				SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath);
 				if (atlasAsset && atlasAsset.materials.Length > 0) {
-					spriteAtlasTexturesToRestore[assetPath] = atlasAsset.materials[0].mainTexture;
+					spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture);
 					atlasAsset.materials[0].mainTexture = null;
 				}
+				EditorUtility.UnloadUnusedAssetsImmediate();
 			}
+			AssetDatabase.StopAssetEditing();
 			if (spriteAtlasAssets.Length > 0)
 				AssetDatabase.SaveAssets();
 		}
@@ -111,7 +120,8 @@ namespace Spine.Unity.Editor {
 				string assetPath = pair.Key;
 				SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath);
 				if (atlasAsset && atlasAsset.materials.Length > 0) {
-					atlasAsset.materials[0].mainTexture = pair.Value;
+					Texture atlasTexture = AssetDatabase.LoadAssetAtPath<Texture>(pair.Value);
+					atlasAsset.materials[0].mainTexture = atlasTexture;
 				}
 			}
 			if (spriteAtlasTexturesToRestore.Count > 0)

+ 3 - 5
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs

@@ -108,8 +108,7 @@ namespace Spine.Unity.Editor {
 			SetupSpinePrefabMesh(g, context);
 		}
 
-		public static bool SetupSpinePrefabMesh(GameObject g, UnityEditor.AssetImporters.AssetImportContext context)
-		{
+		public static bool SetupSpinePrefabMesh (GameObject g, UnityEditor.AssetImporters.AssetImportContext context) {
 			Dictionary<string, int> nameUsageCount = new Dictionary<string, int>();
 			bool wasModified = false;
 			var skeletonRenderers = g.GetComponentsInChildren<SkeletonRenderer>(true);
@@ -124,7 +123,7 @@ namespace Spine.Unity.Editor {
 				renderer.LateUpdateMesh();
 				var mesh = meshFilter.sharedMesh;
 				if (mesh == null) continue;
-				
+
 				string meshName = string.Format("Skeleton Prefab Mesh \"{0}\"", renderer.name);
 				if (nameUsageCount.ContainsKey(meshName)) {
 					nameUsageCount[meshName]++;
@@ -140,8 +139,7 @@ namespace Spine.Unity.Editor {
 			return wasModified;
 		}
 
-		public static bool CleanupSpinePrefabMesh(GameObject g)
-		{
+		public static bool CleanupSpinePrefabMesh (GameObject g) {
 			bool wasModified = false;
 			var skeletonRenderers = g.GetComponentsInChildren<SkeletonRenderer>(true);
 			foreach (SkeletonRenderer renderer in skeletonRenderers) {

+ 25 - 3
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs

@@ -216,6 +216,24 @@ namespace Spine.Unity.Editor {
 			return null;
 		}
 
+		private static void ShowBlendModeMaterialProperty (SerializedProperty blendModeMaterialProperty,
+			string blendType, bool isTexturePresetPMA) {
+
+			EditorGUILayout.PropertyField(blendModeMaterialProperty, new GUIContent(blendType + " Material", blendType + " blend mode Material template."));
+			var material = blendModeMaterialProperty.objectReferenceValue as Material;
+			if (material == null)
+				return;
+
+			bool isMaterialPMA = MaterialChecks.IsPMATextureMaterial(material);
+			if (!isTexturePresetPMA && isMaterialPMA) {
+				EditorGUILayout.HelpBox(string.Format("'{0} Material' uses PMA but 'Atlas Texture Settings' uses Straight Alpha. " +
+					"You might want to assign 'SkeletonStraight{0}' instead.", blendType), MessageType.Warning);
+			} else if (isTexturePresetPMA && !isMaterialPMA) {
+				EditorGUILayout.HelpBox(string.Format("'{0} Material' uses Straight Alpha but 'Atlas Texture Settings' uses PMA. " +
+					"You might want to assign 'SkeletonPMA{0}' instead.", blendType), MessageType.Warning);
+			}
+		}
+
 		public static void HandlePreferencesGUI (SerializedObject settings) {
 
 			float prevLabelWidth = EditorGUIUtility.labelWidth;
@@ -254,9 +272,13 @@ namespace Spine.Unity.Editor {
 						}
 					}
 
-					EditorGUILayout.PropertyField(settings.FindProperty("blendModeMaterialAdditive"), new GUIContent("Additive Material", "Additive blend mode Material template."));
-					EditorGUILayout.PropertyField(settings.FindProperty("blendModeMaterialMultiply"), new GUIContent("Multiply Material", "Multiply blend mode Material template."));
-					EditorGUILayout.PropertyField(settings.FindProperty("blendModeMaterialScreen"), new GUIContent("Screen Material", "Screen blend mode Material template."));
+					SerializedProperty blendModeMaterialAdditive = settings.FindProperty("blendModeMaterialAdditive");
+					SerializedProperty blendModeMaterialMultiply = settings.FindProperty("blendModeMaterialMultiply");
+					SerializedProperty blendModeMaterialScreen = settings.FindProperty("blendModeMaterialScreen");
+					bool isTexturePresetPMA = IsPMAWorkflow(textureSettingsRef.stringValue);
+					ShowBlendModeMaterialProperty(blendModeMaterialAdditive, "Additive", isTexturePresetPMA);
+					ShowBlendModeMaterialProperty(blendModeMaterialMultiply, "Multiply", isTexturePresetPMA);
+					ShowBlendModeMaterialProperty(blendModeMaterialScreen, "Screen", isTexturePresetPMA);
 				}
 
 				EditorGUILayout.Space();

+ 35 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonDataModifierAssets/BlendModeMaterials/SkeletonStraightAdditive.mat

@@ -0,0 +1,35 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!21 &2100000
+Material:
+  serializedVersion: 6
+  m_ObjectHideFlags: 0
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 0}
+  m_Name: SkeletonPMAAdditive
+  m_Shader: {fileID: 4800000, guid: 53efa1d97f5d9f74285d4330cda14e36, type: 3}
+  m_ShaderKeywords: 
+  m_LightmapFlags: 4
+  m_EnableInstancingVariants: 0
+  m_DoubleSidedGI: 0
+  m_CustomRenderQueue: -1
+  stringTagMap: {}
+  disabledShaderPasses: []
+  m_SavedProperties:
+    serializedVersion: 3
+    m_TexEnvs:
+    - <noninit>:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MainTex:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    m_Floats:
+    - <noninit>: 0
+    - _Cutoff: 0.1
+    - _StraightAlphaInput: 0
+    m_Colors:
+    - <noninit>: {r: 0, g: 2.018574, b: 1e-45, a: 0.000007110106}
+    - _Color: {r: 1, g: 1, b: 1, a: 1}

+ 8 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonDataModifierAssets/BlendModeMaterials/SkeletonStraightAdditive.mat.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 517c2df5a5dc5d44a8b3820eca503d13
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 0
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 43 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonDataModifierAssets/BlendModeMaterials/SkeletonStraightMultiply.mat

@@ -0,0 +1,43 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!21 &2100000
+Material:
+  serializedVersion: 6
+  m_ObjectHideFlags: 0
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 0}
+  m_Name: SkeletonPMAMultiply
+  m_Shader: {fileID: 4800000, guid: 8bdcdc7ee298e594a9c20c61d25c33b6, type: 3}
+  m_ShaderKeywords: 
+  m_LightmapFlags: 4
+  m_CustomRenderQueue: -1
+  stringTagMap: {}
+  m_SavedProperties:
+    serializedVersion: 2
+    m_TexEnvs:
+    - first:
+        name: <noninit>
+      second:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - first:
+        name: _MainTex
+      second:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    m_Floats:
+    - first:
+        name: <noninit>
+      second: 0
+    - first:
+        name: _Cutoff
+      second: 0.1
+    m_Colors:
+    - first:
+        name: <noninit>
+      second: {r: 0, g: 2.018574, b: 1e-45, a: 0.000007110106}
+    - first:
+        name: _Color
+      second: {r: 1, g: 1, b: 1, a: 1}

+ 8 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonDataModifierAssets/BlendModeMaterials/SkeletonStraightMultiply.mat.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 053fed1e18e65064ca564f05c4027e1e
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 0
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 43 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonDataModifierAssets/BlendModeMaterials/SkeletonStraightScreen.mat

@@ -0,0 +1,43 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!21 &2100000
+Material:
+  serializedVersion: 6
+  m_ObjectHideFlags: 0
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 0}
+  m_Name: SkeletonPMAScreen
+  m_Shader: {fileID: 4800000, guid: 4e8caa36c07aacf4ab270da00784e4d9, type: 3}
+  m_ShaderKeywords: 
+  m_LightmapFlags: 4
+  m_CustomRenderQueue: -1
+  stringTagMap: {}
+  m_SavedProperties:
+    serializedVersion: 2
+    m_TexEnvs:
+    - first:
+        name: <noninit>
+      second:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - first:
+        name: _MainTex
+      second:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    m_Floats:
+    - first:
+        name: <noninit>
+      second: 0
+    - first:
+        name: _Cutoff
+      second: 0.1
+    m_Colors:
+    - first:
+        name: <noninit>
+      second: {r: 0, g: 2.018574, b: 1e-45, a: 0.000007121922}
+    - first:
+        name: _Color
+      second: {r: 1, g: 1, b: 1, a: 1}

+ 8 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonDataModifierAssets/BlendModeMaterials/SkeletonStraightScreen.mat.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 1a66c2d7ee7642a459bd3831abeb30af
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 0
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 7 - 11
spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs

@@ -123,8 +123,7 @@ namespace Spine.Unity {
 			return isProblematic;
 		}
 
-		public static bool IsMaterialSetupProblematic(SkeletonGraphic skeletonGraphic, ref string errorMessage)
-		{
+		public static bool IsMaterialSetupProblematic (SkeletonGraphic skeletonGraphic, ref string errorMessage) {
 			var material = skeletonGraphic.material;
 			bool isProblematic = false;
 			if (material) {
@@ -157,11 +156,11 @@ namespace Spine.Unity {
 			return isProblematic;
 		}
 
-		public static bool IsMaterialSetupProblematic(Material material, ref string errorMessage) {
+		public static bool IsMaterialSetupProblematic (Material material, ref string errorMessage) {
 			return !IsColorSpaceSupported(material, ref errorMessage);
 		}
 
-		public static bool IsZSpacingRequired(Material material, ref string errorMessage) {
+		public static bool IsZSpacingRequired (Material material, ref string errorMessage) {
 			bool hasForwardAddPass = material.FindPass("FORWARD_DELTA") >= 0;
 			if (hasForwardAddPass) {
 				errorMessage += kZSpacingRequiredMessage;
@@ -222,8 +221,7 @@ namespace Spine.Unity {
 						"(You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath, materialName);
 					isProblematic = true;
 				}
-			}
-			else { // straight alpha texture
+			} else { // straight alpha texture
 				if (!alphaIsTransparency) {
 					string materialName = System.IO.Path.GetFileName(materialPath);
 					errorMessage += string.Format("`{0}` and material `{1}` : Incorrect" +
@@ -245,14 +243,12 @@ namespace Spine.Unity {
 					material.DisableKeyword(STRAIGHT_ALPHA_KEYWORD);
 				else
 					material.EnableKeyword(STRAIGHT_ALPHA_KEYWORD);
-			}
-			else {
+			} else {
 				if (enablePMATexture) {
 					material.DisableKeyword(ALPHAPREMULTIPLY_ON_KEYWORD);
 					material.DisableKeyword(ALPHABLEND_ON_KEYWORD);
 					material.EnableKeyword(ALPHAPREMULTIPLY_VERTEX_ONLY_ON_KEYWORD);
-				}
-				else {
+				} else {
 					material.DisableKeyword(ALPHAPREMULTIPLY_ON_KEYWORD);
 					material.DisableKeyword(ALPHAPREMULTIPLY_VERTEX_ONLY_ON_KEYWORD);
 					material.EnableKeyword(ALPHABLEND_ON_KEYWORD);
@@ -260,7 +256,7 @@ namespace Spine.Unity {
 			}
 		}
 
-		static bool IsPMATextureMaterial (Material material) {
+		public static bool IsPMATextureMaterial (Material material) {
 			bool usesAlphaPremultiplyKeyword = IsSpriteShader(material);
 			if (usesAlphaPremultiplyKeyword)
 				return material.IsKeywordEnabled(ALPHAPREMULTIPLY_ON_KEYWORD);