예제 #1
0
        public Sprite GenerateSprite(string name, out Material material)
        {
            AtlasRegion region = atlas.FindRegion(name);

            Sprite sprite = null;

            material = null;

            if (region != null)
            {
                //sprite.rect
            }

            return(sprite);
        }
    static AtlasAsset GetMatchingAtlas(List <string> requiredPaths, List <AtlasAsset> atlasAssets)
    {
        AtlasAsset atlasAssetMatch = null;

        foreach (AtlasAsset a in atlasAssets)
        {
            Atlas atlas  = a.GetAtlas();
            bool  failed = false;
            foreach (string regionPath in requiredPaths)
            {
                if (atlas.FindRegion(regionPath) == null)
                {
                    failed = true;
                    break;
                }
            }

            if (!failed)
            {
                atlasAssetMatch = a;
                break;
            }
        }

        return(atlasAssetMatch);
    }
예제 #3
0
        }                         // Allow checkbox in inspector

        void Apply(SkeletonRenderer skeletonRenderer)
        {
            if (!this.enabled)
            {
                return;
            }

            atlas = atlasAsset.GetAtlas();
            float scale = skeletonRenderer.skeletonDataAsset.scale;

            foreach (var entry in attachments)
            {
                Slot        slot = skeletonRenderer.Skeleton.FindSlot(entry.slot);
                Attachment  originalAttachment = slot.Attachment;
                AtlasRegion region             = atlas.FindRegion(entry.region);

                if (region == null)
                {
                    slot.Attachment = null;
                }
                else if (inheritProperties && originalAttachment != null)
                {
                    slot.Attachment = originalAttachment.GetRemappedClone(region, true, true, scale);
                }
                else
                {
                    var newRegionAttachment = region.ToRegionAttachment(region.name, scale);
                    slot.Attachment = newRegionAttachment;
                }
            }
        }
예제 #4
0
    static AtlasAsset GetMatchingAtlas(List <string> requiredPaths, List <AtlasAsset> atlasAssets)
    {
        AtlasAsset atlasAssetMatch = null;

        foreach (AtlasAsset a in atlasAssets)
        {
            Atlas atlas  = a.GetAtlas();
            bool  failed = false;
            foreach (string regionPath in requiredPaths)
            {
                if (atlas.FindRegion(regionPath) == null)
                {
                    failed = true;
                    break;
                }
            }

            if (!failed)
            {
                atlasAssetMatch = a;

                // tsteil - default the GetMatchingAtlas so it tries to returns the 2x atlas
                if (atlasAssetMatch.name.EndsWith("-2x_Atlas"))
                {
                    break;
                }
            }
        }

        return(atlasAssetMatch);
    }
예제 #5
0
    void Apply(SkeletonRenderer skeletonRenderer)
    {
        atlas = AtlasAsset.GetAtlas();
        if (atlas == null)
        {
            return;
        }
        float scale = skeletonRenderer.skeletonDataAsset.scale;

        foreach (var entry in attachments)
        {
            Slot        slot = skeletonRenderer.Skeleton.FindSlot(entry.slot);
            Attachment  originalAttachment = slot.Attachment;
            AtlasRegion region             = atlas.FindRegion(entry.region);


            if (region == null)
            {
                slot.Attachment = null;
            }
            else if (inheritProperties && originalAttachment != null)
            {
                slot.Attachment = originalAttachment.GetRemappedClone(region, true, true, scale);
            }
            else
            {
                var newRegionAttachment = region.ToRegionAttachment(region.name, scale);
                slot.Attachment = newRegionAttachment;
            }

            if (!entry.UseOriginalData)
            {
                RegionAttachment ra = slot.Attachment as RegionAttachment;
                if (ra == null)
                {
                    return;
                }
                ra = (RegionAttachment)ra.Copy();

                //HeroAnimImgList.SlotRegionPair PAIR = SDDataManager.Instance
                // .GetPairBySlotAndRegion(CM.SkeletonIndex, entry.slot, entry.region);
                //Vector2 _pos = PAIR.PositionOffset;
                //Vector2 _scale = PAIR.Scale;

                //ra.Width = ra.RegionWidth * scale * _scale.x;
                //ra.Height = ra.RegionHeight * scale * _scale.y;

                //ra.SetPositionOffset( _pos * scale * _scale );
                ra.UpdateOffset();
                slot.Attachment = ra;
            }
        }
    }
