示例#1
0
        private void GenerateTexture(string assetPath)
        {
            SourceTextureInformation textureInformation = new SourceTextureInformation()
            {
                containsAlpha = true,
                hdr           = false,
                height        = textureHeight,
                width         = textureWidth
            };

            TextureImporterPlatformSettings platformSettings = new TextureImporterPlatformSettings()
            {
                overridden = false
            };

            TextureGenerationSettings settings = new TextureGenerationSettings()
            {
                assetPath                = assetPath,
                spriteImportData         = ConvertAseFileSpriteImportDataToUnity(SpriteImportData),
                textureImporterSettings  = TextureImportSettings.ToImporterSettings(),
                enablePostProcessor      = false,
                sourceTextureInformation = textureInformation,
                qualifyForSpritePacking  = true,
                platformSettings         = platformSettings,
                spritePackingTag         = "aseprite",
                secondarySpriteTextures  = new SecondarySpriteTexture[0]
            };


            TextureGenerationOutput output = TextureGenerator.GenerateTexture(settings, new Unity.Collections.NativeArray <Color32>(atlas.GetPixels32(), Unity.Collections.Allocator.Temp));

            Texture   = output.texture;
            thumbnail = output.thumbNail;
            sprites   = output.sprites;
        }
示例#2
0
        void RegisterAssets(AssetImportContext ctx, TextureGenerationOutput output)
        {
            List <int> assetNameHash = new List <int>();

            if (!string.IsNullOrEmpty(output.importInspectorWarnings))
            {
                Debug.LogWarning(output.importInspectorWarnings);
            }
            if (output.importWarnings != null && output.importWarnings.Length != 0)
            {
                foreach (var warning in output.importWarnings)
                {
                    Debug.LogWarning(warning);
                }
            }
            if (output.thumbNail == null)
            {
                Debug.LogWarning("Thumbnail generation fail");
            }
            if (output.texture == null)
            {
                throw new Exception("Texture import fail");
            }
            var assetName = GetUniqueName(System.IO.Path.GetFileNameWithoutExtension(ctx.assetPath), assetNameHash, true);

            output.texture.name = assetName;
            ctx.AddObjectToAsset(assetName, output.texture, output.thumbNail);
            UnityEngine.Object mainAsset = output.texture;


            if (output.sprites != null)
            {
                foreach (var s in output.sprites)
                {
                    assetName = GetUniqueName(s.name, assetNameHash, true, s);
                    ctx.AddObjectToAsset(assetName, s);
                }


                if (shouldProduceGameObject)
                {
                    var prefab = OnProducePrefab(assetName, output.sprites);
                    if (prefab != null)
                    {
                        assetName = GetUniqueName(prefab.name, assetNameHash, true, prefab);
                        ctx.AddObjectToAsset(assetName, prefab);
                        mainAsset = prefab;
                    }
                }
            }
            ctx.SetMainObject(mainAsset);
        }
示例#3
0
        void RegisterAssets(AssetImportContext ctx, TextureGenerationOutput output)
        {
            List <int> assetNameHash = new List <int>();

            if (!string.IsNullOrEmpty(output.importInspectorWarnings))
            {
                Debug.LogWarning(output.importInspectorWarnings);
            }
            if (output.importWarnings != null && output.importWarnings.Length != 0)
            {
                foreach (var warning in output.importWarnings)
                {
                    Debug.LogWarning(warning);
                }
            }
            if (output.thumbNail == null)
            {
                Debug.LogWarning("Thumbnail generation fail");
            }
            if (output.texture == null)
            {
                throw new Exception("Texture import fail");
            }

            var assetName = GetUniqueName(System.IO.Path.GetFileNameWithoutExtension(ctx.assetPath), assetNameHash, true);

            // Setup all fixed name on the hash table
            if (string.IsNullOrEmpty(m_TextureAssetName))
            {
                m_TextureAssetName = GetUniqueName(string.Format("{0} Texture", assetName), assetNameHash, true);
            }
            if (string.IsNullOrEmpty(m_PrefabAssetName))
            {
                m_PrefabAssetName = GetUniqueName(string.Format("{0} Prefab", assetName), assetNameHash, true);
            }
            if (string.IsNullOrEmpty(m_SpriteLibAssetName))
            {
                m_SpriteLibAssetName = GetUniqueName(string.Format("{0} Sprite Lib", assetName), assetNameHash, true);
            }

            output.texture.name = assetName;
            ctx.AddObjectToAsset(m_TextureAssetName, output.texture, output.thumbNail);
            UnityEngine.Object mainAsset = output.texture;


            if (output.sprites != null)
            {
                if (shouldProduceGameObject)
                {
                    GameObject prefab = OnProducePrefab(m_TextureAssetName, output.sprites);
                    if (prefab != null)
                    {
                        ctx.AddObjectToAsset(m_PrefabAssetName, prefab);
                        mainAsset = prefab;
                    }
                }

                foreach (var s in output.sprites)
                {
                    var spriteAssetName = GetUniqueName(s.GetSpriteID().ToString(), assetNameHash, false, s);
                    ctx.AddObjectToAsset(spriteAssetName, s);
                }
            }
            ctx.SetMainObject(mainAsset);
        }