ReadTextureSettings() private method

private ReadTextureSettings ( TextureImporterSettings dest ) : void
dest TextureImporterSettings
return void
Exemplo n.º 1
0
		private static SpriteMetaData GetMetaDataInSingleMode(string name, TextureImporter textureImporter)
		{
			SpriteMetaData result = default(SpriteMetaData);
			result.border = textureImporter.spriteBorder;
			result.name = name;
			result.pivot = textureImporter.spritePivot;
			result.rect = new Rect(0f, 0f, 1f, 1f);
			TextureImporterSettings textureImporterSettings = new TextureImporterSettings();
			textureImporter.ReadTextureSettings(textureImporterSettings);
			result.alignment = textureImporterSettings.spriteAlignment;
			return result;
		}
 private static SpriteMetaData GetMetaDataInSingleMode(string name, TextureImporter textureImporter)
 {
   SpriteMetaData spriteMetaData = new SpriteMetaData();
   spriteMetaData.border = textureImporter.spriteBorder;
   spriteMetaData.name = name;
   spriteMetaData.pivot = textureImporter.spritePivot;
   spriteMetaData.rect = new Rect(0.0f, 0.0f, 1f, 1f);
   TextureImporterSettings dest = new TextureImporterSettings();
   textureImporter.ReadTextureSettings(dest);
   spriteMetaData.alignment = dest.spriteAlignment;
   return spriteMetaData;
 }
    /// <summary>
    /// 把纹理放到编辑器中去
    /// </summary>
    /// <param name="ps"></param>
    private static Texture2D AssembleTexture(ParticleSystem ps, Dictionary <int, object> resource)
    {
        Texture2D tex2D = null;
        Texture3D tex   = resource[ps.TexId] as Texture3D;

        if (tex.IsATF)
        {
        }
        else
        {
            //实例化一个Texture2D,宽和高设置可以是任意的,因为当使用LoadImage方法会对Texture2D的宽和高会做相应的调整
            //Texture2D tex2D = new Texture2D(1,1);
            //tex2D.LoadImage(tex.Data);
            var fileName = string.Empty;
            //if (!File.Exists(SceneFileCopy.GetAbsoluteTextureDir() + tex.Name))
            {
                fileName = tex.Name;
                ps.UnityResourceParam.Texture2DPath = SceneFileCopy.GetRelativeTextureDir(ps.RootFileName) + fileName;
            }
            //else
            //{
            //    fileName = tex.Name.Substring(0, UnityEngine.Mathf.Max(0, tex.Name.Length - 4)) + "_" + Guid.NewGuid().ToString() + tex.Name.Substring(tex.Name.Length - 4, 4);
            //    ps.UnityResourceParam.Texture2DPath = SceneFileCopy.GetRelativeTextureDir() + fileName;
            //}
            ps.UnityResourceParam.Texture2DPath = SceneFileCopy.GetRelativeTextureDir(ps.RootFileName) + fileName;
            SaveFile(SceneFileCopy.GetAbsoluteTextureDir(ps.RootFileName) + fileName, tex.Data);
            tex2D = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.Texture2DPath, typeof(Texture2D)) as Texture2D;
            UnityEditor.TextureImporter         textureImporter = UnityEditor.AssetImporter.GetAtPath(ps.UnityResourceParam.Texture2DPath) as UnityEditor.TextureImporter;
            UnityEditor.TextureImporterSettings settings        = new UnityEditor.TextureImporterSettings();
            textureImporter.ReadTextureSettings(settings);
            settings.ApplyTextureType(UnityEditor.TextureImporterType.Default);
            textureImporter.SetTextureSettings(settings);
            textureImporter.textureType = UnityEditor.TextureImporterType.Default;
            //使用透明度
            textureImporter.alphaIsTransparency = true;
            textureImporter.isReadable          = true;
            textureImporter.filterMode          = (UnityEngine.FilterMode)tex.FilterMode;
            textureImporter.wrapMode            = (UnityEngine.TextureWrapMode)tex.WrapMode;
            textureImporter.mipmapEnabled       = tex.MipMode > 0;
            UnityEditor.AssetDatabase.ImportAsset(ps.UnityResourceParam.Texture2DPath);
        }
        UnityEditor.AssetDatabase.Refresh();
        return(tex2D);
    }
        /**
         * Does two things:
         * 1 - Changes the NPOT strategy to "ToNearest";
         * 2 - Changes the compression to DXT1 or DXT5 if compression is set to something different than DTX1.
         * It only changes the meta file of the texture.
         */
        static void DxtCompressTexture(TextureImporter textureImporter)
        {
            TextureImporterFormat format;
            TextureImporterSettings textureImporterSettings = new TextureImporterSettings();
            textureImporter.ReadTextureSettings(textureImporterSettings);
            format = textureImporterSettings.textureFormat;

            if (format != TextureImporterFormat.DXT1)
            {
                if (textureImporter.DoesSourceTextureHaveAlpha())
                    format = TextureImporterFormat.DXT5;
                else
                    format = TextureImporterFormat.DXT1;
            }

            textureImporter.npotScale = TextureImporterNPOTScale.ToNearest;

            textureImporterSettings.textureFormat = format;
            textureImporter.SetTextureSettings(textureImporterSettings);
        }
        /**
         * Changes the "Max Size" of a texture, acording to its original size and a factor defined by TextureResizingFactor.
         * It only changes the meta file of the texture.
         */
        static void ResizeTexture(Texture2D texture, TextureImporter textureImporter)
        {
            TextureImporterSettings textureImporterSettings = new TextureImporterSettings();
            textureImporter.ReadTextureSettings(textureImporterSettings);
           
            //grabbing the max texture dimension for use in size calculation
            float size = Mathf.Max(texture.width, texture.height);

            string s = "Memory Optimizer: Original size = " + size + "; Original max size = " + textureImporterSettings.maxTextureSize;

            // Getting the smallest texture size between original texture size, to be resized  by TextureResizingFactor, and maxTextureSize set in asset importer settings:
            size = Mathf.Min(Mathf.Pow(2f, Mathf.Floor(Mathf.Log(size, 2f)) - TextureResizingFactor), textureImporterSettings.maxTextureSize);

            Debug.Log(s + "; New max size = " + size);

            // we won't make any changes if the calculate size is lesser than the minimum on Unity dropdown box (32):
            if (size >= 32)
            {
                textureImporterSettings.maxTextureSize = (int)size;
                textureImporter.SetTextureSettings(textureImporterSettings);
            }
        }
	// Texture processing Begin
	public static TextureImporterSettings TextureProcessingBegin(TextureImporter a_rTextureImporter)
	{
		Uni2DAssetPostprocessor.Enabled = false;
		
		// If it's the first time Uni2d use this texture
		// Set the default texture importer settings
		Texture2D rTexture = AssetDatabase.LoadAssetAtPath(a_rTextureImporter.assetPath, typeof(Texture2D)) as Texture2D;
		if(Uni2DEditorUtils.ItIsTheFirstTimeWeUseTheTexture(rTexture))
		{
			Uni2DEditorUtils.MarkAsSourceTexture(rTexture);
			Uni2DEditorUtils.GenerateTextureImportGUID(rTexture);
			SetDefaultTextureImporterSettings( rTexture, false );
		}
		
		TextureImporterSettings rTextureImporterSettings = new TextureImporterSettings();
		a_rTextureImporter.ReadTextureSettings(rTextureImporterSettings);
			
		// Reimport texture as readable and at original size
		SetDefaultTextureImporterSettings(a_rTextureImporter);
		
		if(AssetDatabase.WriteImportSettingsIfDirty(a_rTextureImporter.assetPath))
		{
			AssetDatabase.ImportAsset(a_rTextureImporter.assetPath, ImportAssetOptions.ForceSynchronousImport );
			AssetDatabase.Refresh();
		}

		return rTextureImporterSettings;
	}