예제 #6
0
        void Apply(SkeletonRenderer skeletonRenderer)
        {
            atlas = atlasAsset.GetAtlas();
            float scale = skeletonRenderer.skeletonDataAsset.scale;

            var enumerator = attachments.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var entry = (SlotRegionPair)enumerator.Current;

                var slot   = skeletonRenderer.skeleton.FindSlot(entry.slot);
                var region = atlas.FindRegion(entry.region);
                slot.Attachment = region.ToRegionAttachment(entry.region, scale);
            }
        }
예제 #7
0
        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;
        }
예제 #8
0
        public Mesh GenerateMesh(string name, Mesh mesh, out Material material, float scale = 0.01f)
        {
            AtlasRegion region = atlas.FindRegion(name);

            material = null;
            if (region != null)
            {
                if (mesh == null)
                {
                    mesh      = new Mesh();
                    mesh.name = name;
                }

                Vector3[] verts     = new Vector3[4];
                Vector2[] uvs       = new Vector2[4];
                Color[]   colors    = { Color.white, Color.white, Color.white, Color.white };
                int[]     triangles = { 0, 1, 2, 2, 3, 0 };

                float left, right, top, bottom;
                left   = region.width / -2f;
                right  = left * -1f;
                top    = region.height / 2f;
                bottom = top * -1;

                verts[0] = new Vector3(left, bottom, 0) * scale;
                verts[1] = new Vector3(left, top, 0) * scale;
                verts[2] = new Vector3(right, top, 0) * scale;
                verts[3] = new Vector3(right, bottom, 0) * scale;
                float u, v, u2, v2;
                u  = region.u;
                v  = region.v;
                u2 = region.u2;
                v2 = region.v2;

                if (!region.rotate)
                {
                    uvs[0] = new Vector2(u, v2);
                    uvs[1] = new Vector2(u, v);
                    uvs[2] = new Vector2(u2, v);
                    uvs[3] = new Vector2(u2, v2);
                }
                else
                {
                    uvs[0] = new Vector2(u2, v2);
                    uvs[1] = new Vector2(u, v2);
                    uvs[2] = new Vector2(u, v);
                    uvs[3] = new Vector2(u2, v);
                }

                mesh.triangles = new int[0];
                mesh.vertices  = verts;
                mesh.uv        = uvs;
                mesh.colors    = colors;
                mesh.triangles = triangles;
                mesh.RecalculateNormals();
                mesh.RecalculateBounds();

                material = (Material)region.page.rendererObject;
            }
            else
            {
                mesh = null;
            }

            return(mesh);
        }
