public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
    {
        List<Entry> entries = new List<Entry>();

        foreach (int instanceID in textureImporterInstanceIDs)
        {
            TextureImporter ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;

            //TextureImportInstructions ins = new TextureImportInstructions();
            //ti.ReadTextureImportInstructions(ins, target);

            TextureImporterSettings tis = new TextureImporterSettings();
            ti.ReadTextureSettings(tis);

            Sprite[] sprites = AssetDatabase.LoadAllAssetRepresentationsAtPath(ti.assetPath).Select(x => x as Sprite).Where(x => x != null).ToArray();
            foreach (Sprite sprite in sprites)
            {
                //在这里设置每个图集的参数
                Entry entry = new Entry();
                entry.sprite = sprite;
                entry.settings.format = (TextureFormat)Enum.Parse(typeof(TextureFormat), ParseTextuerFormat(ti.spritePackingTag).ToString());
                entry.settings.filterMode = FilterMode.Bilinear;
                entry.settings.colorSpace = ColorSpace.Linear;
                entry.settings.compressionQuality = (int)TextureCompressionQuality.Normal;
                entry.settings.filterMode = Enum.IsDefined(typeof(FilterMode), ti.filterMode) ? ti.filterMode : FilterMode.Bilinear;
                entry.settings.maxWidth = ParseTextureWidth(ti.spritePackingTag);
                entry.settings.maxHeight = ParseTextureHeight(ti.spritePackingTag);
                entry.atlasName = ParseAtlasName(ti.spritePackingTag);
                entry.packingMode = GetPackingMode(ti.spritePackingTag, tis.spriteMeshType);

                entries.Add(entry);
            }
            Resources.UnloadAsset(ti);
        }

        var atlasGroups =
            from e in entries
            group e by e.atlasName;
        foreach (var atlasGroup in atlasGroups)
        {
            int page = 0;
            // Then split those groups into smaller groups based on texture settings
            var settingsGroups =
                from t in atlasGroup
                group t by t.settings;
            foreach (var settingsGroup in settingsGroups)
            {
                string atlasName = atlasGroup.Key;
                if (settingsGroups.Count() > 1)
                    atlasName += string.Format(" (Group {0})", page);

                job.AddAtlas(atlasName, settingsGroup.Key);
                foreach (Entry entry in settingsGroup)
                {
                    job.AssignToAtlas(atlasName, entry.sprite, entry.packingMode, SpritePackingRotation.None);
                }
                ++page;
            }
        }
    }
Beispiel #2
0
    void ConfigureSpriteAtlas(Texture2D texture, Rect[] uvs)
    {
        string path = AssetDatabase.GetAssetPath(texture);
        TextureImporter texImporter = AssetImporter.GetAtPath(path) as TextureImporter;
        TextureImporterSettings texImporterSettings = new TextureImporterSettings();

        texImporter.textureType = TextureImporterType.Sprite;
        texImporter.spriteImportMode = SpriteImportMode.Multiple;
      //  texImporterSettings.readable = true;

        SpriteMetaData[] spritesheetMeta = new SpriteMetaData[uvs.Length];
        for(int i = 0; i < uvs.Length; i++)
        {
            SpriteMetaData currentMeta = new SpriteMetaData();
            Rect currentRect = uvs[i];
            currentRect.x *= texture.width;
            currentRect.width *= texture.width; 
            currentRect.y *= texture.height;
            currentRect.height *= texture.height;
            currentMeta.rect = currentRect;
            currentMeta.name = textures[i].name;
            currentMeta.alignment = (int)SpriteAlignment.Center;
            currentMeta.pivot = new Vector2(currentRect.width / 2, currentRect.height / 2);
            spritesheetMeta[i] = currentMeta;
        }
        texImporter.spritesheet = spritesheetMeta;
        texImporter.spritePixelsToUnits = 1000f;
        texImporter.ReadTextureSettings(texImporterSettings);

        texImporter.SetTextureSettings(texImporterSettings);

        AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
        AssetDatabase.Refresh();
    }
		public void AddComponents(int layerIndex, GameObject imageObject, Sprite sprite, TextureImporterSettings settings)
		{
			var spr = imageObject.AddComponent<SpriteRenderer>();
			spr.sprite = sprite;
			// If setting the sorting order is as simple as setting a sorting number,
			// do it here. Note that UiImgConstructor is more complex because of how
			// Unity UI uses the hierarchy position for sorting
			spr.sortingOrder = layerIndex;
		}
 void RestoreTextureSettings(Texture2D image, TextureImporterSettings settings)
 {
     var imagePath = AssetDatabase.GetAssetPath(image);
     var imageImporter = (TextureImporter)TextureImporter.GetAtPath(imagePath);
     imageImporter.SetTextureSettings(settings);
     AssetDatabase.WriteImportSettingsIfDirty(imagePath);
     AssetDatabase.ImportAsset(imagePath, ImportAssetOptions.ForceSynchronousImport);
     AssetDatabase.Refresh();
 }
		public void AddComponents(int layerIndex, GameObject imageObject, Sprite sprite, TextureImporterSettings settings)
		{
			var uiImg = imageObject.AddComponent<Image>();

			uiImg.sprite = sprite;
			uiImg.SetNativeSize();
			uiImg.rectTransform.SetAsFirstSibling();

			Vector2 sprPivot = PsdBuilder.GetPivot(settings);
			uiImg.rectTransform.pivot = sprPivot;
		}
		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;
 }
