Skip to content

Commit 642faf1

Browse files
author
Your Name
committed
added closing windows on return button pressed
1 parent 4eec49c commit 642faf1

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Assets/ModalWindows/Scripts/ModalWindow.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public virtual T SetHeader(string text)
9292

9393
return Instance;
9494
}
95+
96+
9597

9698
public virtual T SetBody(string text)
9799
{
@@ -119,6 +121,18 @@ protected virtual void OnBeforeShow()
119121
}
120122
}
121123

124+
protected virtual void CheckIgnorableForClose()
125+
{
126+
if (Input.GetKeyDown(KeyCode.Escape))
127+
{
128+
if (!ReferenceEquals(Instance, null))
129+
{
130+
if (Instance.ignorable)
131+
Instance.Close();
132+
}
133+
}
134+
}
135+
122136
public virtual T Show()
123137
{
124138
OnBeforeShow();

Assets/ModalWindows/Scripts/ModalWindows/InputModalWindow.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ void SubmitInput()
3838

3939
private void Update()
4040
{
41+
CheckIgnorableForClose();
4142
if (inputField.isFocused && inputField.text != "" && Input.GetKeyUp(KeyCode.Return))
42-
{
4343
SubmitInput();
44-
}
4544
}
4645

4746
public void UI_InputFieldOKButton()

Assets/ModalWindows/Scripts/ModalWindows/SimpleModalWindow.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using UnityEngine;
45

@@ -8,4 +9,9 @@ public class SimpleModalWindow : ModalWindow<SimpleModalWindow>
89
{
910
return ModalWindow<SimpleModalWindow>.Create(ignorable);
1011
}
12+
13+
private void Update()
14+
{
15+
CheckIgnorableForClose();
16+
}
1117
}

0 commit comments

Comments
 (0)