// Texture processing End public static void TextureProcessingEnd(TextureImporter a_rTextureImporter, TextureImporterSettings a_rTextureImporterSettings) { if(a_rTextureImporter != null) { a_rTextureImporter.SetTextureSettings(a_rTextureImporterSettings); if(AssetDatabase.WriteImportSettingsIfDirty(a_rTextureImporter.assetPath)) { AssetDatabase.ImportAsset(a_rTextureImporter.assetPath, ImportAssetOptions.ForceSynchronousImport ); AssetDatabase.Refresh(); } } Uni2DAssetPostprocessor.Enabled = true; }
/// <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); } }
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 End public static void TextureProcessingEnd(TextureImporter a_rTextureImporter, TextureImporterSettings a_rTextureImporterSettings) { if(a_rTextureImporter != null) { a_rTextureImporter.SetTextureSettings(a_rTextureImporterSettings); if(AssetDatabase.WriteImportSettingsIfDirty(a_rTextureImporter.assetPath)) { AssetDatabase.ImportAsset(a_rTextureImporter.assetPath); AssetDatabase.Refresh(); } } Uni2DEditorSpriteAssetPostProcessor.Enabled = true; }
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); }
void Start() { /* - We set the empty texture to the inputTex (this might create a copy by reference problem) - We set the renderer of the gameobject this script is attached to, to the texture (input texture) - We set the pix array of Colors to the texture of the texture (input texture) */ /* - This is not used really/anymore - We create a TextureImporter which looks at a specific picture for when chaning its settings. - The idea is to automatically change the settings of a picture but failed. - Sets the settings to "Advanced", EncodeRGB to "off", Read/Write enabled, disable mipMap, compression to RGBA32, FilterMode to Point, and remove N^2 Scale. */ importer = AssetImporter.GetAtPath("Assets/Resources/16.png") as TextureImporter; importerSettings = new TextureImporterSettings(); importerSettings.rgbm = TextureImporterRGBMMode.Off; importer.SetTextureSettings(importerSettings); importer.textureType = TextureImporterType.Advanced; importer.isReadable = true; importer.mipmapEnabled = false; importer.textureFormat = TextureImporterFormat.RGBA32; importer.filterMode = FilterMode.Point; importer.npotScale = TextureImporterNPOTScale.None; texture = new Texture2D(inputTex.width, inputTex.height, TextureFormat.RGBA32, false); Color[,] image = PreProcessing.Instance.GetPixels2D(inputTex); image = PreProcessing.Instance.threshGrey(image); image = PreProcessing.Instance.threshRGB(image); image = PreProcessing.Instance.RGBErodeBlack(image); image = PreProcessing.Instance.spawnDetection(image); image = PreProcessing.Instance.batteryDetection(image); image = PreProcessing.Instance.LaserBlobExtraction(image); image = PreProcessing.Instance.laserDetection(image); image = PreProcessing.Instance.goalDetection(image); PreProcessing.Instance.SetPixels2D(image, texture); this.GetComponent<Renderer>().material.mainTexture = texture; /* - Both of our 2D arrays of integers take the height and width of the image pixels - The array of tags gets 10 pixels worth of padding, otherwise it will go out of bounds later */ int pixIndexCounter = 0; int[] pixIndexX; int[] pixIndexY; for (int w = 1; w < texture.width; w++) { for (int h = 1; h < texture.height; h++) { if (image[w, h].r == 0f) { pixIndexCounter++; } } } pixIndexX = new int[pixIndexCounter]; pixIndexY = new int[pixIndexCounter]; int counter3 = 0; for (int w = 1; w < texture.width; w++) { for (int h = 1; h < texture.height; h++) { if (image[w, h].r == 0f) { pixIndexY[counter3] = h; pixIndexX[counter3] = w; counter3++; } } } /* - We create empty GameObjects based on how many cubes there are divided by 1000. - Then we create 1 more assigned for the last cubes that did not come in 1000 - These are the parents of the cubes. */ parents = new GameObject[(pixIndexCounter / 1000) + 1]; for (int p = 0; p < parents.Length; p++) { parents[p] = (GameObject)Instantiate(Resources.Load("walls")); parents[p].name = "Parent"; } int parentCounter = 0; int countTo1000 = 0; for (int h = 0; h < pixIndexY.Length; h++) { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = new Vector3(pixIndexX[h], 12.4f, pixIndexY[h]); cube.transform.localScale = new Vector3(1, 25, 1); cube.transform.parent = parents[parentCounter].transform; countTo1000++; if (countTo1000 == 1000) { parentCounter++; countTo1000 = 0; } } /* - */ for (int p = 0; p < parents.Length; p++) { parents[p].GetComponent<MeshFilter>().mesh = parents[p].GetComponent<Mesh>(); parents[p].AddComponent<combineMesh>(); } /* - Destroys all the "children" meaning that we delete all individual cubes after they all have went through MeshCombine() */ for (int p = 0; p < parents.Length; p++) { foreach (Transform child in parents[p].transform) { GameObject.Destroy(child.gameObject); } } }
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); } }