/// <summary> /// 전체 스킨 변경 /// </summary> /// <param name="_ArmorLevel">방어구 레벨</param> /// <param name="_SwordLevel">무기 레벨</param> public void SetSkinCombine(int _ArmorLevel, int _SwordLevel) { // 두 개 이상의 스킨을 동시에 그리는 방법!! // Spine.Skin을 할당해서 skeleton에 주는 방법 Skeleton skeleton = m_UIAnimation.Skeleton; SkeletonData skelData = skeleton.Data; //var LevelAmor = skelData.FindSkin(ArmorSkinName); //var LevelSword = skelData.FindSkin(SwordSkinName); // {0}/{1} - SpineAnimation 내에 스킨이 파일별로 분류가 되있기 때문에 // {해당 스킨이 든 파일 명} / {해당 스킨} 으로 스킨명을 해주어야 한다. var LevelArmor = skelData.FindSkin(string.Format("{0}/{1}", ArmorSkinName, SetArmorSkin(_ArmorLevel))); var LevelSword = skelData.FindSkin(string.Format("{0}/{1}", SwordSkinName, SetSwordSkin(_SwordLevel))); Skin newSkin = new Skin("Hero Skin"); newSkin.AddSkin(LevelArmor); newSkin.AddSkin(LevelSword); skeleton.SetSkin(newSkin); skeleton.SetSlotsToSetupPose(); //m_UIAnimation.Update(0); }
void UpdateCharacterSkin() { var skeleton = skeletonAnimation.Skeleton; var skeletonData = skeleton.Data; characterSkin = new Skin("character-base"); // Note that the result Skin returned by calls to skeletonData.FindSkin() // could be cached once in Start() instead of searching for the same skin // every time. For demonstration purposes we keep it simple here. characterSkin.AddSkin(skeletonData.FindSkin(baseSkin)); characterSkin.AddSkin(skeletonData.FindSkin(noseSkins[activeNoseIndex])); characterSkin.AddSkin(skeletonData.FindSkin(eyelidsSkin)); characterSkin.AddSkin(skeletonData.FindSkin(eyesSkins[activeEyesIndex])); characterSkin.AddSkin(skeletonData.FindSkin(hairSkins[activeHairIndex])); }
void Start() { var skeletonComponent = GetComponent <ISkeletonComponent>(); if (skeletonComponent == null) { return; } var skeleton = skeletonComponent.Skeleton; if (skeleton == null) { return; } combinedSkin = combinedSkin ?? new Skin("combined"); combinedSkin.Clear(); foreach (var skinName in skinsToCombine) { var skin = skeleton.Data.FindSkin(skinName); if (skin != null) { combinedSkin.AddSkin(skin); } } skeleton.SetSkin(combinedSkin); skeleton.SetToSetupPose(); var animationStateComponent = skeletonComponent as IAnimationStateComponent; if (animationStateComponent != null) { animationStateComponent.AnimationState.Apply(skeleton); } }
void AddEquipmentSkinsTo(Skin combinedSkin) { var skeleton = skeletonAnimation.Skeleton; var skeletonData = skeleton.Data; combinedSkin.AddSkin(skeletonData.FindSkin(clothesSkin)); combinedSkin.AddSkin(skeletonData.FindSkin(pantsSkin)); if (!string.IsNullOrEmpty(bagSkin)) { combinedSkin.AddSkin(skeletonData.FindSkin(bagSkin)); } if (!string.IsNullOrEmpty(hatSkin)) { combinedSkin.AddSkin(skeletonData.FindSkin(hatSkin)); } }
void UpdateCombinedSkin() { var skeleton = skeletonAnimation.Skeleton; var resultCombinedSkin = new Skin("character-combined"); resultCombinedSkin.AddSkin(characterSkin); AddEquipmentSkinsTo(resultCombinedSkin); skeleton.SetSkin(resultCombinedSkin); skeleton.SetSlotsToSetupPose(); }
public override void SetUpEnteringOnBattle() { CharacterAnimationStateType animType = (CharacterAnimationStateType)System.Enum.Parse(typeof(CharacterAnimationStateType), CharacterAnimationStateType.Growing.ToString() + Random.Range(1, 3).ToString()); SetAnimation(animType); StartCoroutine(base.MoveByTileSpeed(GridManagerScript.Instance.GetBattleTile(UMS.Pos[0]).transform.position, SpineAnim.CurveType == MovementCurveType.Space_Time ? SpineAnim.Space_Time_Curves.UpMovement : SpineAnim.Speed_Time_Curves.UpMovement, SpineAnim.GetAnimLenght(animType))); Skin newSkin = new Skin("new-skin"); // 1. Create a new empty skin newSkin.AddSkin(SpineAnim.skeleton.Data.FindSkin(mfType.ToString())); // 2. Add items SpineAnim.skeleton.SetSkin(mfType.ToString()); SpineAnim.skeleton.SetSlotsToSetupPose(); SpineAnim.SpineAnimationState.Apply(SpineAnim.skeleton); }
public static void SetAnimation(this ISkeletonAnimation anim, List <string> skinMix) { var skeleton = anim.Skeleton; // var animState = (IAnimationStateComponent) (anim); var skeletonData = skeleton.Data; var mixAndMatchSkin = new Skin(skinMix[0]); foreach (var skinName in skinMix) { mixAndMatchSkin.AddSkin(skeletonData.FindSkin(skinName)); } skeleton.SetSkin(mixAndMatchSkin); skeleton.SetSlotsToSetupPose(); }
public void SetSkin(string _name) { //m_UIAnimation.Skeleton.SetSkin(_name); Skeleton skeleton = m_UIAnimation.Skeleton; SkeletonData skelData = skeleton.Data; var skin = skelData.FindSkin(_name); Skin newSkin = new Skin("Monster Skin"); newSkin.AddSkin(skin); skeleton.SetSkin(newSkin); skeleton.SetSlotsToSetupPose(); }
public static void SetAnimation(this ISkeletonAnimation anim, string nameAnim, List <string> skinMix, bool loop = false, Action onComplete = null) { var skeleton = anim.Skeleton; var animState = (IAnimationStateComponent)(anim); var skeletonData = skeleton.Data; var mixAndMatchSkin = new Skin(skinMix[0]); foreach (var skinName in skinMix) { mixAndMatchSkin.AddSkin(skeletonData.FindSkin(skinName)); } skeleton.SetSkin(mixAndMatchSkin); skeleton.SetSlotsToSetupPose(); var spine = animState.AnimationState.SetAnimation(1, nameAnim, loop); spine.Complete += entry => onComplete?.Invoke(); }
public Pack LoadSkeleton(string jsonFile, string atlasFile, string animation, string skin, float scale, float x, float y) { Atlas atlas = new Atlas(assetsFolder + atlasFile + ".atlas", new LoveTextureLoader()); var json = new SkeletonJson(atlas); json.Scale = scale; var skeletonData = json.ReadSkeletonData(assetsFolder + jsonFile + ".json"); var skeleton = new Skeleton(skeletonData); skeleton.X = x; skeleton.Y = y; skeleton.ScaleY = -1; if (skin != null) { skeleton.SetSkin(skin); } skeleton.SetToSetupPose(); var stateData = new AnimationStateData(skeletonData); var state = new AnimationState(stateData); state.SetAnimation(0, animation, true); if (jsonFile == "spineboy-ess") { stateData.SetMix("walk", "jump", 0.5f); stateData.SetMix("jump", "run", 0.5f); state.AddAnimation(0, "jump", false, 3); state.AddAnimation(0, "run", true, 0); } if (jsonFile == "raptor-pro") { swirl.CenterY = -200; //skeleton.VertexEffect = swirl; } if (jsonFile == "mix-and-match-pro") { // Create a new skin, by mixing and matching other skins // that fit together. Items making up the girl are individual // skins. Using the skin API, a new skin is created which is // a combination of all these individual item skins. var lskin = new Skin("mix-and-match"); lskin.AddSkin(skeletonData.FindSkin("skin-base")); lskin.AddSkin(skeletonData.FindSkin("nose/short")); lskin.AddSkin(skeletonData.FindSkin("eyelids/girly")); lskin.AddSkin(skeletonData.FindSkin("eyes/violet")); lskin.AddSkin(skeletonData.FindSkin("hair/brown")); lskin.AddSkin(skeletonData.FindSkin("clothes/hoodie-orange")); lskin.AddSkin(skeletonData.FindSkin("legs/pants-jeans")); lskin.AddSkin(skeletonData.FindSkin("accessories/bag")); lskin.AddSkin(skeletonData.FindSkin("accessories/hat-red-yellow")); skeleton.SetSkin(lskin); } // set some event callbacks state.Start += (entry) => Console.WriteLine(entry.TrackIndex + " start: " + entry.Animation.Name); state.Interrupt += (entry) => Console.WriteLine(entry.TrackIndex + " interrupt: " + entry.Animation.Name); state.End += (entry) => Console.WriteLine(entry.TrackIndex + " end: " + entry.Animation.Name); state.Complete += (entry) => Console.WriteLine(entry.TrackIndex + " complete: " + entry.Animation.Name); state.Dispose += (entry) => Console.WriteLine(entry.TrackIndex + " dispose: " + entry.Animation.Name); state.Event += (entry, e) => Console.WriteLine( entry.TrackIndex + " event: " + entry.Animation.Name + ", " + e.Data.Name + ", " + e.Int + ", " + e.Float + ", '" + e.String + "'" + ", " + e.Volume + ", " + e.Balance ); state.Update(0.5f); state.Apply(skeleton); return(new Pack(skeleton, state)); }
//Applies the chosen gear on the character public void ApplySkinChanges() { if (characterAnimator == null) { characterAnimator = transform.GetChild(0).GetComponent <SkeletonAnimation>(); if (characterAnimator == null) { Debug.Log("Check that the character gameobject has a SkeletonAnimation child"); } return; } //Gets the skeleton and its data from the character gameobject var skeleton = characterAnimator.Skeleton; var skeletonData = skeleton.Data; //Creates a new custom skin var NewCustomSkin = new Skin("CustomCharacter"); //Combines the skins based on the gear choices if (Job == Jobs.Warrior) { NewCustomSkin.AddSkin(skeletonData.FindSkin("MELEE " + Melee.ToString())); if (Shield == 0) { NewCustomSkin.AddSkin(skeletonData.FindSkin("EMPTY")); } else { NewCustomSkin.AddSkin(skeletonData.FindSkin("SHIELD " + (Shield - 1).ToString())); } } else if (Job == Jobs.Archer) { NewCustomSkin.AddSkin(skeletonData.FindSkin("BOW " + Bow.ToString())); NewCustomSkin.AddSkin(skeletonData.FindSkin("QUIVER " + Quiver.ToString())); } else if (Job == Jobs.Elementalist) { NewCustomSkin.AddSkin(skeletonData.FindSkin("STAFF " + Staff.ToString())); } else if (Job == Jobs.Duelist) { NewCustomSkin.AddSkin(skeletonData.FindSkin("OFFHAND " + DuelistOffhand.ToString())); NewCustomSkin.AddSkin(skeletonData.FindSkin("MELEE " + Melee.ToString())); } NewCustomSkin.AddSkin(skeletonData.FindSkin("ARMOR " + Armor.ToString())); NewCustomSkin.AddSkin(skeletonData.FindSkin("ARMOR " + Armor.ToString())); NewCustomSkin.AddSkin(skeletonData.FindSkin("ARMOR " + Armor.ToString())); NewCustomSkin.AddSkin(skeletonData.FindSkin("ARMOR " + Armor.ToString())); if (Helmet == 0) { NewCustomSkin.AddSkin(skeletonData.FindSkin("EMPTY")); } else { NewCustomSkin.AddSkin(skeletonData.FindSkin("HELMET " + Helmet.ToString())); } NewCustomSkin.AddSkin(skeletonData.FindSkin("SHOULDER " + Shoulder.ToString())); NewCustomSkin.AddSkin(skeletonData.FindSkin("ARM " + Arm.ToString())); NewCustomSkin.AddSkin(skeletonData.FindSkin("FEET " + Feet.ToString())); NewCustomSkin.AddSkin(skeletonData.FindSkin("HAIR " + Hair.ToString())); NewCustomSkin.AddSkin(skeletonData.FindSkin("EYES " + Face.ToString())); //Sets the new created skin on the character SkeletonAnimation skeleton.SetSkin(NewCustomSkin); skeleton.SetSlotsToSetupPose(); }
void Apply() { var skeletonAnimation = GetComponent <SkeletonAnimation>(); var skeleton = skeletonAnimation.Skeleton; // STEP 0: PREPARE SKINS // Let's prepare a new skin to be our custom skin with equips/customizations. We get a clone so our original skins are unaffected. customSkin = customSkin ?? new Skin("custom skin"); // This requires that all customizations are done with skin placeholders defined in Spine. var templateSkin = skeleton.Data.FindSkin(templateAttachmentsSkin); // STEP 1: "EQUIP" ITEMS USING SPRITES // STEP 1.1 Find the original/template attachment. // Step 1.2 Get a clone of the original/template attachment. // Step 1.3 Apply the Sprite image to the clone. // Step 1.4 Add the remapped clone to the new custom skin. // Let's do this for the visor. int visorSlotIndex = skeleton.Data.FindSlot(visorSlot).Index; // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster. Attachment templateAttachment = templateSkin.GetAttachment(visorSlotIndex, visorKey); // STEP 1.1 // Note: Each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` creates // a cached Texture copy which can be cleared by calling AtlasUtilities.ClearCache() as done in the method below. Attachment newAttachment = templateAttachment.GetRemappedClone(visorSprite, sourceMaterial, pivotShiftsMeshUVCoords: false); // STEP 1.2 - 1.3 customSkin.SetAttachment(visorSlotIndex, visorKey, newAttachment); // STEP 1.4 // And now for the gun. int gunSlotIndex = skeleton.Data.FindSlot(gunSlot).Index; Attachment templateGun = templateSkin.GetAttachment(gunSlotIndex, gunKey); // STEP 1.1 Attachment newGun = templateGun.GetRemappedClone(gunSprite, sourceMaterial, pivotShiftsMeshUVCoords: false); // STEP 1.2 - 1.3 if (newGun != null) { customSkin.SetAttachment(gunSlotIndex, gunKey, newGun); // STEP 1.4 } // customSkin.RemoveAttachment(gunSlotIndex, gunKey); // To remove an item. // customSkin.Clear() // Use skin.Clear() To remove all customizations. // Customizations will fall back to the value in the default skin if it was defined there. // To prevent fallback from happening, make sure the key is not defined in the default skin. // STEP 3: APPLY AND CLEAN UP. // Recommended, preferably at level-load-time: REPACK THE CUSTOM SKIN TO MINIMIZE DRAW CALLS // IMPORTANT NOTE: the GetRepackedSkin() operation is expensive - if multiple characters // need to call it every few seconds the overhead will outweigh the draw call benefits. // // Repacking requires that you set all source textures/sprites/atlases to be Read/Write enabled in the inspector. // Combine all the attachment sources into one skin. Usually this means the default skin and the custom skin. // call Skin.GetRepackedSkin to get a cloned skin with cloned attachments that all use one texture. if (repack) { var repackedSkin = new Skin("repacked skin"); repackedSkin.AddSkin(skeleton.Data.DefaultSkin); // Include the "default" skin. (everything outside of skin placeholders) repackedSkin.AddSkin(customSkin); // Include your new custom skin. // Note: materials and textures returned by GetRepackedSkin() behave like 'new Texture2D()' and need to be destroyed if (runtimeMaterial) { Destroy(runtimeMaterial); } if (runtimeAtlas) { Destroy(runtimeAtlas); } repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas); // Pack all the items in the skin. skeleton.SetSkin(repackedSkin); // Assign the repacked skin to your Skeleton. if (bbFollower != null) { bbFollower.Initialize(true); } } else { skeleton.SetSkin(customSkin); // Just use the custom skin directly. } skeleton.SetSlotsToSetupPose(); // Use the pose from setup pose. skeletonAnimation.Update(0); // Use the pose in the currently active animation. // `GetRepackedSkin()` and each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` // cache necessarily created Texture copies which can be cleared by calling AtlasUtilities.ClearCache(). // You can optionally clear the textures cache after multiple repack operations. // Just be aware that while this cleanup frees up memory, it is also a costly operation // and will likely cause a spike in the framerate. AtlasUtilities.ClearCache(); Resources.UnloadUnusedAssets(); }
void Apply() { var skeletonGraphic = GetComponent <SkeletonGraphic>(); var skeleton = skeletonGraphic.Skeleton; // STEP 0: PREPARE SKINS // Let's prepare a new skin to be our custom skin with equips/customizations. We get a clone so our original skins are unaffected. customSkin = customSkin ?? new Skin("custom skin"); // This requires that all customizations are done with skin placeholders defined in Spine. // Next let's get the skin that contains our source attachments. These are the attachments that var baseSkin = skeleton.Data.FindSkin(baseSkinName); // STEP 1: "EQUIP" ITEMS USING SPRITES // STEP 1.1 Find the original attachment. // Step 1.2 Get a clone of the original attachment. // Step 1.3 Apply the Sprite image to it. // Step 1.4 Add the remapped clone to the new custom skin. // Let's do this for the visor. int visorSlotIndex = skeleton.Data.FindSlot(visorSlot).Index; // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster. Attachment baseAttachment = baseSkin.GetAttachment(visorSlotIndex, visorKey); // STEP 1.1 // Note: Each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` creates // a cached Texture copy which can be cleared by calling AtlasUtilities.ClearCache() as done below. Attachment newAttachment = baseAttachment.GetRemappedClone(visorSprite, sourceMaterial); // STEP 1.2 - 1.3 customSkin.SetAttachment(visorSlotIndex, visorKey, newAttachment); // STEP 1.4 // And now for the gun. int gunSlotIndex = skeleton.Data.FindSlot(gunSlot).Index; Attachment baseGun = baseSkin.GetAttachment(gunSlotIndex, gunKey); // STEP 1.1 Attachment newGun = baseGun.GetRemappedClone(gunSprite, sourceMaterial); // STEP 1.2 - 1.3 if (newGun != null) { customSkin.SetAttachment(gunSlotIndex, gunKey, newGun); // STEP 1.4 } // customSkin.RemoveAttachment(gunSlotIndex, gunKey); // To remove an item. // customSkin.Clear() // Use skin.Clear() To remove all customizations. // Customizations will fall back to the value in the default skin if it was defined there. // To prevent fallback from happening, make sure the key is not defined in the default skin. // STEP 3: APPLY AND CLEAN UP. // Recommended: REPACK THE CUSTOM SKIN TO MINIMIZE DRAW CALLS // Repacking requires that you set all source textures/sprites/atlases to be Read/Write enabled in the inspector. // Combine all the attachment sources into one skin. Usually this means the default skin and the custom skin. // call Skin.GetRepackedSkin to get a cloned skin with cloned attachments that all use one texture. if (repack) { var repackedSkin = new Skin("repacked skin"); repackedSkin.AddSkin(skeleton.Data.DefaultSkin); repackedSkin.AddSkin(customSkin); // Note: materials and textures returned by GetRepackedSkin() behave like 'new Texture2D()' and need to be destroyed if (runtimeMaterial) { Destroy(runtimeMaterial); } if (runtimeAtlas) { Destroy(runtimeAtlas); } repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas); skeleton.SetSkin(repackedSkin); } else { skeleton.SetSkin(customSkin); } //skeleton.SetSlotsToSetupPose(); skeleton.SetToSetupPose(); skeletonGraphic.Update(0); skeletonGraphic.OverrideTexture = runtimeAtlas; // `GetRepackedSkin()` and each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` // cache necessarily created Texture copies which can be cleared by calling AtlasUtilities.ClearCache(). // You can optionally clear the textures cache after multiple repack operations. // Just be aware that while this cleanup frees up memory, it is also a costly operation // and will likely cause a spike in the framerate. AtlasUtilities.ClearCache(); Resources.UnloadUnusedAssets(); }