i’m doing some stuff with GUIStyles and the one roadblock for me is trying to find textures in my Assets folder to apply into a texture2D var so that I can hand it off to the GUIStyle. any help would be most appreciated.
cheers,
malcolm.
i’m doing some stuff with GUIStyles and the one roadblock for me is trying to find textures in my Assets folder to apply into a texture2D var so that I can hand it off to the GUIStyle. any help would be most appreciated.
cheers,
malcolm.
simply declare a variable of type Texture2D
var myTexture: Texture2D;
in your script, and when you save it, a slot wil pop up in the inspector when you choose the script. This new slot will accept any texture that you drag and drop onto it.
i’m wondering more if there’s a way through script to find the actual texture so you don’t have to apply it through the inspector.
because with normal gameobjects you can just do:
var myObj : GameObject;
myObj = GameObject.Find("objectName");
and this will make the variable have that gameObject. I’m looking for something like that but with textures that aren’t applied currently anywhere. so i’m looking for something like this:
var myTexture : Texture2d;
myTexture = findTexture("textureName");
there’s something similar in the EditorGUIUtility class but I couldn’t figure out how to get that to work from the editor script back into my main script.
cheers,
malcolm.[/code]
Resources.Load
–Eric
i’d briefly seen that one, but i didn’t know if that was the preferred method. thanks for the advice.
cheers,
malcolm.
Assigning via the inspector is generally preferred, unless you have a good reason otherwise (like 5000 textures or something, which would be really tedious to do manually).
–Eric
I am having a similar issue.
I am trying to create a command that can create a list of prefabs from a given set of commands. My only issue is I cannot grab a texture from file.
I am hoping to assign the texture via code, because I create my materials per object.
I have tried EditorGUIUtility.Load(), Resources.Load(), and EditorGUIUtility.FindTexture(). They all return null. I have tried using many different asset pathname styles (Assets/theAsset, Assets/theAsset.png, theAsset, theAsset.png, Assets//theAsset, Assets//theAsset.png) and those do not seem to fix the issue.
I’m curious if there is any syntax issues, or my misunderstanding how to get a particular asset.
Here is what I have:
Texture tex = (Resources.Load(mydata.data.prefabList[i].texture))as Texture;
Material mat = new Material(Shader.Find ("Transparent/Diffuse"));
mat.mainTexture = tex;
texture is a string containing the path.