- Home /
Question by
Jojo Batista · Oct 19, 2013 at 07:28 PM ·
stringpopupproperty
Property drawers popup
Hello, I just want to have a public string, and set its value depending on a list of assets available in a folder: Here is my script, If I uncomment the EditorGUI.TextField it shows the text field and I can edit the string, but If I create a popup it doesn't show. The file ,the names array and the pop up work ok, because I'm using the exact same code in an editor script for a level creator.
using System.Collections; using UnityEditor; using System.IO; [CustomPropertyDrawer (typeof (LevelListAttribute))] public class LevelListDrawer : PropertyDrawer {using UnityEngine;
private int _lastIndex = 0;
private LevelListAttribute levelAttribute { get { return ((LevelListAttribute)attribute); } } public override void OnGUI (Rect position, SerializedProperty prop, GUIContent label) {
EditorGUI.BeginChangeCheck ();
//string value = EditorGUI.TextField (position, label, prop.stringValue);
DirectoryInfo dir = new DirectoryInfo("Assets/Resources/Levels"); FileInfo[] info = dir.GetFiles("*.asset"); string[] names = new string[info.Length]; int f = 0; foreach (FileInfo inf in info) { names[f] = inf.Name; f++; } _lastIndex = EditorGUI.Popup(new Rect(0, 0 , 200, 15),_lastIndex,names); string value = names[_lastIndex];
if (EditorGUI.EndChangeCheck ()) prop.stringValue = value;
}
public override float GetPropertyHeight (SerializedProperty prop, GUIContent label) { return base.GetPropertyHeight (prop, label); } } This is the attribute
using System.Collections; using System.IO; [System.Serializable] public class LevelListAttribute : PropertyAttribute {using UnityEngine;
public string LevelList; public LevelListAttribute() { LevelList = "asd"; } }
Comment
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
'Cannot convert int to String' 2 Answers
How do I get a list to randomly select.... 1 Answer
Remove Numbers from a String 2 Answers
Get values from long string (C#) 5 Answers