Эх сурвалжийг харах

[unity] Added `SkeletonRenderer.EditorSkipSkinSync` property for setting custom skins in editor scripts. Only affects inspector synchronisation of skin with `initialSkinName`, not startup initialization. Closes #1469.

Harald Csaszar 5 жил өмнө
parent
commit
ed68aef0ad

+ 1 - 0
CHANGELOG.md

@@ -296,6 +296,7 @@
   * `Real physics hinge chains` for both 2D and 3D physics. The [SkeletonUtilityBone](http://esotericsoftware.com/spine-unity#SkeletonUtilityBone) Inspector provides an interface to create 2D and 3D hinge chains. Previously created chains have only been respecting gravity, but not momentum of the skeleton or parent bones. The new physics rig created when pressing `Create 3D Hinge Chain` and `Create 2D Hinge Chain` creates a more complex setup that also works when flipping the skeleton. Note that the chain root node is no longer parented to bones of the skeleton. This is a requirement in Unity to have momentum applied properly - do not reparent the chain root to bones of your skeleton, or you will loose any momentum applied by the skeleton's movement.
   * `Outline rendering functionality for all shaders.` Every shader now provides an additional set of `Outline` parameters to enable custom outline rendering. When outline rendering is enabled via the `Material` inspector, it automatically switches the shader to the respective `Spine/Outline` shader variant. Outlines are generated by sampling neighbour pixels, so be sure to add enough transparent padding when exporting your atlas textures to fit the desired outline width. In order to enable outline rendering at a skeleton, it is recommended to first prepare an additional outline material copy and then switch the material of the target skeleton to this material. This prevents unnecessary additional runtime material copies and drawcalls. Material switching can be prepared via a [SkeletonRendererCustomMaterials](http://esotericsoftware.com/spine-unity#SkeletonRendererCustomMaterials) component and then enabled or disabled at runtime. Alternatively, you can also directly modify the `SkeletonRenderer.CustomMaterialOverride` property.
   Outline rendering is fully supported on `SkeletonGraphic` shaders as well.
+  * Added `SkeletonRenderer.EditorSkipSkinSync` scripting API property to be able to set custom skins in editor scripts. Enable this property when overwriting the Skeleton's skin from an editor script. Without setting this parameter, changes will be overwritten by the next inspector update. Only affects Inspector synchronisation of skin with `initialSkinName`, not startup initialization.
 
 * **Changes of default values**
   * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`.

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

@@ -509,7 +509,7 @@ namespace Spine.Unity.Editor {
 		}
 
 		static bool UpdateIfSkinMismatch (SkeletonRenderer skeletonRenderer, string componentSkinName) {
-			if (!skeletonRenderer.valid) return false;
+			if (!skeletonRenderer.valid || skeletonRenderer.EditorSkipSkinSync) return false;
 
 			var skin = skeletonRenderer.Skeleton.Skin;
 			string skeletonSkinName = skin != null ? skin.Name : null;

+ 9 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs

@@ -61,6 +61,15 @@ namespace Spine.Unity {
 		/// <summary>Skin name to use when the Skeleton is initialized.</summary>
 		[SerializeField] [SpineSkin(defaultAsEmptyString:true)] public string initialSkinName;
 
+		/// <summary>Enable this parameter when overwriting the Skeleton's skin from an editor script.
+		/// Otherwise any changes will be overwritten by the next inspector update.</summary>
+		#if UNITY_EDITOR
+		public bool EditorSkipSkinSync {
+			get { return editorSkipSkinSync; }
+			set { editorSkipSkinSync = value; }
+		}
+		protected bool editorSkipSkinSync = false;
+		#endif
 		/// <summary>Flip X and Y to use when the Skeleton is initialized.</summary>
 		[SerializeField] public bool initialFlipX, initialFlipY;
 		#endregion