Exemple #1
0
        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.Append(skin);
                }
            }

            skeleton.SetSkin(combinedSkin);
            skeleton.SetToSetupPose();
            var animationStateComponent = skeletonComponent as IAnimationStateComponent;

            if (animationStateComponent != null)
            {
                animationStateComponent.AnimationState.Apply(skeleton);
            }
        }
Exemple #2
0
        private System.Collections.IEnumerator TexturePackaged(SkeletonAnimation skeleAnim, CombineTextureData combineTextureData)
        {
            combineTextureData.isFinished = false;
            Skin skin = new Skin(SpineConstValue.NewSkinname);

            skin.Append(skeleAnim.skeleton.data.DefaultSkin);
            System.DateTime time1 = System.DateTime.Now;
            GetRepackedFromSkin(combineTextureData, skin, SpineConstValue.NewSkinname, Shader.Find(SpineConstValue.shaderPath));
            while (!combineTextureData.isFinished)
            {
                yield return(null);
            }
            System.DateTime time2 = System.DateTime.Now;
            if (null != GameObject.FindObjectOfType <ChangeTest> ())
            {
                GameObject.FindObjectOfType <ChangeTest> ().text.text += "合并图集用时:" + (time2 - time1).TotalMilliseconds + "\n";
            }
            if (combineTextureData.isFinished)
            {
                skeleAnim.skeleton.SetSkin(combineTextureData.resultData.skin);
                skeleAnim.skeleton.data.defaultSkin = combineTextureData.resultData.skin;
                combineTextureData.resultData.self.DestroyEquipment();
                DestroyResources(combineTextureData);
            }
        }
        public void ExchangeEquipmentAndMergeUI(SkeletonGraphic skeletonAnimation, List <EquipmentItem> infos)
        {
            for (int i = 0; i < infos.Count; i++)
            {
                EquipmentItem      info               = infos[i];
                string             regionName         = info.equipmentImageName;
                string             defaultSkinName    = info.defaultSkinName;
                string             spineEquipmentType = info.spineEquipmentTypeName;
                AssetBundlePackage assetbundle        = HFResourceManager.Instance.LoadAssetBundleFromFile(info.equipmentAssetbundleName);
                AtlasAsset         atlasAsset         = assetbundle.LoadAssetWithCache <AtlasAsset>(info.equipmentAtlasAssetName);
                float       scale              = skeletonAnimation.skeletonDataAsset.scale;
                Atlas       atlas              = atlasAsset.GetAtlas();
                AtlasRegion region             = atlas.FindRegion(regionName);
                Slot        slot               = skeletonAnimation.Skeleton.FindSlot(info.slotName);
                Attachment  originalAttachment = slot.Attachment;
                if (region == null)
                {
                    HFLog.C("没有找到图集里的 : 图片  " + regionName);
                    slot.Attachment = null;
                }
                else if (originalAttachment != null)
                {
                    slot.Attachment = originalAttachment.GetRemappedClone(region, true, true, 1);
                }
                else
                {
                    var newRegionAttachment = region.ToRegionAttachment(region.name, scale);
                    slot.Attachment = newRegionAttachment;
                }
                slot.Skeleton.Skin.SetAttachment(slot.Data.Index, info.slotPlaceholderName, slot.Attachment);
            }

            Skin repackedSkin = new Skin(RepackConst);

            repackedSkin.Append(skeletonAnimation.Skeleton.Data.DefaultSkin); // Include the "default" skin. (everything outside of skin placeholders)
            repackedSkin.Append(skeletonAnimation.Skeleton.Skin);             // Include your new custom skin.
            Texture2D runtimeAtlas    = null;
            Material  runtimeMaterial = null;

            repackedSkin = repackedSkin.GetRepackedSkin(RepackConst, skeletonAnimation.SkeletonDataAsset.atlasAssets[0].materials[0], out runtimeMaterial, out runtimeAtlas); // Pack all the items in the skin.
            skeletonAnimation.Skeleton.SetSkin(repackedSkin);                                                                                                                 // Assign the repacked skin to your Skeleton.
            skeletonAnimation.Skeleton.SetSlotsToSetupPose();                                                                                                                 // Use the pose from setup pose.
            skeletonAnimation.Update(0);                                                                                                                                      // Use the pose in the currently active animation.
            skeletonAnimation.OverrideTexture = runtimeAtlas;
        }
        private void Apply()
        {
            SkeletonAnimation component = base.GetComponent <SkeletonAnimation>();
            Skeleton          skeleton  = component.Skeleton;

            if (this.customSkin == null)
            {
            }
            this.customSkin = new Skin("custom skin");
            Skin       skin       = skeleton.Data.FindSkin(this.templateAttachmentsSkin);
            int        slotIndex  = skeleton.FindSlotIndex(this.visorSlot);
            Attachment attachment = skin.GetAttachment(slotIndex, this.visorKey).GetRemappedClone(this.visorSprite, this.sourceMaterial, true, true, false);

            this.customSkin.SetAttachment(slotIndex, this.visorKey, attachment);
            int        num2        = skeleton.FindSlotIndex(this.gunSlot);
            Attachment attachment4 = skin.GetAttachment(num2, this.gunKey).GetRemappedClone(this.gunSprite, this.sourceMaterial, true, true, false);

            if (attachment4 != null)
            {
                this.customSkin.SetAttachment(num2, this.gunKey, attachment4);
            }
            if (this.repack)
            {
                Skin destination = new Skin("repacked skin");
                destination.Append(skeleton.Data.DefaultSkin);
                destination.Append(this.customSkin);
                destination = destination.GetRepackedSkin("repacked skin", this.sourceMaterial, out this.runtimeMaterial, out this.runtimeAtlas, 0x400, 2, TextureFormat.RGBA32, false, true);
                skeleton.SetSkin(destination);
                if (this.bbFollower != null)
                {
                    this.bbFollower.Initialize(true);
                }
            }
            else
            {
                skeleton.SetSkin(this.customSkin);
            }
            skeleton.SetSlotsToSetupPose();
            component.Update(0f);
            Resources.UnloadUnusedAssets();
        }
