Exemplo n.º 1
0
        public static void ImportTexture(string path, Bitmap texture, ICookingRules rules, byte[] CookingRulesSHA1)
        {
            var textureParamsPath = Path.ChangeExtension(path, ".texture");

            if (!AreTextureParamsDefault(rules))
            {
                UpscaleTextureIfNeeded(ref texture, rules, false);
                var textureParams = new TextureParams {
                    WrapMode  = rules.WrapMode,
                    MinFilter = rules.MinFilter,
                    MagFilter = rules.MagFilter,
                };
                Serialization.WriteObjectToBundle(AssetBundle, textureParamsPath, textureParams, Serialization.Format.Binary, ".texture", AssetAttributes.None, null);
            }
            else
            {
                if (AssetBundle.FileExists(textureParamsPath))
                {
                    DeleteFileFromBundle(textureParamsPath);
                }
            }
            if (ShouldGenerateOpacityMasks())
            {
                var maskPath = Path.ChangeExtension(path, ".mask");
                OpacityMaskCreator.CreateMask(AssetBundle, texture, maskPath);
            }
            var attributes = AssetAttributes.ZippedDeflate;

            if (!TextureConverterUtils.IsPowerOf2(texture.Width) || !TextureConverterUtils.IsPowerOf2(texture.Height))
            {
                attributes |= AssetAttributes.NonPowerOf2Texture;
            }
            switch (Platform)
            {
            case TargetPlatform.Android:
                var f = rules.PVRFormat;
                if (f == PVRFormat.ARGB8 || f == PVRFormat.RGB565 || f == PVRFormat.RGBA4)
                {
                    TextureConverter.RunPVRTexTool(texture, AssetBundle, path, attributes, rules.MipMaps, rules.HighQualityCompression, rules.PVRFormat, CookingRulesSHA1);
                }
                else
                {
                    TextureConverter.RunEtcTool(texture, AssetBundle, path, attributes, rules.MipMaps, rules.HighQualityCompression, CookingRulesSHA1);
                }
                break;

            case TargetPlatform.iOS:
                TextureConverter.RunPVRTexTool(texture, AssetBundle, path, attributes, rules.MipMaps, rules.HighQualityCompression, rules.PVRFormat, CookingRulesSHA1);
                break;

            case TargetPlatform.Win:
            case TargetPlatform.Mac:
                TextureConverter.RunNVCompress(texture, AssetBundle, path, attributes, rules.DDSFormat, rules.MipMaps, CookingRulesSHA1);
                break;

            default:
                throw new Lime.Exception();
            }
        }
Exemplo n.º 2
0
        public void ImportTexture(string path, Bitmap texture, ICookingRules rules, DateTime time, byte[] CookingRulesSHA1)
        {
            var textureParamsPath = Path.ChangeExtension(path, ".texture");
            var textureParams     = new TextureParams {
                WrapMode  = rules.WrapMode,
                MinFilter = rules.MinFilter,
                MagFilter = rules.MagFilter,
            };

            if (!AreTextureParamsDefault(rules))
            {
                TextureTools.UpscaleTextureIfNeeded(ref texture, rules, false);
                var isNeedToRewriteTexParams = true;
                if (AssetBundle.FileExists(textureParamsPath))
                {
                    var oldTexParams = InternalPersistence.Instance.ReadObject <TextureParams>(textureParamsPath, AssetBundle.OpenFile(textureParamsPath));
                    isNeedToRewriteTexParams = !oldTexParams.Equals(textureParams);
                }
                if (isNeedToRewriteTexParams)
                {
                    InternalPersistence.Instance.WriteObjectToBundle(AssetBundle, textureParamsPath, textureParams, Persistence.Format.Binary, ".texture",
                                                                     File.GetLastWriteTime(textureParamsPath), AssetAttributes.None, null);
                }
            }
            else
            {
                if (AssetBundle.FileExists(textureParamsPath))
                {
                    DeleteFileFromBundle(textureParamsPath);
                }
            }
            if (rules.GenerateOpacityMask)
            {
                var maskPath = Path.ChangeExtension(path, ".mask");
                OpacityMaskCreator.CreateMask(AssetBundle, texture, maskPath);
            }
            var attributes = AssetAttributes.ZippedDeflate;

            if (!TextureConverterUtils.IsPowerOf2(texture.Width) || !TextureConverterUtils.IsPowerOf2(texture.Height))
            {
                attributes |= AssetAttributes.NonPowerOf2Texture;
            }
            switch (Target.Platform)
            {
            case TargetPlatform.Android:
                //case TargetPlatform.iOS:
                var f = rules.PVRFormat;
                if (f == PVRFormat.ARGB8 || f == PVRFormat.RGB565 || f == PVRFormat.RGBA4)
                {
                    TextureConverter.RunPVRTexTool(texture, AssetBundle, path, attributes, rules.MipMaps, rules.HighQualityCompression, rules.PVRFormat, CookingRulesSHA1, time);
                }
                else
                {
                    TextureConverter.RunEtcTool(texture, AssetBundle, path, attributes, rules.MipMaps, rules.HighQualityCompression, CookingRulesSHA1, time);
                }
                break;

            case TargetPlatform.iOS:
                TextureConverter.RunPVRTexTool(texture, AssetBundle, path, attributes, rules.MipMaps, rules.HighQualityCompression, rules.PVRFormat, CookingRulesSHA1, time);
                break;

            case TargetPlatform.Win:
            case TargetPlatform.Mac:
                TextureConverter.RunNVCompress(texture, AssetBundle, path, attributes, rules.DDSFormat, rules.MipMaps, CookingRulesSHA1, time);
                break;

            default:
                throw new Lime.Exception();
            }
        }