예제 #9
0
        public Mesh GenerateMesh(string name, Mesh mesh, out Material material, float scale = 0.01f)
        {
            AtlasRegion atlasRegion = atlas.FindRegion(name);

            material = null;
            if (atlasRegion != null)
            {
                if (mesh == null)
                {
                    mesh      = new Mesh();
                    mesh.name = name;
                }
                Vector3[] array  = new Vector3[4];
                Vector2[] array2 = new Vector2[4];
                Color[]   colors = new Color[4]
                {
                    Color.white,
                    Color.white,
                    Color.white,
                    Color.white
                };
                int[] triangles = new int[6]
                {
                    0,
                    1,
                    2,
                    2,
                    3,
                    0
                };
                float num  = (float)atlasRegion.width / -2f;
                float x    = num * -1f;
                float num2 = (float)atlasRegion.height / 2f;
                float y    = num2 * -1f;
                array[0] = new Vector3(num, y, 0f) * scale;
                array[1] = new Vector3(num, num2, 0f) * scale;
                array[2] = new Vector3(x, num2, 0f) * scale;
                array[3] = new Vector3(x, y, 0f) * scale;
                float u  = atlasRegion.u;
                float v  = atlasRegion.v;
                float u2 = atlasRegion.u2;
                float v2 = atlasRegion.v2;
                if (!atlasRegion.rotate)
                {
                    array2[0] = new Vector2(u, v2);
                    array2[1] = new Vector2(u, v);
                    array2[2] = new Vector2(u2, v);
                    array2[3] = new Vector2(u2, v2);
                }
                else
                {
                    array2[0] = new Vector2(u2, v2);
                    array2[1] = new Vector2(u, v2);
                    array2[2] = new Vector2(u, v);
                    array2[3] = new Vector2(u2, v);
                }
                mesh.triangles = new int[0];
                mesh.vertices  = array;
                mesh.uv        = array2;
                mesh.colors    = colors;
                mesh.triangles = triangles;
                mesh.RecalculateNormals();
                mesh.RecalculateBounds();
                material = (Material)atlasRegion.page.rendererObject;
            }
            else
            {
                mesh = null;
            }
            return(mesh);
        }
예제 #10
0
//    private void SetAtttachment(SkeletonAnimation skeletonrenderer, string resName, string slotStrm)

    public void SetAttachment(SkeletonAnimation skeletonrenderer, string atlasName, string regionStr, string slotStr, string attachName = "")
    {
        //        float scale = skeletonrenderer.skeletonDataAsset.scale;

        Slot slot = skeletonrenderer.skeleton.FindSlot(slotStr);

        if (slot == null)
        {
            return;               //没有slot,可能表示没有该细节
        }
        if (atlasName.Equals("")) //直接加载texture
        {
            Sprite tex = RoleGenerateManager.instance.LoadTexture(regionStr);
            if (tex == null)
            {
                Debug.LogErrorFormat("<RoleGenerator> 找不到贴图{0}", regionStr);
                return;
            }
            Attachment originalAttachment = slot.Attachment;
            if (originalAttachment != null)
            {
                slot.Attachment = originalAttachment.GetRemappedClone(tex, skeletonrenderer.SkeletonDataAsset.atlasAssets[0].materials[0]);
            }
            else
            {
                slot.Attachment = tex.ToRegionAttachment(skeletonrenderer.SkeletonDataAsset.atlasAssets[0].materials[0]);
            }
        }
        else
        {
            AtlasRegion atlasRegion = null;
            Atlas       atlas       = RoleGenerateManager.instance.LoadPartAtlas(atlasName).GetAtlas();
            atlasRegion = atlas.FindRegion(regionStr);
            if (atlasRegion == null)
            {
                Debug.LogErrorFormat("<RoleGenerator> 图集:{0}中没有切片{1}", atlasName, regionStr);
                return;
            }

            Attachment originalAttachment = slot.Attachment;
            if (originalAttachment != null)
            {
                slot.Attachment = originalAttachment.GetRemappedClone(atlasRegion);
            }
            else
            {
                slot.Attachment = atlasRegion.ToRegionAttachment(atlasRegion.name);
            }
        }

//        if (slot!=null)
//        {

        //        customSkin = customSkin ?? new Skin("custom skin"); // This requires that all customizations are done with skin placeholders defined in Spine.
        //        int slotIndex = skeletonrenderer.skeleton.FindSlotIndex(slotStr); // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster.
        //        Skin templateSkin = skeletonrenderer.skeleton.Data.DefaultSkin;
        //        Attachment templateAttachment = templateSkin.GetAttachment(slotIndex, attachName);
        //        Attachment newAttachment = templateAttachment.GetRemappedClone(sprite, sourceMaterial);
        //        customSkin.SetAttachment(slotIndex, attachName, newAttachment);

//        }
    }