Pārlūkot izejas kodu

Merge branch '4.0' into 4.1-beta

Harald Csaszar 3 gadi atpakaļ
vecāks
revīzija
1cc2a57be5

+ 1 - 0
CHANGELOG.md

@@ -249,6 +249,7 @@
   * `SkeletonRenderer` (and subclasses`SkeletonAnimation` and `SkeletonMecanim`) now provide a property `Advanced - Fix Prefab Override MeshFilter`, which when enabled fixes the prefab always being marked as changed. It sets the MeshFilter's hide flags to `DontSaveInEditor`. Unfortunately this comes at the cost of references to the `MeshFilter` by other components being lost, therefore this parameter defaults to `false` to keep the safe existing behaviour.
   * `BoundingBoxFollower` and `BoundingBoxFollowerGraphic` now provide previously missing `usedByEffector` and `usedByComposite` parameters to be set at all generated colliders.
   * `BoneFollower` and `BoneFollowerGraphic` now provide an additional `Follow Parent World Scale` parameter to allow following simple scale of parent bones (rotated/skewed scale can't be supported).
+  * Improved `Advanced - Fix Prefab Override MeshFilter` property for `SkeletonRenderer` (and subclasses`SkeletonAnimation` and `SkeletonMecanim`), now providing an additional option to use a global value which can be set in `Edit - Preferences - Spine`.
 
 * **Changes of default values**
 

+ 5 - 8
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs

@@ -45,8 +45,6 @@
 #define HAS_ON_POSTPROCESS_PREFAB
 #endif
 
-using System.Collections.Generic;
-using System.Reflection;
 using UnityEditor;
 using UnityEngine;
 
@@ -131,7 +129,7 @@ namespace Spine.Unity.Editor {
 			SingleSubmeshLabel = new GUIContent("Use Single Submesh", "Simplifies submesh generation by assuming you are only using one Material and need only one submesh. This is will disable multiple materials, render separation, and custom slot materials.");
 			UpdateWhenInvisibleLabel = new GUIContent("Update When Invisible", "Update mode used when the MeshRenderer becomes invisible. Update mode is automatically reset to UpdateMode.FullUpdate when the mesh becomes visible again.");
 			FixDrawOrderLabel = new GUIContent("Fix Draw Order", "Applies only when 3+ submeshes are used (2+ materials with alternating order, e.g. \"A B A\"). If true, GPU instancing will be disabled at all materials and MaterialPropertyBlocks are assigned at each material to prevent aggressive batching of submeshes by e.g. the LWRP renderer, leading to incorrect draw order (e.g. \"A1 B A2\" changed to \"A1A2 B\"). You can disable this parameter when everything is drawn correctly to save the additional performance cost. Note: the GPU instancing setting will remain disabled at affected material assets after exiting play mode, you have to enable it manually if you accidentally enabled this parameter.");
-			FixPrefabOverrideViaMeshFilterLabel = new GUIContent("Fix Prefab Overr. MeshFilter", "Fixes the prefab always being marked as changed (sets the MeshFilter's hide flags to DontSaveInEditor), but at the cost of references to the MeshFilter by other components being lost.");
+			FixPrefabOverrideViaMeshFilterLabel = new GUIContent("Fix Prefab Overr. MeshFilter", "Fixes the prefab always being marked as changed (sets the MeshFilter's hide flags to DontSaveInEditor), but at the cost of references to the MeshFilter by other components being lost. For global settings see Edit - Preferences - Spine.");
 			MaskInteractionLabel = new GUIContent("Mask Interaction", "SkeletonRenderer's interaction with a Sprite Mask.");
 			MaskMaterialsHeadingLabel = new GUIContent("Mask Interaction Materials", "Materials used for different interaction with sprite masks.");
 			MaskMaterialsNoneLabel = new GUIContent("Normal Materials", "Normal materials used when Mask Interaction is set to None.");
@@ -397,11 +395,11 @@ namespace Spine.Unity.Editor {
 
 							bool ignoredParam = true;
 							MaskMaterialsEditingField(ref setMaskNoneMaterialsQueued, ref ignoredParam, maskMaterialsNone, MaskMaterialsNoneLabel,
-														differentMaskModesSelected, allowDelete : false, isActiveMaterial : activeMaskInteractionValue == (int)SpriteMaskInteraction.None);
+														differentMaskModesSelected, allowDelete: false, isActiveMaterial: activeMaskInteractionValue == (int)SpriteMaskInteraction.None);
 							MaskMaterialsEditingField(ref setInsideMaskMaterialsQueued, ref deleteInsideMaskMaterialsQueued, maskMaterialsInside, MaskMaterialsInsideLabel,
 														differentMaskModesSelected, allowDelete: true, isActiveMaterial: activeMaskInteractionValue == (int)SpriteMaskInteraction.VisibleInsideMask);
 							MaskMaterialsEditingField(ref setOutsideMaskMaterialsQueued, ref deleteOutsideMaskMaterialsQueued, maskMaterialsOutside, MaskMaterialsOutsideLabel,
-														differentMaskModesSelected, allowDelete : true, isActiveMaterial: activeMaskInteractionValue == (int)SpriteMaskInteraction.VisibleOutsideMask);
+														differentMaskModesSelected, allowDelete: true, isActiveMaterial: activeMaskInteractionValue == (int)SpriteMaskInteraction.VisibleOutsideMask);
 						}
 #endif
 