Exemple #5
0
        private void Start()
        {
            var slotIndex          = _skeletonAnimation.skeleton.FindSlotIndex("sword");
            var templateSkin       = _skeletonAnimation.SkeletonDataAsset.GetSkeletonData(false).FindSkin("default");
            var templateAttachment = templateSkin.GetAttachment(slotIndex, "sword");
            var attachment         = templateAttachment.GetRemappedClone(_attachment,
                                                                         _skeletonAnimation.skeletonDataAsset.atlasAssets[0].materials[0], true);
            var skin = new Skin("EquipSkin");

            skin.Append(_skeletonAnimation.SkeletonDataAsset.GetSkeletonData(false).FindSkin("knight"));
            skin.AddAttachment(slotIndex, "sword", attachment);
            _skeletonAnimation.Skeleton.SetSkin(skin);
            _skeletonAnimation.Skeleton.SetSlotsToSetupPose();
        }
Exemple #6
0
        public void EquipNewSprite(string animationName, Sprite sprite)
        {
            EquipData data = GetEquipData(animationName);

            if (data == null)
            {
                Log.e("Error, equip data is null");
                return;
            }
            //sprite = SpriteLoader.S.GetSpriteByName("bing_1");
            //sprite = Resources.Load("bing_1", typeof(Sprite)) as Sprite;

            int        slotIndex      = skeleton.FindSlotIndex(data.slot);
            Attachment baseAttachment = baseSkin.GetAttachment(slotIndex, data.key);             // STEP 1.1
            Attachment newAttachment  = baseAttachment.GetRemappedClone(sprite, sourceMaterial); // STEP 1.2 - 1.3

            if (newAttachment != null)
            {
                customSkin.SetAttachment(slotIndex, data.key, newAttachment);                        // STEP 1.4
            }
            if (repack)
            {
                var repackedSkin = new Skin("repacked skin");
                repackedSkin.Append(skeleton.Data.DefaultSkin);
                repackedSkin.Append(customSkin);
                repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas);
                skeleton.SetSkin(repackedSkin);
            }
            else
            {
                skeleton.SetSkin(customSkin);
            }

            skeleton.SetToSetupPose();
            skeletonGraphic.Update(0);
            skeletonGraphic.OverrideTexture = runtimeAtlas;
        }
Exemple #7
0
        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.
            //customSkin = customSkin ?? skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState); // use this if you are not customizing on the default skin and don't plan to remove
            // Next let's
            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 the clone.
            // Step 1.4 Add the remapped clone to the new custom skin.

            // Let's do this for the visor.
            int        visorSlotIndex = skeleton.FindSlotIndex(visorSlot);                            // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster.
            Attachment baseAttachment = baseSkin.GetAttachment(visorSlotIndex, visorKey);             // STEP 1.1
            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.FindSlotIndex(gunSlot);
            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.
            //				Under the hood, this relies on
            if (repack)
            {
                var repackedSkin = new Skin("repacked skin");
                repackedSkin.Append(skeleton.Data.DefaultSkin);
                repackedSkin.Append(customSkin);
                repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas);
                skeleton.SetSkin(repackedSkin);
                if (bbFollower != null)
                {
                    bbFollower.Initialize(true);
                }
            }
            else
            {
                skeleton.SetSkin(customSkin);
            }

            skeleton.SetSlotsToSetupPose();
            skeletonAnimation.Update(0);

            Resources.UnloadUnusedAssets();
        }