Hi everyone,
I’m currently trying to do an EditorWindow where you can do stuff with textures(not important) the point is that the textures there have to be readable. I know i can make the textures readable with TextureImporter etc. but i don’t want to change the textures otherwise i only want to show textures that are already readable when selecting it with EditorGUILayout.objectfield.
If it’s not clear what i mean, I mean where it says select Textures2D in the following image.
Is it possible to only show readable textures? and if so, could you guys please lead me in the right direction on how to achieve this.
Edit
This is my Set Default UI EditorWindow:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
public class SetDefaultUI : EditorWindow
{
[MenuItem("Manager/UI/Set Default")]
public static void Init()
{
SetDefaultUI myWindow = (SetDefaultUI)EditorWindow.GetWindow (typeof(SetDefaultUI));
myWindow.Show ();
}
Texture2D m_frontSideImage;
Texture2D m_backSideImage;
Texture2D m_backImage;
Texture2D m_playImage;
Vector2 scrollPos;
bool showLevelButton = false;
void OnGUI()
{
EditorGUILayout.LabelField ("Set the default UI here", EditorStyles.boldLabel);
scrollPos = EditorGUILayout.BeginScrollView (scrollPos);
showLevelButton = EditorGUILayout.Foldout (showLevelButton, "Level Button:");
if (showLevelButton)
{
m_frontSideImage = EditorGUILayout.ObjectField ("Front side", m_frontSideImage, typeof(Texture2D), false) as Texture2D;
m_backSideImage = EditorGUILayout.ObjectField ("Back side", m_backSideImage, typeof(Texture2D), false) as Texture2D;
m_backImage = EditorGUILayout.ObjectField ("Back image", m_backImage, typeof(Texture2D), false) as Texture2D;
m_playImage = EditorGUILayout.ObjectField ("Play image", m_playImage, typeof(Texture2D), false) as Texture2D;
}
EditorGUILayout.BeginHorizontal ();
if (GUILayout.Button ("Get Level Button's UI"))
GetLevelButtonUI ();
if (GUILayout.Button ("Set Level Button's UI"))
SetLevelButtonUI ();
EditorGUILayout.EndHorizontal ();
EditorGUILayout.EndScrollView ();
}
void GetLevelButtonUI()
{
List<Texture2D> textures = SaveLoad.LoadDefaultUI ();
if (textures [0] != null)
m_frontSideImage = textures [0];
else
m_frontSideImage = null;
if (textures [1] != null)
m_backSideImage = textures [1];
else
m_backSideImage = null;
if (textures [2] != null)
m_backImage = textures [2];
else
m_backImage = null;
if (textures [3] != null)
m_playImage = textures [3];
else
m_playImage = null;
}
void SetLevelButtonUI()
{
if (DefaultLevelUI.current != null)
{
if (DefaultLevelUI.current.FrontSideImage != m_frontSideImage ||
DefaultLevelUI.current.BackSideImage != m_backSideImage ||
DefaultLevelUI.current.BackImage != m_backImage ||
DefaultLevelUI.current.PlayImage != m_playImage)
{
SaveLevelButtonUI ();
}
} else
{
DefaultLevelUI.current = new DefaultLevelUI ();
SaveLevelButtonUI ();
}
}
void SaveLevelButtonUI()
{
if (EditorUtility.DisplayDialog ("Overwrite Level Button default UI", "Some or all of the sprites provided don't match the current default Level Button UI, are you sure you want to overwrite them?", "Ok", "Cancel"))
{
DefaultLevelUI.current.FrontSideImage = m_frontSideImage;
DefaultLevelUI.current.BackSideImage = m_backSideImage;
DefaultLevelUI.current.BackImage = m_backImage;
DefaultLevelUI.current.PlayImage = m_playImage;
SaveLoad.SaveDefaultUI (GetTexturesInList());
}
}
List<Texture2D> GetTexturesInList()
{
List<Texture2D> texList = new List<Texture2D> ();
texList.Add (DefaultLevelUI.current.FrontSideImage);
texList.Add (DefaultLevelUI.current.BackSideImage);
texList.Add (DefaultLevelUI.current.BackImage);
texList.Add (DefaultLevelUI.current.PlayImage);
return texList;
}
}
As you can see on line 29-32 i have the object fields, i think i should do there something but honestly I have no idea how to do it.
Thanks in advance
-Jorge