- Home /
Loading assets in Editor Mode?
Hi all, I'm trying to make an editor tool... quite annoying to be honest. Don't know much about them.
I have figured how to create a menu item and display a window when a link is created (Step 1 :3 ). Next I'm trying to load images from a folder in the project (Step 2) and display them in a grid. (Step 3)...
I have been stuck trying to just get an array with the data for quite a while.
public class ObjectManager : EditorWindow
{
int myInt = 1;
int[] arr1 = {1,2,3,4,5};
string[] arr2 = {"ab", "cd", "ef","gh","ij"};
Object txt = new Object();
bool RunOnce = true;
// Add menu to Window menu
[MenuItem ("Level Editor/Add Object")]
static void Init ()
{
// Get existing open window or if none, make a new one:
ObjectManager window = (ObjectManager)EditorWindow.GetWindow (typeof(ObjectManager));
window.title = "Object Manager";
}
void OnGUI ()
{
// if(GUI.Button(new Rect(0,0,200,100), "Get Info"))
// {
// txt = EditorGUIUtility.Load("Assets/Images/Planets");
// txt = Resources.LoadAll("Assets/Images/Planets");
// }
GUILayout.Label ("Base Settings", EditorStyles.boldLabel);
myInt = EditorGUILayout.IntPopup ("Level Number", myInt,arr2,arr1);
EditorGUILayout.BeginScrollView(new Vector2(0,0));
GUILayout.Label (txt.name, EditorStyles.boldLabel);
EditorGUILayout.EndScrollView();
}
}
Sooooo 1. How do you load objects while in editor mode to an editor window? Extra Credit: How could they be displayed in a grid?
Any tips to guide me are greatly appreciated :)
Answer by iwaldrop · Jul 01, 2013 at 11:03 PM
You can create a folder called 'Editor Default Resources' and run the following:
someTexture = EditorGUIUtility.Load("someTexture.png") as Texture;
Remember that you need to include the full path to the file and the extension. So if you have a file called 'Editor Default Resources/Images/button1.jpg', then you'd run:
someTexture = EditorGUIUtility.Load("/Images/button1.jpg") as Texture;
Edit: You want to assign these once in your Awake, not each frame in your GUI.
Thanks I had forgotten about the editor file. :) Now all i need to do if to figure out the showing the images and i can be happy for 5 $$anonymous$$utes :D.