Skip to content

Commit 749463a

Browse files
authored
Merge pull request #2 from wththd/test_pr
Implemented closing modal window on esc (back) key
2 parents 4eec49c + 93a4643 commit 749463a

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

Assets/ModalWindows/Scripts/ModalWindow.cs

Lines changed: 19 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,23 @@ protected virtual void OnBeforeShow()
119121
}
120122
}
121123

124+
protected virtual void Update()
125+
{
126+
CheckIgnorableForClose();
127+
}
128+
129+
protected virtual void CheckIgnorableForClose()
130+
{
131+
if (Input.GetKeyDown(KeyCode.Escape))
132+
{
133+
if (!ReferenceEquals(Instance, null))
134+
{
135+
if (Instance.ignorable)
136+
Instance.Close();
137+
}
138+
}
139+
}
140+
122141
public virtual T Show()
123142
{
124143
OnBeforeShow();

Assets/ModalWindows/Scripts/ModalWindows/InputModalWindow.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ void SubmitInput()
3636
Close();
3737
}
3838

39-
private void Update()
39+
protected override void Update()
4040
{
41+
base.Update();
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: 3 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,5 @@ public class SimpleModalWindow : ModalWindow<SimpleModalWindow>
89
{
910
return ModalWindow<SimpleModalWindow>.Create(ignorable);
1011
}
12+
1113
}

0 commit comments

Comments
 (0)