@@ -630,14 +628,13 @@ namespace Spine.Unity.Editor {
 		}
 
 #if BUILT_IN_SPRITE_MASK_COMPONENT
-		static void EditorSetMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType)
-		{
+		static void EditorSetMaskMaterials (SkeletonRenderer component, SpriteMaskInteraction maskType) {
 			if (component == null) return;
 			if (!SpineEditorUtilities.SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
 			SpineMaskUtilities.EditorInitMaskMaterials(component, component.maskMaterials, maskType);
 		}
 
-		static void EditorDeleteMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType) {
+		static void EditorDeleteMaskMaterials (SkeletonRenderer component, SpriteMaskInteraction maskType) {
 			if (component == null) return;
 			if (!SpineEditorUtilities.SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
 			SpineMaskUtilities.EditorDeleteMaskMaterials(component.maskMaterials, maskType);

+ 23 - 2
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs

@@ -35,6 +35,10 @@
 #define NEW_PREFERENCES_SETTINGS_PROVIDER
 #endif
 
+#if UNITY_2020_2_OR_NEWER
+#define HAS_ON_POSTPROCESS_PREFAB
+#endif
+
 using System.Threading;
 using UnityEditor;
 using UnityEngine;
@@ -78,6 +82,11 @@ namespace Spine.Unity.Editor {
 		internal const string DEFAULT_TEXTURE_SETTINGS_REFERENCE = "";
 		public string textureSettingsReference = DEFAULT_TEXTURE_SETTINGS_REFERENCE;
 
+#if HAS_ON_POSTPROCESS_PREFAB
+		internal const bool DEFAULT_FIX_PREFAB_OVERRIDE_VIA_MESH_FILTER = false;
+		public bool fixPrefabOverrideViaMeshFilter = DEFAULT_FIX_PREFAB_OVERRIDE_VIA_MESH_FILTER;
+#endif
+
 		public bool UsesPMAWorkflow {
 			get {
 				return IsPMAWorkflow(textureSettingsReference);
@@ -177,8 +186,7 @@ namespace Spine.Unity.Editor {
 			settings = AssetDatabase.LoadAssetAtPath<SpinePreferences>(SPINE_SETTINGS_ASSET_PATH);
 			if (settings == null)
 				settings = FindSpinePreferences();
-			if (settings == null)
-			{
+			if (settings == null) {
 				settings = ScriptableObject.CreateInstance<SpinePreferences>();
 				SpineEditorUtilities.OldPreferences.CopyOldToNewPreferences(ref settings);
 				// Multiple threads may be calling this method during import, creating the folder
@@ -189,6 +197,10 @@ namespace Spine.Unity.Editor {
 				if (Interlocked.Exchange(ref wasPreferencesAssetCreated, 1) == 0)
 					AssetDatabase.CreateAsset(settings, SPINE_SETTINGS_ASSET_PATH);
 			}
+
+#if HAS_ON_POSTPROCESS_PREFAB
+			SkeletonRenderer.fixPrefabOverrideViaMeshFilterGlobal = settings.fixPrefabOverrideViaMeshFilter;
+#endif
 			return settings;
 		}
 
@@ -280,6 +292,15 @@ namespace Spine.Unity.Editor {
 					}
 				}
 
+#if HAS_ON_POSTPROCESS_PREFAB
+				EditorGUILayout.Space();
+				EditorGUILayout.LabelField("Prefabs", EditorStyles.boldLabel);
+				{
+					EditorGUILayout.PropertyField(settings.FindProperty("fixPrefabOverrideViaMeshFilter"), new GUIContent("Fix Prefab Overr. MeshFilter", "Fixes the prefab always being marked as changed (sets the MeshFilter's hide flags to DontSaveInEditor), but at the cost of references to the MeshFilter by other components being lost. This is a global setting that can be overwritten on each SkeletonRenderer"));
+					SkeletonRenderer.fixPrefabOverrideViaMeshFilterGlobal = settings.FindProperty("fixPrefabOverrideViaMeshFilter").boolValue;
+				}
+#endif
+
 #if SPINE_TK2D_DEFINE
 				bool isTK2DDefineSet = true;
 #else

+ 24 - 23
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs

@@ -73,17 +73,26 @@ namespace Spine.Unity {
 			set { editorSkipSkinSync = value; }
 		}
 		protected bool editorSkipSkinSync = false;
+
 		/// <summary>Sets the MeshFilter's hide flags to DontSaveInEditor which fixes the prefab
 		/// always being marked as changed, but at the cost of references to the MeshFilter by other
 		/// components being lost.</summary>
-		public bool fixPrefabOverrideViaMeshFilter = false;
+		public SettingsTriState fixPrefabOverrideViaMeshFilter = SettingsTriState.UseGlobalSetting;
+		public static bool fixPrefabOverrideViaMeshFilterGlobal = false;
 		public void EditorUpdateMeshFilterHideFlags () {
 			if (!meshFilter) {
 				meshFilter = GetComponent<MeshFilter>();
 				if (meshFilter == null)
 					meshFilter = gameObject.AddComponent<MeshFilter>();
 			}
-			if (fixPrefabOverrideViaMeshFilter) {
+
+			bool dontSaveInEditor = false;
+			if (fixPrefabOverrideViaMeshFilter == SettingsTriState.Enable ||
+				(fixPrefabOverrideViaMeshFilter == SettingsTriState.UseGlobalSetting &&
+					fixPrefabOverrideViaMeshFilterGlobal))
+				dontSaveInEditor = true;
+
+			if (dontSaveInEditor) {
 #if NEW_PREFAB_SYSTEM
 				if (UnityEditor.PrefabUtility.IsPartOfAnyPrefab(meshFilter)) {
 					var instanceRoot = UnityEditor.PrefabUtility.GetOutermostPrefabInstanceRoot(meshFilter);
@@ -99,8 +108,7 @@ namespace Spine.Unity {
 				}
 #endif
 				meshFilter.hideFlags = HideFlags.DontSaveInEditor;
-			}
-			else {
+			} else {
 				meshFilter.hideFlags = HideFlags.None;
 			}
 		}
@@ -321,7 +329,7 @@ namespace Spine.Unity {
 #endif
 
 #if UNITY_EDITOR
-		void OnEnable() {
+		void OnEnable () {
 			if (!Application.isPlaying)
 				LateUpdate();
 		}
@@ -619,8 +627,7 @@ namespace Spine.Unity {
 					separatorSlots.Add(slot);
 				}
 #if UNITY_EDITOR
-				else if (!string.IsNullOrEmpty(separatorSlotNames[i]))
-				{
+				else if (!string.IsNullOrEmpty(separatorSlotNames[i])) {
 					Debug.LogWarning(separatorSlotNames[i] + " is not a slot in " + skeletonDataAsset.skeletonJSON.name);
 				}
 #endif
@@ -628,8 +635,7 @@ namespace Spine.Unity {
 		}
 
 #if BUILT_IN_SPRITE_MASK_COMPONENT
-		private void AssignSpriteMaskMaterials()
-		{
+		private void AssignSpriteMaskMaterials () {
 #if UNITY_EDITOR
 			if (!Application.isPlaying && !UnityEditor.EditorApplication.isUpdating) {
 				EditorFixStencilCompParameters();
@@ -644,15 +650,13 @@ namespace Spine.Unity {
 			if (maskMaterials.materialsMaskDisabled.Length > 0 && maskMaterials.materialsMaskDisabled[0] != null &&
 				maskInteraction == SpriteMaskInteraction.None) {
 				this.meshRenderer.materials = maskMaterials.materialsMaskDisabled;
-			}
-			else if (maskInteraction == SpriteMaskInteraction.VisibleInsideMask) {
+			} else if (maskInteraction == SpriteMaskInteraction.VisibleInsideMask) {
 				if (maskMaterials.materialsInsideMask.Length == 0 || maskMaterials.materialsInsideMask[0] == null) {
 					if (!InitSpriteMaskMaterialsInsideMask())
 						return;
 				}
 				this.meshRenderer.materials = maskMaterials.materialsInsideMask;
-			}
-			else if (maskInteraction == SpriteMaskInteraction.VisibleOutsideMask) {
+			} else if (maskInteraction == SpriteMaskInteraction.VisibleOutsideMask) {
 				if (maskMaterials.materialsOutsideMask.Length == 0 || maskMaterials.materialsOutsideMask[0] == null) {
 					if (!InitSpriteMaskMaterialsOutsideMask())
 						return;
@@ -661,18 +665,15 @@ namespace Spine.Unity {
 			}
 		}
 
-		private bool InitSpriteMaskMaterialsInsideMask()
-		{
+		private bool InitSpriteMaskMaterialsInsideMask () {
 			return InitSpriteMaskMaterialsForMaskType(STENCIL_COMP_MASKINTERACTION_VISIBLE_INSIDE, ref maskMaterials.materialsInsideMask);
 		}
 
-		private bool InitSpriteMaskMaterialsOutsideMask()
-		{
+		private bool InitSpriteMaskMaterialsOutsideMask () {
 			return InitSpriteMaskMaterialsForMaskType(STENCIL_COMP_MASKINTERACTION_VISIBLE_OUTSIDE, ref maskMaterials.materialsOutsideMask);
 		}
 
-		private bool InitSpriteMaskMaterialsForMaskType(UnityEngine.Rendering.CompareFunction maskFunction, ref Material[] materialsToFill)
-		{
+		private bool InitSpriteMaskMaterialsForMaskType (UnityEngine.Rendering.CompareFunction maskFunction, ref Material[] materialsToFill) {
 #if UNITY_EDITOR
 			if (!Application.isPlaying) {
 				return false;
@@ -690,14 +691,14 @@ namespace Spine.Unity {
 		}
 
 #if UNITY_EDITOR
-		private void EditorFixStencilCompParameters() {
+		private void EditorFixStencilCompParameters () {
 			if (!haveStencilParametersBeenFixed && HasAnyStencilComp0Material()) {
 				haveStencilParametersBeenFixed = true;
 				FixAllProjectMaterialsStencilCompParameters();
 			}
 		}
 
-		private void FixAllProjectMaterialsStencilCompParameters() {
+		private void FixAllProjectMaterialsStencilCompParameters () {
 			string[] materialGUIDS = UnityEditor.AssetDatabase.FindAssets("t:material");
 			foreach (var guid in materialGUIDS) {
 				string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guid);
@@ -712,7 +713,7 @@ namespace Spine.Unity {
 			UnityEditor.AssetDatabase.SaveAssets();
 		}
 
-		private bool HasAnyStencilComp0Material() {
+		private bool HasAnyStencilComp0Material () {
 			if (meshRenderer == null)
 				return false;
 
@@ -739,7 +740,7 @@ namespace Spine.Unity {
 		/// Otherwise, e.g. when using Lightweight Render Pipeline, deliberately separated draw calls
 		/// "A1 B A2" are reordered to "A1A2 B", regardless of batching-related project settings.
 		/// </summary>
-		private void SetMaterialSettingsToFixDrawOrder() {
+		private void SetMaterialSettingsToFixDrawOrder () {
 			if (reusedPropertyBlock == null) reusedPropertyBlock = new MaterialPropertyBlock();
 
 			bool hasPerRendererBlock = meshRenderer.HasPropertyBlock();

+ 42 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/Utility/SettingsTriState.cs

@@ -0,0 +1,42 @@
+/******************************************************************************
+ * Spine Runtimes License Agreement
+ * Last updated January 1, 2020. Replaces all prior versions.
+ *
+ * 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
+ * conditions of Section 2 of the Spine Editor License Agreement:
+ * http://esotericsoftware.com/spine-editor-license
+ *
+ * Otherwise, it is permitted to integrate the Spine Runtimes into software
+ * or otherwise create derivative works of the Spine Runtimes (collectively,
+ * "Products"), provided that each user of the Products must obtain their own
+ * Spine Editor license and redistribution of the Products in any form must
+ * include this license and copyright notice.
+ *
+ * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
+ * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
+namespace Spine.Unity {
+
+	/// <summary>
+	/// TriState enum which can be used to replace and extend a bool variable by
+	/// a third <c>UseGlobalSettings</c> state. Automatically maps serialized
+	/// bool values to corresponding <c>Disable</c> and <c>Enable</c> states.
+	/// </summary>
+	public enum SettingsTriState {
+		Disable,
+		Enable,
+		UseGlobalSetting
+	}
+}

+ 11 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/Utility/SettingsTriState.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8f6692d1b45ac11459207a012cafeb03
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: