Skip to content

Commit 738f065

Browse files
authored
refactor: simplify the codebase (#40)
1 parent 3f35c03 commit 738f065

File tree

75 files changed

+10892
-9938
lines changed

Some content is hidden

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

75 files changed

+10892
-9938
lines changed

Assets/Audio/Events/FMODEvent.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ private void Update3DPosition() {
6767
}
6868

6969
public void SetParameter(FMODParameter parameter, float val) {
70-
if (!IsInitialized || parameter.IsGlobal)
70+
if (!IsInitialized || parameter.IsGlobal) {
7171
return;
72+
}
7273

7374
if (_parameterIdLookup.TryGetValue(parameter, out var instance)) {
7475
Instance.setParameterByID(instance, val);
@@ -85,6 +86,7 @@ public void Play() {
8586
public void Release() {
8687
if (IsInitialized) {
8788
Instance.release();
89+
IsInitialized = false;
8890
}
8991
}
9092
}

Assets/DevTools/CSV/CsvParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public static IReadOnlyList<Row> Parse(string text) {
1616
var cells = new List<string>();
1717

1818
var isInsideField = false;
19-
var previousEmpty = false;
2019
_builder.Clear();
2120
_rows.Clear();
2221

Assets/DevTools/GoogleSheetLoaderDev.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Aarthificial.Typewriter.References;
55
using DevTools.CSV;
66
using Framework;
7-
using Input;
87
using Interactions;
98
using Player;
109
using System.Collections;
@@ -19,9 +18,7 @@ public partial class GoogleSheetLoader {
1918
private static string _customDocumentId;
2019
private static string _customSheetName;
2120

22-
[SerializeField] [Inject] private PlayerChannel _players;
23-
[SerializeField] [Inject] private InputChannel _input;
24-
[SerializeField] [Inject] private StoryMode _story;
21+
[SerializeField] [Inject] private StoryState _story;
2522
[SerializeField] private DatabaseTable _table;
2623
[SerializeField] private string _documentId;
2724
[SerializeField] private string _sheetName;
@@ -32,6 +29,11 @@ public partial class GoogleSheetLoader {
3229
private bool _onlyFacts;
3330
private bool _hideEmpty = true;
3431
private string _searchText = "";
32+
private PlayerManager _players;
33+
34+
private void Awake() {
35+
_players = GetComponent<PlayerManager>();
36+
}
3537

3638
private void OnEnable() {
3739
if (string.IsNullOrEmpty(_customDocumentId)) {
@@ -58,8 +60,8 @@ private void Open() {
5860
}
5961

6062
_isOpen = true;
61-
_previousMap = _input.CurrentMap;
62-
_input.SetMap("None");
63+
_previousMap = App.Input.CurrentMap;
64+
App.Input.SetMap("None");
6365
Time.timeScale = 0;
6466
}
6567

@@ -69,7 +71,7 @@ private void Close() {
6971
}
7072

7173
_isOpen = false;
72-
_input.SetMap(_previousMap);
74+
App.Input.SetMap(_previousMap);
7375
Time.timeScale = 1;
7476
}
7577

@@ -78,8 +80,8 @@ private void OnGUI() {
7880
return;
7981
}
8082

81-
var isInConversation = _players.Manager.DialogueState.IsActive
82-
&& _players.Manager.DialogueState.Context != null;
83+
var isInConversation = _players.DialogueState.IsActive
84+
&& _players.DialogueState.Context != null;
8385

8486
var size = new Vector2(640, 160);
8587
var rect = new Rect(
@@ -162,7 +164,7 @@ private void BlackboardGUI(Rect rect) {
162164

163165
_scrollPosition = GUILayout.BeginScrollView(_scrollPosition);
164166

165-
var context = _players.Manager.DialogueState.Context;
167+
var context = _players.DialogueState.Context;
166168
BlackboardEntriesGUI(context, InteractionContext.GlobalScope);
167169
BlackboardEntriesGUI(context, InteractionContext.InteractionScope);
168170
BlackboardEntriesGUI(context, InteractionContext.ContextScope);

Assets/Environment/LookAtCamera.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
using UnityEngine;
2-
using Utils;
32
using View.Overlay;
43

54
namespace Environment {
65
[DefaultExecutionOrder(1000)]
76
public class LookAtCamera : MonoBehaviour {
8-
[Inject] [SerializeField] private OverlayChannel _overlay;
7+
private Camera _mainCamera;
8+
9+
private void Awake() {
10+
_mainCamera = OverlayManager.Camera;
11+
}
912

1013
private void LateUpdate() {
11-
if (_overlay.IsReady) {
12-
transform.rotation =
13-
_overlay.CameraManager.MainCamera.transform.rotation;
14-
}
14+
transform.rotation = _mainCamera.transform.rotation;
1515
}
1616
}
1717
}

Assets/Environment/Shaders/BoxSDF.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Shader "GUI/BoxSDF"
106106
{
107107
UNITY_SETUP_INSTANCE_ID(input);
108108
Varyings output;
109-
output.worldPosition = float4(TransformWorldToObject(input.vertex), 0.0);
109+
output.worldPosition = float4(TransformWorldToObject(input.vertex.xyz), 0.0);
110110
output.vertex = TransformObjectToHClip(input.vertex);
111111

112112
output.texcoord = input.texcoord;

Assets/Environment/Shaders/InteractionGizmo.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Shader "GUI/InteractionGizmo"
129129
const float scale = 0.5 + lerp(1, 0.58333333333333, _State.x);
130130
const float4 positionOS = input.positionOS * scale;
131131
output.positionOS = positionOS;
132-
output.positionCS = TransformObjectToHClip(positionOS);
132+
output.positionCS = TransformObjectToHClip(positionOS.xyz);
133133

134134
output.uv = (input.uv - 0.5) * scale + 0.5;
135135
output.color = input.color;

Assets/Framework/App.cs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,51 @@
1+
using Audio;
2+
using FMODUnity;
3+
using Input;
14
using UnityEngine;
25
using UnityEngine.SceneManagement;
36

47
namespace Framework {
5-
// TODO Move to the editor namespace maybe?
6-
#if UNITY_EDITOR
78
public static class App {
9+
public static GameManager Game;
10+
public static InputManager Input;
11+
public static AudioManager Audio;
12+
public static InputActions Actions;
13+
814
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
9-
private static void Bootstrap() {
10-
if (ShouldBootstrap()) {
11-
SceneManager.LoadScene(0, LoadSceneMode.Additive);
15+
private static void BetterBootstrap() {
16+
#if UNITY_EDITOR
17+
if (ShouldSkip()) {
18+
return;
1219
}
20+
#endif
21+
22+
// Force FMOD initialization to avoid a framerate drop when the first
23+
// sound is played.
24+
_ = RuntimeManager.StudioSystem;
25+
26+
var app = Object.Instantiate(Resources.Load<GameObject>("App"));
27+
Game = app.GetComponent<GameManager>();
28+
Input = app.GetComponent<InputManager>();
29+
Audio = app.GetComponent<AudioManager>();
30+
Actions = Input.Actions;
31+
32+
Game.DrivenAwake();
33+
34+
Object.DontDestroyOnLoad(app);
1335
}
1436

15-
private static bool ShouldBootstrap() {
37+
#if UNITY_EDITOR
38+
private static bool ShouldSkip() {
1639
var activeScene = SceneManager.GetActiveScene();
17-
if (activeScene.buildIndex == 0) {
18-
return false;
19-
}
20-
2140
var path = activeScene.path;
2241
foreach (var scene in UnityEditor.EditorBuildSettings.scenes) {
2342
if (scene.path == path) {
24-
return true;
43+
return false;
2544
}
2645
}
2746

28-
return false;
47+
return true;
2948
}
30-
}
3149
#endif
50+
}
3251
}

Assets/Framework/GameManager.cs

Lines changed: 24 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
1-
using System.Collections;
2-
using Audio;
3-
using FMODUnity;
1+
using System;
42
using UnityEngine;
53
using UnityEngine.InputSystem;
64
using UnityEngine.SceneManagement;
7-
using Utils;
85

96
namespace Framework {
107
public class GameManager : MonoBehaviour {
11-
[Inject] public MenuMode MenuMode;
12-
[Inject] public StoryMode StoryMode;
13-
public AudioManager Audio;
8+
[NonSerialized] public MenuState Menu;
9+
[NonSerialized] public StoryState Story;
1410

15-
private GameMode _currentMode;
16-
private GameMode _switchingTo;
11+
private GameState _currentState;
1712

18-
private bool ISSwitching => !ReferenceEquals(_switchingTo, null);
13+
public void DrivenAwake() {
14+
Menu = GetComponent<MenuState>();
15+
Story = GetComponent<StoryState>();
1916

20-
public void RequestMode(GameMode mode) {
21-
if (_switchingTo == mode || _currentMode == mode) {
17+
#if UNITY_EDITOR
18+
if (SceneManager.GetActiveScene().buildIndex == 0) {
19+
SwitchState(Menu);
20+
} else {
21+
SwitchState(Story);
22+
}
23+
#else
24+
SwitchState(Menu);
25+
#endif
26+
}
27+
28+
public void SwitchState(GameState state) {
29+
if (_currentState == state) {
2230
return;
2331
}
2432

25-
StartCoroutine(SwitchMode(mode));
33+
_currentState?.OnExit();
34+
_currentState = state;
35+
_currentState?.OnEnter();
2636
}
2737

2838
public void Quit() {
@@ -32,38 +42,11 @@ public void Quit() {
3242
Application.Quit();
3343
}
3444

35-
private void Awake() {
36-
MenuMode.Setup(this);
37-
StoryMode.Setup(this);
38-
39-
// Force FMOD initialization to avoid a framerate drop when the first
40-
// sound is played.
41-
_ = RuntimeManager.StudioSystem;
42-
43-
#if UNITY_EDITOR
44-
switch (SceneManager.GetActiveScene().buildIndex) {
45-
case 0:
46-
RequestMode(MenuMode);
47-
break;
48-
case 1:
49-
_currentMode = MenuMode;
50-
_currentMode.OnEditorStart();
51-
break;
52-
default:
53-
_currentMode = StoryMode;
54-
_currentMode.OnEditorStart();
55-
break;
56-
}
57-
#else
58-
RequestMode(MenuMode);
59-
#endif
60-
}
61-
6245
#if UNITY_EDITOR || DEVELOPMENT_BUILD
6346
private void Update() {
6447
if (Keyboard.current.rKey.wasPressedThisFrame
6548
&& Keyboard.current.ctrlKey.isPressed) {
66-
StoryMode.Reload();
49+
Story.Reload();
6750
}
6851

6952
if (Keyboard.current.fKey.wasPressedThisFrame
@@ -72,25 +55,5 @@ private void Update() {
7255
}
7356
}
7457
#endif
75-
76-
private IEnumerator SwitchMode(GameMode mode) {
77-
if (_switchingTo == mode || _currentMode == mode) {
78-
yield break;
79-
}
80-
81-
if (ISSwitching) {
82-
yield return new WaitUntil(() => !ISSwitching);
83-
}
84-
85-
_switchingTo = mode;
86-
if (!ReferenceEquals(_currentMode, null)) {
87-
yield return _currentMode.OnEnd();
88-
}
89-
90-
_currentMode = mode;
91-
yield return _currentMode.OnStart();
92-
93-
_switchingTo = null;
94-
}
9558
}
9659
}

Assets/Framework/GameMode.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

Assets/Framework/GameState.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Player.States;
2+
3+
namespace Framework {
4+
public class GameState : BaseState {
5+
protected GameManager Manager;
6+
7+
protected virtual void Awake() {
8+
Manager = GetComponent<GameManager>();
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)