Beispiel #8
0
    void ConfigureForAtlas(string texturePath)
    {
        TextureImporter texImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter;
        TextureImporterSettings texImporterSettings = new TextureImporterSettings();

        texImporter.textureType = TextureImporterType.Sprite;
        texImporter.ReadTextureSettings(texImporterSettings);
        texImporterSettings.readable = true;

        texImporter.SetTextureSettings(texImporterSettings);
        AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);
        AssetDatabase.Refresh();
    }
 TextureImporterSettings ChangeTextureSettings(Texture2D image, bool readable, TextureImporterFormat textureFormat)
 {
     var imagePath = AssetDatabase.GetAssetPath(image);
     var imageImporter = (TextureImporter)TextureImporter.GetAtPath(imagePath);
     var prevsetting = new TextureImporterSettings();
     imageImporter.ReadTextureSettings(prevsetting);
     imageImporter.isReadable = readable;
     imageImporter.textureFormat = textureFormat;
     AssetDatabase.WriteImportSettingsIfDirty(imagePath);
     AssetDatabase.ImportAsset(imagePath, ImportAssetOptions.ForceSynchronousImport);
     AssetDatabase.Refresh();
     return prevsetting;
 }
 public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
 {
     List<Entry> source = new List<Entry>();
     foreach (int num in textureImporterInstanceIDs)
     {
         TextureFormat format;
         ColorSpace space;
         int num3;
         TextureImporter assetToUnload = EditorUtility.InstanceIDToObject(num) as TextureImporter;
         assetToUnload.ReadTextureImportInstructions(target, out format, out space, out num3);
         TextureImporterSettings dest = new TextureImporterSettings();
         assetToUnload.ReadTextureSettings(dest);
         if (<>f__am$cache0 == null)
         {
 /// <summary>
 /// <para>TODO.</para>
 /// </summary>
 /// <param name="platform"></param>
 public TextureImporterFormat GetAutomaticFormat(string platform)
 {
     TextureImporterSettings dest = new TextureImporterSettings();
     this.ReadTextureSettings(dest);
     TextureImporterPlatformSettings platformTextureSettings = this.GetPlatformTextureSettings(platform);
     List<BuildPlayerWindow.BuildPlatform> validPlatforms = BuildPlayerWindow.GetValidPlatforms();
     foreach (BuildPlayerWindow.BuildPlatform platform2 in validPlatforms)
     {
         if (platform2.name == platform)
         {
             return FormatFromTextureParameters(dest, platformTextureSettings, this.DoesSourceTextureHaveAlpha(), this.IsSourceTextureHDR(), platform2.DefaultTarget);
         }
     }
     return TextureImporterFormat.Automatic;
 }
    static void ChangeTextureType_GuiFull() {
        Object[] textures = GetSelectedTextures();
        Selection.objects = new Object[0];
        foreach (Texture2D texture in textures)  {
            string path = AssetDatabase.GetAssetPath(texture);
            //Debug.Log("path: " + path);
            TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
            textureImporter.textureType = TextureImporterType.GUI;	
			textureImporter.npotScale = TextureImporterNPOTScale.None;
			TextureImporterSettings st = new TextureImporterSettings();
			textureImporter.ReadTextureSettings(st);
			st.wrapMode = TextureWrapMode.Clamp;
			textureImporter.SetTextureSettings(st);
	        AssetDatabase.ImportAsset(path);
    	}
    }
Beispiel #13
0
    private static void OnPostprocessTexture()
    {
        Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);

        foreach (Object obj in SelectedAsset)
        {
            if (obj is Texture2D)
            {
                string path = AssetDatabase.GetAssetPath(obj);
                TextureImporter texImporter = GetTextureSettings(path);
                TextureImporterSettings tis = new TextureImporterSettings();
                texImporter.ReadTextureSettings(tis);
                texImporter.SetTextureSettings(tis);
                AssetDatabase.ImportAsset(path);
            }
        }
    }
    /// <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);
    }
Beispiel #15
0
        /// <summary>
        /// Sets the asset texture format.
        /// </summary>
        /// <returns><c>true</c>, if set format was set, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        /// <param name="format">Format.</param>
        public static bool AssetSetFormat(string path, TextureImporterFormat format)
        {
            if (string.IsNullOrEmpty(path))
                return false;

            TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;

            if (ti == null)
                return false;

            TextureImporterSettings settings = new TextureImporterSettings();
            ti.ReadTextureSettings(settings);

            settings.textureFormat = format;
            ti.SetTextureSettings(settings);
            SPTools.DoAssetReimport(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);

            return true;
        }
Beispiel #16
0
    public void ConfigureForPacker(string path)
    {
        TextureImporter pImporter = AssetImporter.GetAtPath (path) as TextureImporter;
        pImporter.textureType = TextureImporterType.Advanced;

        TextureImporterSettings pSetting = new TextureImporterSettings ();
        pImporter.ReadTextureSettings (pSetting);
        //only 2D false
        pSetting.mipmapEnabled = false;
        pSetting.readable = true;
        pSetting.maxTextureSize = 4096;
        pSetting.textureFormat = TextureImporterFormat.ARGB32;
        pSetting.filterMode = FilterMode.Point;
        pSetting.wrapMode = TextureWrapMode.Clamp;
        pSetting.npotScale = TextureImporterNPOTScale.None;
        pImporter.SetTextureSettings (pSetting);

        AssetDatabase.ImportAsset (path,ImportAssetOptions.ForceUpdate);
        AssetDatabase.Refresh ();
    }
 public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
 {
     List<Entry> list = new List<Entry>();
     string targetName = "";
     if (target != BuildTarget.NoTarget)
     {
         targetName = BuildPipeline.GetBuildTargetName(target);
     }
     foreach (int num in textureImporterInstanceIDs)
     {
         TextureFormat format;
         ColorSpace space;
         int num3;
         TextureImporter ti = EditorUtility.InstanceIDToObject(num) as TextureImporter;
         ti.ReadTextureImportInstructions(target, out format, out space, out num3);
         TextureImporterSettings dest = new TextureImporterSettings();
         ti.ReadTextureSettings(dest);
         bool flag = (targetName != "") && this.HasPlatformEnabledAlphaSplittingForCompression(targetName, ti);
         if (<>f__am$cache0 == null)
         {
 static void ChangeTextureType_GuiFull()
 {
     IEnumerable<Object> textures = GetSelectedTextures();
     Selection.objects = new Object[0];
     foreach (var o in textures)
     {
         var texture = (Texture2D) o;
         var path = AssetDatabase.GetAssetPath(texture);
         //Debug.Log("path: " + path);
         var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
         Debug.Assert(textureImporter != null, "textureImporter != null");
         textureImporter.textureType = TextureImporterType.GUI;
         textureImporter.npotScale = TextureImporterNPOTScale.None;
         var st = new TextureImporterSettings();
         textureImporter.ReadTextureSettings(st);
         st.wrapMode = TextureWrapMode.Clamp;
         textureImporter.SetTextureSettings(st);
         AssetDatabase.ImportAsset(path);
     }
 }
Beispiel #19
0
        /// <summary>
        /// Sets the asset Read/Write enabled state.
        /// </summary>
        /// <returns><c>true</c>, if set read write enabled was asseted, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        /// <param name="enabled">If set to <c>true</c> enabled.</param>
        /// <param name="force">If set to <c>true</c> force.</param>
        public static bool AssetSetReadWriteEnabled(string path, bool enabled, bool force)
        {
            if (string.IsNullOrEmpty(path))
                return false;

            TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;

            if (ti == null)
                return false;

            TextureImporterSettings settings = new TextureImporterSettings();
            ti.ReadTextureSettings(settings);

            if (force || settings.readable != enabled)
            {
                settings.readable = enabled;
                ti.SetTextureSettings(settings);
                SPTools.DoAssetReimport(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
            }

            return true;
        }
    public void ApplySettings()
    {
        TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;
        if(importer == null) {
            Debug.Log("Importer for asset at path: " + path + " is null.");
            return;
        }

        bool differentSettings = false;

        TextureImporterSettings settings = new TextureImporterSettings();
        importer.ReadTextureSettings(settings);

        if(settings.mipmapEnabled != mipmaps) {
            settings.mipmapEnabled = mipmaps;
            differentSettings = true;
        }

        if(settings.maxTextureSize != maxSize) {
            settings.maxTextureSize = maxSize;
            differentSettings = true;
        }

        if(settings.textureFormat != format) {
            settings.textureFormat = format;
            differentSettings = true;
        }

        if(settings.npotScale != npotScale) {
            settings.npotScale = npotScale;
            differentSettings = true;
        }

        if(differentSettings) {
            importer.SetTextureSettings(settings);
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate); //Re-import the asset
        }
    }
Beispiel #21
0
    // 步骤1  优化输入的纹理
    private void ConfigureForTextureAtlas(string TexturePath)
    {
        // 1. 获取指定路径下的纹理
        TextureImporter TexImport = AssetImporter.GetAtPath(TexturePath) as TextureImporter;
        TexImport.textureType = TextureImporterType.Advanced;

        // 2.修改此纹理的设置
        TextureImporterSettings tiSettings = new TextureImporterSettings();
        TexImport.ReadTextureSettings (tiSettings);

        tiSettings.mipmapEnabled = false;
        tiSettings.readable = true;
        tiSettings.maxTextureSize = 4096;
        tiSettings.textureFormat = TextureImporterFormat.ARGB32;
        tiSettings.filterMode = FilterMode.Point;
        tiSettings.wrapMode = TextureWrapMode.Clamp;
        tiSettings.npotScale = TextureImporterNPOTScale.None;
        TexImport.SetTextureSettings (tiSettings);

        // 3.重新把纹理导入到 unity 中
        AssetDatabase.ImportAsset(TexturePath,ImportAssetOptions.ForceUpdate);
        AssetDatabase.Refresh ();
    }
	public static void SetTexSettingsToAllSelected() {
		// get all the selected textures in the editor
		
		Object[] selectedTex = Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
		
		// read the texture settings from the first texture in the selection list
		if (Selection.activeObject.GetType() != typeof(Texture2D)) {
			Debug.Log("Your first selection must be a texture asset!");
			return;
		}
		
		string firstAssetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
		Debug.Log("MultipleTexturesSetup: Applying texture settings from: " + firstAssetPath);
		
		TextureImporter texImporter = AssetImporter.GetAtPath(firstAssetPath) as TextureImporter;
		TextureImporterSettings texSettings = new TextureImporterSettings();
		texImporter.ReadTextureSettings(texSettings);
		TextureImporterType texType = texImporter.textureType;
		
		// apply the texture settings to all the other selected textures
		Debug.Log("MultipleTexturesSetup: Applied texture settings to " + (selectedTex.Length - 1) + " textures:");
		for(int i = 0; i < selectedTex.Length; i++) {
			string newAssetPath = AssetDatabase.GetAssetPath(selectedTex[i]);
			// avoid the first selected asset path (this is because the assets returned by Selection.GetFiltered are not in a known order
			if (firstAssetPath == newAssetPath)
				continue;
	
			texImporter = AssetImporter.GetAtPath(newAssetPath) as TextureImporter;	
			texImporter.SetTextureSettings(texSettings);
			texImporter.textureType = texType;
			
			Debug.Log("MultipleTexturesSetup: " + newAssetPath);
			
			// re-import the texture with the new settings
			AssetDatabase.ImportAsset(newAssetPath, ImportAssetOptions.ForceSynchronousImport);
		}
	}
		public static extern bool Equal(TextureImporterSettings a, TextureImporterSettings b);
    internal static void setAtlasTextureSettings( string path, bool createMode )
    {
        AssetDatabase.Refresh();

        var importer = AssetImporter.GetAtPath( path ) as TextureImporter;
        if( importer == null )
        {
            Debug.LogError( "Failed to obtain import settings for texture: " + path );
        }

        importer.ClearPlatformTextureSettings( "iPhone" );

        var settings = new TextureImporterSettings();

        importer.ReadTextureSettings( settings );
        settings.mipmapEnabled = false;
        settings.readable = false;
        settings.maxTextureSize = 4096;
        settings.textureFormat = TextureImporterFormat.AutomaticTruecolor;
        settings.wrapMode = TextureWrapMode.Clamp;
        settings.npotScale = TextureImporterNPOTScale.None;

        if( createMode )
        {
            settings.filterMode = FilterMode.Bilinear;
            settings.alphaIsTransparency = true;
            settings.linearTexture = true;
        }

        importer.SetTextureSettings( settings );

        AssetDatabase.ImportAsset( path, ImportAssetOptions.ForceUpdate );
    }
Beispiel #25
0
 public void CopyTo(TextureImporterSettings target)
 {
     Copy(this, target);
 }
Beispiel #26
0
 public static extern bool Equal(TextureImporterSettings a, TextureImporterSettings b);
Beispiel #27
0
        //================================================================================
        // 関数
        //================================================================================
        /// <summary>
        /// 指定された TextureImporter に設定を適用します
        /// </summary>
        public void Apply(TextureImporter importer)
        {
            var settings = new UnityEditor.TextureImporterSettings();

            importer.ReadTextureSettings(settings);

            if (m_textureType.IsOverride)
            {
                settings.textureType = m_textureType.Value;
            }

            if (m_textureShape.IsOverride)
            {
                settings.textureShape = m_textureShape.Value;
            }

            if (m_spritePixelsPerUnit.IsOverride)
            {
                settings.spritePixelsPerUnit = m_spritePixelsPerUnit.Value;
            }

            if (m_spriteMeshType.IsOverride)
            {
                settings.spriteMeshType = m_spriteMeshType.Value;
            }

            if (m_spriteExtrude.IsOverride)
            {
                settings.spriteExtrude = m_spriteExtrude.Value;
            }

            if (m_spriteAlignment.IsOverride)
            {
                settings.spriteAlignment = ( int )m_spriteAlignment.Value;
            }

            if (m_spritePivot.IsOverride)
            {
                settings.spritePivot = m_spritePivot.Value;
            }

            if (m_spriteGenerateFallbackPhysicsShape.IsOverride)
            {
                settings.spriteGenerateFallbackPhysicsShape = m_spriteGenerateFallbackPhysicsShape.Value;
            }

            if (m_sRGBTexture.IsOverride)
            {
                settings.sRGBTexture = m_sRGBTexture.Value;
            }

            if (m_alphaSource.IsOverride)
            {
                settings.alphaSource = m_alphaSource.Value;
            }

            if (m_alphaIsTransparency.IsOverride)
            {
                settings.alphaIsTransparency = m_alphaIsTransparency.Value;
            }

            if (m_npotScale.IsOverride)
            {
                settings.npotScale = m_npotScale.Value;
            }

            if (m_readable.IsOverride)
            {
                settings.readable = m_readable.Value;
            }

            if (m_streamingMipmaps.IsOverride)
            {
                settings.streamingMipmaps = m_streamingMipmaps.Value;
            }

            if (m_streamingMipmapsPriority.IsOverride)
            {
                settings.streamingMipmapsPriority = m_streamingMipmapsPriority.Value;
            }

            if (m_mipmapEnabled.IsOverride)
            {
                settings.mipmapEnabled = m_mipmapEnabled.Value;
            }

            if (m_borderMipmap.IsOverride)
            {
                settings.borderMipmap = m_borderMipmap.Value;
            }

            if (m_mipmapFilter.IsOverride)
            {
                settings.mipmapFilter = m_mipmapFilter.Value;
            }

            if (m_mipMapsPreserveCoverage.IsOverride)
            {
                settings.mipMapsPreserveCoverage = m_mipMapsPreserveCoverage.Value;
            }

            if (m_alphaTestReferenceValue.IsOverride)
            {
                settings.alphaTestReferenceValue = m_alphaTestReferenceValue.Value;
            }

            if (m_fadeOut.IsOverride)
            {
                settings.fadeOut = m_fadeOut.Value;
            }

            if (m_mipmapFadeDistanceStart.IsOverride)
            {
                settings.mipmapFadeDistanceStart = m_mipmapFadeDistanceStart.Value;
            }

            if (m_mipmapFadeDistanceEnd.IsOverride)
            {
                settings.mipmapFadeDistanceEnd = m_mipmapFadeDistanceEnd.Value;
            }

            if (m_wrapMode.IsOverride)
            {
                settings.wrapMode = m_wrapMode.Value;
            }

            if (m_filterMode.IsOverride)
            {
                settings.filterMode = m_filterMode.Value;
            }

            if (m_aniso.IsOverride)
            {
                settings.aniso = m_aniso.Value;
            }

            if (m_defaultSettings != null)
            {
                var platformSettings = importer.GetPlatformTextureSettings("DefaultTexturePlatform");
                m_defaultSettings.Apply(platformSettings);
                importer.SetPlatformTextureSettings(platformSettings);
            }

            if (m_standaloneSettings != null)
            {
                var platformSettings = importer.GetPlatformTextureSettings("Standalone");
                m_standaloneSettings.Apply(platformSettings);
                importer.SetPlatformTextureSettings(platformSettings);
            }

            if (m_iPhoneSettings != null)
            {
                var platformSettings = importer.GetPlatformTextureSettings("iPhone");
                platformSettings.overridden = true;
                m_iPhoneSettings.Apply(platformSettings);
                importer.SetPlatformTextureSettings(platformSettings);
            }

            if (m_androidSettings != null)
            {
                var platformSettings = importer.GetPlatformTextureSettings("Android");
                m_androidSettings.Apply(platformSettings);
                importer.SetPlatformTextureSettings(platformSettings);
            }

            if (m_webGLSettings != null)
            {
                var platformSettings = importer.GetPlatformTextureSettings("WebGL");
                m_webGLSettings.Apply(platformSettings);
                importer.SetPlatformTextureSettings(platformSettings);
            }

            importer.SetTextureSettings(settings);

            // TextureImporterSettings は Sprite Mode のパラメータを持っていないため
            // TextureImporter で設定する必要がある
            // また、Sprite Mode は SetTextureSettings の後に設定しないと反映されないので
            // SetTextureSettings の後に設定するようにしています
            if (m_spriteImportMode.IsOverride)
            {
                importer.spriteImportMode = m_spriteImportMode.Value;
            }
        }
Beispiel #28
0
 private static extern void Copy([NotNull] TextureImporterSettings self, [Out][NotNull] TextureImporterSettings target);
Beispiel #29
0
 // Read texture settings into [[TextureImporterSettings]] class.
 public void ReadTextureSettings(TextureImporterSettings dest)
 {
     settings.CopyTo(dest);
 }
Beispiel #30
0
 internal static extern TextureImporterFormat FormatFromTextureParameters([NotNull] TextureImporterSettings settings, TextureImporterPlatformSettings platformSettings, bool doesTextureContainAlpha, bool sourceWasHDR, BuildTarget destinationPlatform);
    bool MakeTextureReadable(Texture tex)
    {
        string path = AssetDatabase.GetAssetPath(tex.GetInstanceID());
        if (string.IsNullOrEmpty(path)) return false;
        TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;
        if (ti == null) return false;

        TextureImporterSettings settings = new TextureImporterSettings();
        ti.ReadTextureSettings(settings);

        if (!settings.readable)
        {
            settings.readable = true;

            ti.SetTextureSettings(settings);
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
        }
        return true;
    }
Beispiel #32
0
 // Set texture importers settings from [[TextureImporterSettings]] class.
 public void SetTextureSettings(TextureImporterSettings src)
 {
     settings = src;
 }
Beispiel #33
0
 internal static extern TextureImporterFormat SimpleToFullTextureFormat2(TextureImporterFormat simpleFormat, TextureImporterType tType, TextureImporterSettings settings, bool doesTextureContainAlpha, bool sourceWasHDR, BuildTarget destinationPlatform);
Beispiel #34
0
 public extern void ReadTextureSettings(TextureImporterSettings dest);
 public extern void ReadTextureSettings(TextureImporterSettings dest);
		public extern void CopyTo(TextureImporterSettings target);
Beispiel #37
0
 private static extern void Internal_ApplyTextureType([Out][NotNull] TextureImporterSettings self, TextureImporterType type);
		private static extern void Internal_ApplyTextureType(TextureImporterSettings s, TextureImporterType type, bool applyAll);
 public extern void SetTextureSettings(TextureImporterSettings src);
Beispiel #40
0
 public extern void SetTextureSettings(TextureImporterSettings src);
 private static extern void Internal_ApplyTextureType(TextureImporterSettings s, TextureImporterType type, bool applyAll);
        public static void ApplySpriteSettings(Texture2D texture,
            SpriteSettings prefs, SpriteFileSettings fileSettings)
        {
            if (prefs == null) return;

            string path = AssetDatabase.GetAssetPath (texture);
            var importer = AssetImporter.GetAtPath(path) as TextureImporter;

            // When we have text file data
            SpriteSlicingOptions slicingOptions = fileSettings.SlicingOptions;
            if (slicingOptions.ImportMode == SpriteImportMode.Multiple)
            {
                // Clamp cellSize to texture width and height
                slicingOptions.CellSize.x = Mathf.Min (texture.width, slicingOptions.CellSize.x);
                slicingOptions.CellSize.y = Mathf.Min (texture.height, slicingOptions.CellSize.y);

                SpriteMetaData[] spriteSheet;
                spriteSheet = SpriteSlicer.CreateSpriteSheetForTexture (AssetDatabase.LoadAssetAtPath(path,
                    typeof(Texture2D)) as Texture2D, slicingOptions);

                // If we don't do this it won't update the new sprite meta data
                importer.spriteImportMode = SpriteImportMode.Single;
                importer.spriteImportMode = SpriteImportMode.Multiple;

                importer.spritesheet = spriteSheet;
            }
            else if (slicingOptions.ImportMode == SpriteImportMode.Single)
            {
                importer.spriteImportMode = SpriteImportMode.Single;
            } else if (slicingOptions.ImportMode == SpriteImportMode.None)
            {
                // Do nothing for None mode for now.
            } else
            {
                throw new System.NotSupportedException ("Encountered unsupported SpriteImportMode:"
                    + slicingOptions.ImportMode);
            }

            TextureImporterSettings settings = new TextureImporterSettings();
            importer.ReadTextureSettings(settings);
            importer.textureType = TextureImporterType.Advanced;

            settings.filterMode = prefs.FilterMode;
            settings.wrapMode = prefs.WrapMode;
            settings.mipmapEnabled = prefs.GenerateMipMaps;
            settings.textureFormat = prefs.TextureFormat;
            settings.maxTextureSize = prefs.MaxSize;

            settings.spritePixelsPerUnit = prefs.PixelsPerUnit;

            settings.spriteExtrude = (uint)Mathf.Clamp(prefs.ExtrudeEdges, 0, 32);
            settings.spriteMeshType = prefs.SpriteMeshType;

            // Settings also store Sprite Alignment for Single spritemode
            settings.spriteAlignment = (int)slicingOptions.Pivot;
            if (slicingOptions.Pivot == SpriteAlignment.Custom)
            {
                settings.spritePivot = slicingOptions.CustomPivot;
            }

            importer.spritePackingTag = fileSettings.PackingTag;

            importer.SetTextureSettings(settings);
            #if UNITY_5_0
            importer.SaveAndReimport();
            #else
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
            #endif
            EditorUtility.SetDirty(texture);
            WriteSpriteFileSettings (path, prefs.SpritesheetDataFile, texture.name + ".png", fileSettings);
        }
 public void ApplyTextureType(TextureImporterType type, bool applyAll)
 {
     TextureImporterSettings.Internal_ApplyTextureType(this, type, applyAll);
 }
 public extern void CopyTo(TextureImporterSettings target);
Beispiel #45
0
 internal static extern TextureImporterFormat SimpleToFullTextureFormat2(TextureImporterFormat simpleFormat, TextureImporterType tType, TextureImporterSettings settings, bool doesTextureContainAlpha, bool sourceWasHDR, BuildTarget destinationPlatform);