Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

EnterNamePopup.cs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace UnityEditor.AdaptivePerformance.Editor
  4. {
  5. class EnterNamePopup : PopupWindowContent
  6. {
  7. public delegate void EnterDelegate(string str);
  8. readonly EnterDelegate EnterCB;
  9. private string m_NewProfileName = "New Scaler Profile";
  10. private bool m_NeedsFocus = true;
  11. public EnterNamePopup(SerializedProperty profiles, EnterDelegate cb)
  12. {
  13. EnterCB = cb;
  14. List<string> existingProfileNames = new List<string>();
  15. for (int i = 0; i < profiles.arraySize; i++)
  16. {
  17. string profileName = profiles.GetArrayElementAtIndex(i).FindPropertyRelative("m_Name").stringValue;
  18. if (!string.IsNullOrEmpty(profileName))
  19. existingProfileNames.Add(profileName);
  20. }
  21. m_NewProfileName = ObjectNames.GetUniqueName(existingProfileNames.ToArray(), m_NewProfileName);
  22. }
  23. public override Vector2 GetWindowSize()
  24. {
  25. return new Vector2(400, EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing + 14);
  26. }
  27. public override void OnGUI(Rect windowRect)
  28. {
  29. GUILayout.Space(5);
  30. Event evt = Event.current;
  31. bool hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter);
  32. GUI.SetNextControlName("ProfileName");
  33. m_NewProfileName = EditorGUILayout.TextField("New Profile Name", m_NewProfileName);
  34. if (m_NeedsFocus)
  35. {
  36. m_NeedsFocus = false;
  37. EditorGUI.FocusTextInControl("ProfileName");
  38. }
  39. GUI.enabled = m_NewProfileName.Length != 0;
  40. if (GUILayout.Button("Save") || hitEnter)
  41. {
  42. EnterCB(m_NewProfileName);
  43. editorWindow.Close();
  44. }
  45. }
  46. }
  47. }