WindowUtils.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright (c) 2025 Omar Duarte
  3. Unauthorized copying of this file, via any medium is strictly prohibited.
  4. Writen by Omar Duarte, 2025.
  5. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  8. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  9. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  10. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  11. THE SOFTWARE.
  12. */
  13. using UnityEngine;
  14. namespace PluginMaster
  15. {
  16. public class RenameWindow : UnityEditor.EditorWindow
  17. {
  18. private string _name = string.Empty;
  19. private bool _focusSet = false;
  20. private System.Action<string> Save = null;
  21. public static void ShowWindow(Vector2 position, System.Action<string> saveAction, string title, string name)
  22. {
  23. var window = GetWindow<RenameWindow>(true, title);
  24. window.position = new Rect(position.x, position.y + 50, 0, 0);
  25. window.minSize = window.maxSize = new Vector2(160, 45);
  26. window._focusSet = false;
  27. window.Save += saveAction;
  28. window._name = name;
  29. }
  30. private void OnGUI()
  31. {
  32. GUI.SetNextControlName("NameField");
  33. _name = GUILayout.TextField(_name);
  34. if (!_focusSet)
  35. {
  36. UnityEditor.EditorGUI.FocusTextInControl("NameField");
  37. _focusSet = true;
  38. }
  39. using (new UnityEditor.EditorGUI.DisabledGroupScope(string.IsNullOrWhiteSpace(_name)))
  40. {
  41. if (GUILayout.Button("Save"))
  42. {
  43. if (Save != null) Save(_name);
  44. Close();
  45. }
  46. }
  47. }
  48. }
  49. }