Beispiel #1
0
        void AppsListClick(object userData, string[] options, int selected)
        {
            AppsListUserData ud = (AppsListUserData)userData;

            if (options[selected] == L10n.Tr("Browse..."))
            {
                string path = EditorUtility.OpenFilePanel("Browse for application", "", InternalEditorUtility.GetApplicationExtensionForRuntimePlatform(Application.platform));
                if (path.Length != 0)
                {
                    // browsed to new application
                    ud.str.str = path;
                    if (ud.onChanged != null)
                    {
                        ud.onChanged();
                    }
                }
            }
            else
            {
                // value comes from the list
                ud.str.str = ud.paths[selected];
                if (ud.onChanged != null)
                {
                    ud.onChanged();
                }
            }

            WritePreferences();
            ReadPreferences();
        }
Beispiel #2
0
        private void FilePopup(GUIContent label, string selectedString, ref string[] names, ref string[] paths, RefString outString, string defaultString, Action onChanged)
        {
            GUIStyle style = EditorStyles.popup;

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(label, style);

            int[] selected = new int[0];
            if (paths.Contains(selectedString))
            {
                selected = new[] { Array.IndexOf(paths, selectedString) }
            }
            ;
            GUIContent       text = new GUIContent(selected.Length == 0 ? defaultString : names[selected[0]]);
            Rect             r    = GUILayoutUtility.GetRect(GUIContent.none, style);
            AppsListUserData ud   = new AppsListUserData(paths, outString, onChanged);

            if (EditorGUI.DropdownButton(r, text, FocusType.Passive, style))
            {
                ArrayUtility.Add(ref names, Styles.browse.text);
                EditorUtility.DisplayCustomMenu(r, names, selected, AppsListClick, ud, false);
            }
            GUILayout.EndHorizontal();
        }