skeletonRenderer.EditorSkipSkinSync = true
Works great!
Here is some reference code for anyone that might want to add a Skin Configuration. It has options to Apply the skins OnStart (or you can apply by calling Activate() at runtime). If you select the SkinApplicationType.ReplaceSkin and check the box for replaceSkinApplyInEditMode then it will apply the skin in Editor mode.
Two notes:
1) I haven't thoroughly tested this, so there could be some corner-case issues. It might be best just to use this for reference and create your own script.
2) I'm using Odin Inspector, so the "ShowIf" and "LabelText" attributes on the replaceSkinApplyInEditMode will only work if you have Odin Inspector.
using Sirenix.OdinInspector;
using Spine;
using Spine.Unity;
using Spine.Unity.AttachmentTools;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class SpineSkinApplicator : MonoBehaviour
{
public SkeletonAnimation targetSkeletonAnimation;
public bool ignoreSkinNotFoundError = false;
public enum AutomaticApplicationOption { None, OnStart }
public AutomaticApplicationOption automaticApplyOption = AutomaticApplicationOption.OnStart;
public enum SkinApplicationType { ReplaceSkin, AddToSkin }
public SkinApplicationType applicationType;
[ShowIf("applicationType", SkinApplicationType.ReplaceSkin)][LabelText("Apply In Edit Mode")] public bool replaceSkinApplyInEditMode = true;
[SpineSkin(dataField = "targetSkeletonAnimation")] public List<string> skinEntries = new List<string>(1);
void Start() {
if (Application.isPlaying == false && applicationType == SkinApplicationType.ReplaceSkin && replaceSkinApplyInEditMode) { Activate(); }
if (Application.isPlaying == true && automaticApplyOption == AutomaticApplicationOption.OnStart) { Activate(); }
}
private void OnValidate() {
if (Application.isPlaying) { return; }
if (targetSkeletonAnimation == null) { targetSkeletonAnimation = GetComponent<SkeletonAnimation>(); }
if (targetSkeletonAnimation != null) {
if (applicationType == SkinApplicationType.ReplaceSkin && replaceSkinApplyInEditMode) {
targetSkeletonAnimation.EditorSkipSkinSync = true;
Activate();
} else {
targetSkeletonAnimation.EditorSkipSkinSync = false;
}
}
}
private void OnDestroy() {
#if UNITY_EDITOR
if (targetSkeletonAnimation != null) {
targetSkeletonAnimation.EditorSkipSkinSync = false;
}
#endif
}
public void Activate() {
if(ValidTargetAndSkeleton() == false) { return; }
switch (applicationType) {
case SkinApplicationType.ReplaceSkin:
ApplyAsReplace();
break;
case SkinApplicationType.AddToSkin:
ApplyAsAddToSkin();
break;
}
}
public void ApplyAsReplace() {
Skin buildSkin = new Skin("buildSkin");
foreach (var skinName in skinEntries) {
var skinCur = targetSkeletonAnimation.skeleton.Data.FindSkin(skinName);
if (skinCur != null) {
buildSkin.AddAttachments(skinCur);
} else {
if (ignoreSkinNotFoundError == false) {
Debug.LogError("Error: skin not found, skinName: " + skinName, gameObject);
}
}
}
targetSkeletonAnimation.skeleton.SetSkin(buildSkin);
targetSkeletonAnimation.skeleton.SetSlotsToSetupPose();
}
public void ApplyAsAddToSkin() {
foreach(string skinName in skinEntries) {
Skin newSkin = targetSkeletonAnimation.skeleton.Data.FindSkin(skinName);
if (newSkin != null) {
Skin currentSkin = targetSkeletonAnimation.skeleton.Skin;
Skin combinedSkin = new Skin("combinedSkin");
combinedSkin.AddSkin(currentSkin);
combinedSkin.AddSkin(newSkin);
targetSkeletonAnimation.skeleton.SetSkin(combinedSkin);
targetSkeletonAnimation.skeleton.SetSlotsToSetupPose();
} else {
if (ignoreSkinNotFoundError == false) {
Debug.LogError("Error: skin not found, skinName: " + skinName, gameObject);
}
}
}
}
public bool ValidTargetAndSkeleton() {
if(targetSkeletonAnimation == null) { return false; }
return targetSkeletonAnimation.skeleton != null;
}
}
Edit: code tweaks