Exemplo n.º 7
0
        void SetTextureSetting( TextureImporter textureImporter,bool readable )
        {
            TextureImporterSettings settings = new TextureImporterSettings();
            textureImporter.ReadTextureSettings( settings );

            settings.readable = readable;
            settings.textureFormat = TextureImporterFormat.ARGB32;
            settings.npotScale = TextureImporterNPOTScale.None;

            textureImporter.SetTextureSettings(settings);
        }
    // Texture processing Begin
    public static TextureImporterSettings TextureProcessingBegin(TextureImporter a_rTextureImporter)
    {
        Uni2DEditorSpriteAssetPostProcessor.Enabled = false;

        // If it's the first time Uni2d use this texture
        // Set the default texture importer settings
        Texture2D rTexture = AssetDatabase.LoadAssetAtPath(a_rTextureImporter.assetPath, typeof(Texture2D)) as Texture2D;
        if(Uni2DEditorUtils.ItIsTheFirstTimeWeUseTheTexture(rTexture))
        {
            SetDefaultTextureImporterSettings(a_rTextureImporter);
            Uni2DEditorUtils.GenerateTextureImportGUID(rTexture);
        }

        TextureImporterSettings rTextureImporterSettings = new TextureImporterSettings();
        a_rTextureImporter.ReadTextureSettings(rTextureImporterSettings);

        // Reimport texture as readable and at original size
        a_rTextureImporter.isReadable = true;
        a_rTextureImporter.npotScale = TextureImporterNPOTScale.None;
        a_rTextureImporter.maxTextureSize = 4096;
        a_rTextureImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;

        if(AssetDatabase.WriteImportSettingsIfDirty(a_rTextureImporter.assetPath))
        {
            AssetDatabase.ImportAsset(a_rTextureImporter.assetPath);
            AssetDatabase.Refresh();
        }

        return rTextureImporterSettings;
    }
