private void SetLUTImportSettings(TextureImporter importer)
 {
     importer.textureType = TextureImporterType.Advanced;
     importer.anisoLevel = 0;
     importer.mipmapEnabled = false;
     importer.linearTexture = true;
     importer.textureFormat = TextureImporterFormat.RGB24;
     importer.SaveAndReimport();
 }
Exemple #2
0
    /// <summary>
    /// 设置图片 样式
    /// </summary>
    /// <param name="iOSFroamt"></param>
    /// <param name="AndroidFroamt"></param>
    static void SettingTexture(TextureImporterFormat iOSFroamt, TextureImporterFormat?AndroidFroamt = null)
    {
        if (null == AndroidFroamt)
        {
            AndroidFroamt = iOSFroamt;
        }
        List <string> fileList = new List <string>();

        /// 遍历 目录 操作
        if (null != Selection.objects)
        {
            for (int index = 0; index < Selection.objects.Length; index++)
            {
                if (null != Selection.objects[index])
                {
                    string path = string.Format("{0}/../{1}", Application.dataPath, AssetDatabase.GetAssetPath(Selection.objects[index]));
                    if (System.IO.Directory.Exists(path))
                    {
                        EditorSearchFile.SearchPath(path, fileList, "");
                    }
                    else
                    {
                        fileList.Add(path);
                    }
                }
            }
        }
        for (int index = 0; index < fileList.Count; index++)
        {
            string path = fileList[index];
            while (path.LastIndexOf("Assets/", System.StringComparison.Ordinal) != 0 && path.LastIndexOf("Assets/", System.StringComparison.Ordinal) != -1)
            {
                path = path.Substring(path.LastIndexOf("Assets/", System.StringComparison.Ordinal));
            }
            UnityEditor.TextureImporter importer = UnityEditor.TextureImporter.GetAtPath(path) as UnityEditor.TextureImporter;
            if (null == importer)
            {
                continue;
            }
            importer.mipmapEnabled = false;
            /// 读取
            TextureImporterPlatformSettings iOS     = importer.GetPlatformTextureSettings("iPhone");
            TextureImporterPlatformSettings Android = importer.GetPlatformTextureSettings("Android");
            /// 重写 设成 true
            Android.overridden           = iOS.overridden = true;
            importer.textureType         = TextureImporterType.Sprite;
            importer.alphaSource         = TextureImporterAlphaSource.FromInput;
            importer.alphaIsTransparency = true;
            importer.npotScale           = TextureImporterNPOTScale.None;
            /// 类型设置
            Android.format = (TextureImporterFormat)AndroidFroamt;
            iOS.format     = iOSFroamt;
            /// 赋值
            importer.SetPlatformTextureSettings(iOS);
            importer.SetPlatformTextureSettings(Android);
            /// LOG
            Debug.Log(string.Format("Setting Texture : [ Android = {1}, iOS = {2} ]{0}", path, AndroidFroamt, iOSFroamt));
            /// 保存
            importer.SaveAndReimport();
        }
    }
        private void splitUpSmartMaterial()
        {
            if (tile.m_smartMaterialSource != null)
            {
                //get provided material
                var             assetPath = AssetDatabase.GetAssetPath(tile.m_smartMaterialSource);
                TextureImporter ti        = AssetImporter.GetAtPath(assetPath) as TextureImporter;
                ti.isReadable = true;

                var cellWidth    = tile.m_smartMaterialSource.texture.width / 12.0f;
                var cellHeight   = tile.m_smartMaterialSource.texture.height / 6.0f;
                var spriteWidth  = cellWidth * 2;
                var spriteHeight = cellHeight * 2;


                //build new ones
                List <SpriteMetaData> newSprites = new List <SpriteMetaData>();
                foreach (var smartRule in allSmartRules)
                {
                    var thisSprite = new SpriteMetaData();
                    thisSprite.alignment = (int)SpriteAlignment.Center;
                    thisSprite.name      = smartRule.name;
                    var x = smartRule.bottomLeftIndex % 12 - 1;
                    var y = smartRule.bottomLeftIndex / 12;
                    thisSprite.rect = new Rect(
                        x * cellWidth,
                        y * cellHeight,
                        spriteWidth,
                        spriteHeight
                        );
                    newSprites.Add(thisSprite);
                }

                //update new sprite slice
                ti.spriteImportMode = SpriteImportMode.Multiple;
                ti.spritesheet      = newSprites.ToArray();
                EditorUtility.SetDirty(ti);
                ti.SaveAndReimport();


                //fetch new sprites
                var generatedSprites = AssetDatabase.LoadAllAssetsAtPath(assetPath)
                                       .OfType <Sprite>().ToList();

                //build rule tiles
                tile.m_TilingRules = new List <RuleTile.TilingRule>();
                foreach (var rule in allSmartRules)
                {
                    var newRule = new RuleTile.TilingRule();
                    rule.neighborRules.CopyTo(newRule.m_Neighbors, 0);
                    newRule.m_Sprites = new[] { generatedSprites.Find(x => x.name == rule.name) };
                    tile.m_TilingRules.Add(newRule);
                }

                //need to do this or you can't see the tiles in the pallette
                tile.m_DefaultSprite = generatedSprites.Find(x => x.name == "default");

                //editor update
                MakeReorderableList();
                SaveTile();
            }
        }
		// Apply settings.
		void Apply(bool preview)
		{
			// Error.
			if (texture == null)
			{
				status = "Drag a texture into the slot.";
				return;
			}

			// Locate asset, get meta.
			path = AssetDatabase.GetAssetPath(texture);
			textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
			SpriteMetaData[] sliceMetaData = textureImporter.spritesheet;

			// Error.
			if (sliceMetaData == null || sliceMetaData.Length == 0)
			{
				status = "Seems no slices defined in texture.";
				return;
			}

			// Naming loop.
			int index = 0;
			status = "";
			if (model.arguments.Count > 3) { status += "Exceeded argument limit of 3. Only first 3 arguments will be used.\n\n"; }
			foreach (SpriteMetaData eachSliceMetaData in sliceMetaData)
			{
				string eachName = "";
				
				// Create string.
				switch (model.arguments.Count)
				{
				case 0: eachName = format; break;
				case 1: eachName = string.Format(format, model.arguments[0].valueForIndex(index)); break;
				case 2: eachName = string.Format(format, model.arguments[0].valueForIndex(index), model.arguments[1].valueForIndex(index)); break;
				case 3: eachName = string.Format(format, model.arguments[0].valueForIndex(index), model.arguments[1].valueForIndex(index), model.arguments[2].valueForIndex(index)); break;
				}
				
				// Assemble name.
				string verb = (preview) ? "Rename" : "Renamed";
				if (index > 0) status += "\n";
				status += verb+" `"+eachSliceMetaData.name+"` to `"+eachName+"`.";
				
				// Assign.
				if (preview == false)
				{ sliceMetaData[index].name = eachName; }
				
				index++;
			}

			// Branding.
			status += "\n\nBrought to you by @_eppz";

			// Apply.
			if (preview == false)
			{
				// Save settings.
				textureImporter.spritesheet = sliceMetaData;
				EditorUtility.SetDirty(textureImporter);
				textureImporter.SaveAndReimport();
				
				// Reimport asset.
				AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
			}
		}