Skip to content

Commit a544129

Browse files
Tr0sTserg.morozov
authored andcommitted
feat: BREAKING CHANGE: Nuclear Windows Manager
1 parent d17caf9 commit a544129

File tree

108 files changed

+2976
-2398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+2976
-2398
lines changed

Assets/com.nuclearband.windowsmanager/Runtime/AdditionalUtilities.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#nullable enable
2+
using System;
3+
using UnityEngine;
4+
5+
namespace Nuclear.WindowsManager
6+
{
7+
public static class StaticWindowsManager
8+
{
9+
private static IWindowsManager? _instance;
10+
11+
public static void Init(WindowsManagerSettings settings)
12+
{
13+
if (_instance != null)
14+
{
15+
Debug.LogError("WindowsManager already initialized");
16+
return;
17+
}
18+
19+
_instance = new WindowsManager(settings);
20+
}
21+
22+
public static Window CreateWindow(string path, Action<Window>? setupWindow = null) =>
23+
_instance != null
24+
? _instance.CreateWindow(path, setupWindow)
25+
: throw new ArgumentException("WindowsManager not initialized");
26+
27+
public static void PrefetchWindow(string path)
28+
{
29+
if (_instance != null)
30+
_instance.PrefetchWindow(path);
31+
else
32+
throw new ArgumentException("WindowsManager not initialized");
33+
}
34+
35+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
36+
private static void Reset()
37+
{
38+
_instance = null!;
39+
}
40+
}
41+
}

Assets/com.nuclearband.windowsmanager/Runtime/AdditionalUtilities/StaticWindowsManager.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/com.nuclearband.windowsmanager/Runtime/Implementation.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#nullable enable
2+
using System;
3+
using UnityEngine;
4+
5+
namespace NuclearBand
6+
{
7+
public class BackButtonEventManager : MonoBehaviour
8+
{
9+
public event Action OnBackButtonPressed = delegate { };
10+
11+
private void Update()
12+
{
13+
if(Input.GetKeyDown(KeyCode.Escape) )
14+
OnBackButtonPressed.Invoke();
15+
}
16+
}
17+
}

Assets/com.nuclearband.windowsmanager/Runtime/UtilityManagers/BackButtonEventManager.cs.meta renamed to Assets/com.nuclearband.windowsmanager/Runtime/Implementation/BackButtonEventManager.cs.meta

File renamed without changes.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#nullable enable
2+
using System;
3+
using UnityEngine;
4+
5+
namespace Nuclear.WindowsManager
6+
{
7+
public class Window : MonoBehaviour
8+
{
9+
public event Action<Window> OnShown = delegate { };
10+
public event Action<Window> OnHidden = delegate { };
11+
public event Action<Window> OnStartShow = delegate { };
12+
public event Action<Window> OnStartHide = delegate { };
13+
14+
private enum WindowState
15+
{
16+
Opened, Closed, Opening, Closing
17+
}
18+
19+
public bool WithInputBlockForBackground;
20+
public bool DestroyOnClose;
21+
public bool ProcessBackButton = true;
22+
23+
[SerializeField] private WindowAnimation? _showAnimation;
24+
[SerializeField] private WindowAnimation? _hideAnimation;
25+
26+
private WindowState _windowState = WindowState.Closed;
27+
28+
private GameObject? _inputBlock;
29+
private Action? _customBackButtonAction;
30+
private Action _customDeInitActions = delegate { };
31+
32+
public virtual void Init()
33+
{
34+
if (_showAnimation != null)
35+
_showAnimation.OnEnd += EndShowAnimationCallback;
36+
37+
if (_hideAnimation != null)
38+
_hideAnimation.OnEnd += CloseInternal;
39+
}
40+
41+
public void Show(bool immediate = false)
42+
{
43+
OnStartShow.Invoke(this);
44+
_windowState = WindowState.Opening;
45+
if (_showAnimation != null && !immediate)
46+
_showAnimation.Play();
47+
else
48+
EndShowAnimationCallback();
49+
}
50+
51+
public void Close()
52+
{
53+
_windowState = WindowState.Closing;
54+
OnStartHide.Invoke(this);
55+
if (_hideAnimation != null)
56+
_hideAnimation.Play();
57+
else
58+
CloseInternal();
59+
}
60+
61+
public void ProcessBackButtonPress()
62+
{
63+
if (_windowState == WindowState.Closing)
64+
return;
65+
66+
if (_customBackButtonAction != null)
67+
_customBackButtonAction.Invoke();
68+
else
69+
Close();
70+
}
71+
72+
protected void SetCustomBackButtonAction(Action? action) =>
73+
_customBackButtonAction = action;
74+
75+
public void AddDeInitAction(Action action) =>
76+
_customDeInitActions += action;
77+
78+
private void EndShowAnimationCallback()
79+
{
80+
OnShown.Invoke(this);
81+
_windowState = WindowState.Opened;
82+
}
83+
84+
private void CloseInternal()
85+
{
86+
_windowState = WindowState.Closed;
87+
var onHidden = OnHidden;
88+
DeInit();
89+
if (DestroyOnClose)
90+
Destroy(gameObject);
91+
else
92+
gameObject.SetActive(false);
93+
onHidden(this);
94+
}
95+
96+
private void DeInit()
97+
{
98+
OnStartShow = delegate { };
99+
OnShown = delegate { };
100+
OnStartHide = delegate { };
101+
OnHidden = delegate { };
102+
if (_showAnimation != null)
103+
_showAnimation.OnEnd -= EndShowAnimationCallback;
104+
105+
if (_hideAnimation != null)
106+
_hideAnimation.OnEnd -= CloseInternal;
107+
108+
_customDeInitActions.Invoke();
109+
_customDeInitActions = delegate { };
110+
}
111+
}
112+
}

Assets/com.nuclearband.windowsmanager/Runtime/Window.cs.meta renamed to Assets/com.nuclearband.windowsmanager/Runtime/Implementation/Window.cs.meta

File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace Nuclear.WindowsManager
5+
{
6+
public abstract class WindowAnimation : MonoBehaviour
7+
{
8+
public event Action OnEnd = delegate { };
9+
10+
public abstract void Play();
11+
12+
public void End() => OnEnd.Invoke();
13+
}
14+
}

Assets/com.nuclearband.windowsmanager/Runtime/Implementation/WindowAnimation.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)