Exemplo n.º 9
0
 private static SpriteMetaData GetMetaDataInSingleMode(string name, TextureImporter textureImporter)
 {
     SpriteMetaData data = new SpriteMetaData {
         border = textureImporter.spriteBorder,
         name = name,
         pivot = textureImporter.spritePivot,
         rect = new Rect(0f, 0f, 1f, 1f)
     };
     TextureImporterSettings dest = new TextureImporterSettings();
     textureImporter.ReadTextureSettings(dest);
     data.alignment = dest.spriteAlignment;
     return data;
 }
Exemplo n.º 10
0
        private static void SetDefaultSpriteSettings(ref TextureImporter textureImporter)
        {
            textureImporter.textureFormat = TextureImporterFormat.ARGB32;
            textureImporter.textureType = TextureImporterType.Advanced;
            textureImporter.spriteImportMode = SpriteImportMode.Single;
            textureImporter.npotScale = TextureImporterNPOTScale.None;
            textureImporter.filterMode = FilterMode.Point;
            textureImporter.isReadable = true;
            textureImporter.wrapMode = TextureWrapMode.Clamp;
            textureImporter.mipmapEnabled = false;

            TextureImporterSettings settings = new TextureImporterSettings ();
            textureImporter.ReadTextureSettings (settings);
            settings.spriteMeshType = SpriteMeshType.FullRect;
            settings.spriteAlignment = (int)SpriteAlignment.Center;
            textureImporter.SetTextureSettings (settings);
        }
 public TextureImporterSettings GetSettings(TextureImporter importer)
 {
   TextureImporterSettings importerSettings = new TextureImporterSettings();
   importer.ReadTextureSettings(importerSettings);
   this.m_Inspector.GetSerializedPropertySettings(importerSettings);
   return importerSettings;
 }
Exemplo n.º 12
0
        private static void changeTextureImportSettings(TextureImporter _Importer, GAFTexturesResource _Resource)
        {
            if (!m_ImportList.Contains(_Importer.assetPath))
            {
                _Importer.textureType			= TextureImporterType.Advanced;
                _Importer.npotScale				= TextureImporterNPOTScale.None;
                _Importer.maxTextureSize		= 4096;
                _Importer.alphaIsTransparency	= true;
                _Importer.mipmapEnabled			= false;

                TextureImporterSettings st = new TextureImporterSettings();
                _Importer.ReadTextureSettings(st);
                st.wrapMode = TextureWrapMode.Clamp;
                _Importer.SetTextureSettings(st);

                m_ImportList.Add(_Importer.assetPath);
            }
        }