Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2016
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1.         public class TestEditorWindow : UnityEditor.EditorWindow {
  2.  
  3.             [MenuItem ("Window/My Window")]
  4.             static void Init () {
  5.                 // Get existing open window or if none, make a new one:
  6.                 var window = (TestEditorWindow)EditorWindow.GetWindow (typeof (TestEditorWindow));
  7.                 window.Show();
  8.             }
  9.  
  10.             private int index = 0;
  11.  
  12.             public void OnGUI() {
  13.                 var padding = 5;
  14.                 var width = Screen.width - 2*padding;
  15.                 var lineHeight = EditorGUIUtility.singleLineHeight;
  16.  
  17.                 var audioclipNames = FileNamesFromFolder<AudioClip>("Audiofiles");
  18.  
  19.                 if(audioclipNames.Length <= 0) return;
  20.  
  21.                 index = EditorGUI.Popup(new Rect(padding, padding, width, lineHeight), "test: ", index, audioclipNames);
  22.  
  23.             }
  24.  
  25.  
  26.             public string[] FileNamesFromFolder<T>(string folderpath) where T : UnityEngine.Object {
  27.                 var allfiles = Resources.LoadAll<T>(folderpath);
  28.                 return allfiles.Select(obj => obj.name).ToArray();
  29.             }
  30.  
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement