Skip to content

Commit 6242a78

Browse files
authored
Update Doc
1 parent 3d1ae47 commit 6242a78

File tree

1 file changed

+123
-1
lines changed

1 file changed

+123
-1
lines changed

README.md

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,125 @@
1+
# WaitForSecondsCache and WaitForSecondsDebugView Documentation
12

3+
This project introduces a caching system for `WaitForSeconds` in Unity to optimize the creation of identical timers and a debug view for monitoring cached timers in the Unity Editor.
24

3-
Dependency - [MonoSingleton](https://github.com/RimuruDev/MonoSingleton)
5+
---
6+
7+
## Table of Contents
8+
1. [Overview](#overview)
9+
2. [Features](#features)
10+
3. [Usage](#usage)
11+
4. [Debug View](#debug-view)
12+
5. [Dependencies](#dependencies)
13+
6. [Integration](#integration)
14+
7. [Contributions](#contributions)
15+
16+
---
17+
18+
## Overview
19+
20+
The `WaitForSecondsCache` class provides a simple and efficient caching mechanism for `WaitForSeconds` objects. This reduces memory allocation overhead and improves performance, especially in projects where timers with identical durations are used frequently.
21+
22+
The `WaitForSecondsDebugView` is a utility designed to help developers monitor and debug cached timers during development.
23+
24+
---
25+
26+
## Features
27+
28+
- **Efficient caching**: Avoids redundant creation of `WaitForSeconds` objects.
29+
- **Debugging support**: View and monitor cached timers in the Unity Editor.
30+
- **Singleton design**: The `WaitForSecondsDebugView` leverages a `MonoSingleton` implementation for centralized management.
31+
- **Editor-only Debugging**: The debug view is included only when the project is running in the Unity Editor.
32+
33+
---
34+
35+
## Usage
36+
37+
### Caching Timers
38+
39+
To retrieve or cache a `WaitForSeconds` object:
40+
```csharp
41+
WaitForSeconds wait = WaitForSecondsCache.Get(0.5f);
42+
yield return wait;
43+
```
44+
45+
### Resetting the Cache
46+
47+
To clear all cached timers:
48+
```csharp
49+
WaitForSecondsCache.Reset();
50+
```
51+
52+
### Accessing the Cache Directly
53+
54+
To get a read-only view of the current cache:
55+
```csharp
56+
var cache = WaitForSecondsCache.GetCache();
57+
foreach (var entry in cache)
58+
{
59+
Debug.Log($"Time: {entry.Key}, WaitForSeconds: {entry.Value}");
60+
}
61+
```
62+
63+
---
64+
65+
## Debug View
66+
67+
The `WaitForSecondsDebugView` provides a GUI for monitoring cached timers in the Unity Editor.
68+
69+
### Features
70+
- Displays all currently cached `WaitForSeconds` objects.
71+
- Allows enabling/disabling the debug view via an Inspector toggle.
72+
73+
### GUI Example
74+
75+
The debug view appears in the top-left corner of the game view when running in the Editor:
76+
```
77+
WaitForSeconds Cache Debug View:
78+
Time: 0.5 seconds
79+
Time: 1.0 seconds
80+
Time: 2.0 seconds
81+
```
82+
83+
### Enable/Disable Debugging
84+
85+
You can enable or disable the debug view using the `enableDebugView` checkbox in the `WaitForSecondsDebugView` component.
86+
87+
---
88+
89+
## Dependencies
90+
91+
- **MonoSingleton**: The `WaitForSecondsDebugView` relies on a generic MonoSingleton implementation, which can be found [here](https://github.com/RimuruDev/MonoSingleton.git).
92+
93+
To integrate the MonoSingleton, ensure the following class is available in your project:
94+
```csharp
95+
namespace AbyssMoth.Internal.Codebase.Runtime._MainMenuModule.User
96+
{
97+
public abstract class MonoSingleton<TComponent> : MonoBehaviour where TComponent : Component
98+
{
99+
// Implementation here (already included in the project).
100+
}
101+
}
102+
```
103+
104+
---
105+
106+
## Integration
107+
108+
1. Add the `WaitForSecondsCache` and `WaitForSecondsDebugView` classes to your project.
109+
2. Ensure the `MonoSingleton` implementation is present in your codebase.
110+
3. Add the `WaitForSecondsDebugView` to a GameObject in your scene or let it auto-instantiate.
111+
112+
---
113+
114+
## Contributions
115+
116+
Contributions are welcome! If you find a bug or have a suggestion, feel free to open an issue or a pull request.
117+
118+
For questions, contact me:
119+
- **Email**: [email protected]
120+
- **LinkedIn**: [Rimuru's Profile](https://www.linkedin.com/in/rimuru/)
121+
- **GitHub**: [Rimuru's GitHub](https://github.com/RimuruDev)
122+
123+
---
124+
125+
**License**: Open Source, available under the MIT License.

0 commit comments

Comments
 (0)