diff --git a/spine-unity/Assets/Spine Examples/Scripts/DataAssetsFromExportsExample.cs b/spine-unity/Assets/Spine Examples/Scripts/RuntimeLoadFromExportsExample.cs similarity index 85% rename from spine-unity/Assets/Spine Examples/Scripts/DataAssetsFromExportsExample.cs rename to spine-unity/Assets/Spine Examples/Scripts/RuntimeLoadFromExportsExample.cs index c7ac58b95..ff21923e4 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/DataAssetsFromExportsExample.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/RuntimeLoadFromExportsExample.cs @@ -32,13 +32,17 @@ using System.Collections.Generic; using UnityEngine; namespace Spine.Unity.Examples { - public class DataAssetsFromExportsExample : MonoBehaviour { + public class RuntimeLoadFromExportsExample : MonoBehaviour { public TextAsset skeletonJson; public TextAsset atlasText; public Texture2D[] textures; public Material materialPropertySource; + public float delay = 0; + public string skinName; + public string animationName; + SpineAtlasAsset runtimeAtlasAsset; SkeletonDataAsset runtimeSkeletonDataAsset; SkeletonAnimation runtimeSkeletonAnimation; @@ -54,19 +58,19 @@ namespace Spine.Unity.Examples { IEnumerator Start () { CreateRuntimeAssetsAndGameObject(); - runtimeSkeletonDataAsset.GetSkeletonData(false); // preload. - yield return new WaitForSeconds(0.5f); - + if (delay > 0) { + runtimeSkeletonDataAsset.GetSkeletonData(false); // preload + yield return new WaitForSeconds(delay); + } runtimeSkeletonAnimation = SkeletonAnimation.NewSkeletonAnimationGameObject(runtimeSkeletonDataAsset); - // Extra Stuff + // additional initialization runtimeSkeletonAnimation.Initialize(false); - runtimeSkeletonAnimation.Skeleton.SetSkin("base"); + if (skinName != "") + runtimeSkeletonAnimation.Skeleton.SetSkin(skinName); runtimeSkeletonAnimation.Skeleton.SetSlotsToSetupPose(); - runtimeSkeletonAnimation.AnimationState.SetAnimation(0, "run", true); - runtimeSkeletonAnimation.GetComponent().sortingOrder = 10; - runtimeSkeletonAnimation.transform.Translate(Vector3.down * 2); - + if (animationName != "") + runtimeSkeletonAnimation.AnimationState.SetAnimation(0, animationName, true); } } diff --git a/spine-unity/Assets/Spine Examples/Scripts/DataAssetsFromExportsExample.cs.meta b/spine-unity/Assets/Spine Examples/Scripts/RuntimeLoadFromExportsExample.cs.meta similarity index 100% rename from spine-unity/Assets/Spine Examples/Scripts/DataAssetsFromExportsExample.cs.meta rename to spine-unity/Assets/Spine Examples/Scripts/RuntimeLoadFromExportsExample.cs.meta diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs index 069a81a09..3de82334b 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs @@ -38,7 +38,6 @@ namespace Spine.Unity.Editor { public class SkeletonAnimationInspector : SkeletonRendererInspector { protected SerializedProperty animationName, loop, timeScale, autoReset; protected bool wasAnimationParameterChanged = false; - protected bool requireRepaint; readonly GUIContent LoopLabel = new GUIContent("Loop", "Whether or not .AnimationName should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected."); readonly GUIContent TimeScaleLabel = new GUIContent("Time Scale", "The rate at which animations progress over time. 1 means normal speed. 0.5 means 50% speed."); @@ -79,13 +78,6 @@ namespace Spine.Unity.Editor { SkeletonRootMotionParameter(); serializedObject.ApplyModifiedProperties(); - - if (!isInspectingPrefab) { - if (requireRepaint) { - UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); - requireRepaint = false; - } - } } protected void TrySetAnimation (SkeletonAnimation skeletonAnimation) { diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs index f1d9373b3..a4ad0b6b1 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs @@ -70,6 +70,8 @@ namespace Spine.Unity.Editor { protected SerializedProperty maskInteraction; protected SerializedProperty maskMaterialsNone, maskMaterialsInside, maskMaterialsOutside; protected SpineInspectorUtility.SerializedSortingProperties sortingProperties; + protected bool wasInitParameterChanged = false; + protected bool requireRepaint = false; protected bool isInspectingPrefab; protected bool forceReloadQueued = false; @@ -196,6 +198,13 @@ namespace Spine.Unity.Editor { SceneView.RepaintAll(); } } + + if (!isInspectingPrefab) { + if (requireRepaint) { + UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); + requireRepaint = false; + } + } } protected virtual void DrawInspectorGUI (bool multi) { @@ -259,6 +268,9 @@ namespace Spine.Unity.Editor { bool valid = TargetIsValid; + foreach (var o in targets) + ApplyModifiedMeshParameters(o as SkeletonRenderer); + // Fields. if (multi) { using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) { @@ -330,8 +342,10 @@ namespace Spine.Unity.Editor { using (new SpineInspectorUtility.IndentScope()) { using (new EditorGUILayout.HorizontalScope()) { + EditorGUI.BeginChangeCheck(); SpineInspectorUtility.ToggleLeftLayout(initialFlipX); SpineInspectorUtility.ToggleLeftLayout(initialFlipY); + wasInitParameterChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update. EditorGUILayout.Space(); } @@ -421,6 +435,23 @@ namespace Spine.Unity.Editor { } } + protected void ApplyModifiedMeshParameters (SkeletonRenderer skeletonRenderer) { + if (skeletonRenderer == null) return; + if (!skeletonRenderer.valid) + return; + + if (!isInspectingPrefab) { + if (wasInitParameterChanged) { + wasInitParameterChanged = false; + if (!Application.isPlaying) { + skeletonRenderer.Initialize(true); + skeletonRenderer.LateUpdate(); + requireRepaint = true; + } + } + } + } + protected void SkeletonRootMotionParameter () { SkeletonRootMotionParameter(targets); } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs index c5e0b4365..d5b3a48e8 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs @@ -118,11 +118,12 @@ namespace Spine.Unity.Editor { static readonly AttachmentType[] AtlasTypes = { AttachmentType.Region, AttachmentType.Linkedmesh, AttachmentType.Mesh }; public static List GetRequiredAtlasRegions (string skeletonDataPath) { - List requiredPaths = new List(); + HashSet requiredPaths = new HashSet(); if (skeletonDataPath.Contains(".skel")) { - AddRequiredAtlasRegionsFromBinary(skeletonDataPath, requiredPaths); - return requiredPaths; + List requiredPathsResult = new List(); + AddRequiredAtlasRegionsFromBinary(skeletonDataPath, requiredPathsResult); + return requiredPathsResult; } TextReader reader = null; @@ -143,11 +144,11 @@ namespace Spine.Unity.Editor { } if (root == null || !root.ContainsKey("skins")) - return requiredPaths; + return new List(); var skinsList = root["skins"] as List; if (skinsList == null) - return requiredPaths; + return new List(); foreach (Dictionary skinMap in skinsList) { if (!skinMap.ContainsKey("attachments")) @@ -189,7 +190,7 @@ namespace Spine.Unity.Editor { } } - return requiredPaths; + return requiredPaths.ToList(); } internal static void AddRequiredAtlasRegionsFromBinary (string skeletonDataPath, List requiredPaths) { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs index 81cc9af06..ab3a98650 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs @@ -181,7 +181,10 @@ namespace Spine.Unity { var drawOrderItems = drawOrder.Items; for (int i = 0; i < drawOrderCount; i++) { Slot slot = drawOrderItems[i]; - if (!slot.Bone.Active) continue; + if (!slot.Bone.Active) { + workingAttachmentsItems[i] = null; + continue; + } if (slot.Data.BlendMode == BlendMode.Additive) current.hasPMAAdditiveSlot = true; Attachment attachment = slot.Attachment; @@ -303,7 +306,10 @@ namespace Spine.Unity { var drawOrderItems = drawOrder.Items; for (int i = 0; i < drawOrderCount; i++) { Slot slot = drawOrderItems[i]; - if (!slot.Bone.Active) continue; + if (!slot.Bone.Active) { + workingAttachmentsItems[i] = null; + continue; + } if (slot.Data.BlendMode == BlendMode.Additive) current.hasPMAAdditiveSlot = true; Attachment attachment = slot.Attachment; #if SPINE_TRIANGLECHECK