- Home /
how to change Texture Max Size with scripting
followed a bit this and cant seem to find how do I change Max Size
it can be found in inspector
using UnityEngine;
using System.Collections;
public class GuiFloat : MonoBehaviour {
public Texture2D Leaves;
void Update(){
Leaves.texelSize = (new Vector2(32,32));
}
}
I'm almost sure .texelSize isn't right one for that
but how do I change that value by scripting?
Answer by DaveA · Feb 08, 2013 at 05:56 PM
http://docs.unity3d.com/Documentation/ScriptReference/TextureImporter-maxTextureSize.html
then (untested)
string imgAssetPath = AssetDatabase.GetAssetPath(Leaves);
TextureImporter ti = new TextureImporter();
TextureImporterSettings tis = new TextureImporterSettings();
ti.ReadTextureSettings (tis);
ti.maxTextureSize = 32;
ti.SetTextureSettings (tis);
AssetDatabase.WriteImportSettingsIfDirty (imgAssetPath);
AssetDatabase.ImportAsset(imgAssetPath, ImportAssetOptions.ForceUpdate);
Some of that may not be needed, I just lifted this from some old code that worked for me.
gr8 thanks Yoda with your code I figured partionally where should I look
as with your code I got just too many errors I couldn't fix
I came across Editor class "Texture Importer" + Apply import settings question and I still couldn't figure out how to get path and than I came across Getting the absolute path of current project and I tried it and it works perfectly
this is the code I'm using now:
TextureImporter tImporter = AssetImporter.GetAtPath("Assets/Textures/Floor/Leaves/Leaves.jpg") as TextureImporter;
tImporter.mipmapEnabled = true;
tImporter.isReadable = true;
tImporter.maxTextureSize = 32;
AssetDatabase.ImportAsset( "Assets/Textures/Floor/Leaves/Leaves.jpg", ImportAssetOptions.ForceUpdate );
tho I think for 2 months old programmer <--- me I'm pretty good
thanks Yoda may the force be with you
it's strange tho this path works for me searching sub folders
while path for sub folders didn't for resources.load
Resources.Load ("Category1/Hatchet") as GameObject as provided here as sub answer
Your answer
Follow this Question
Related Questions
Maximum scene size? 2 Answers
NGUI resizes fine in engine but not on actual devices 1 Answer
How do you set minimum EditorWindow size when undocked? 0 Answers
Why is it working in JS but not C# 1 Answer
Big size after export from Xcode 1 Answer