A robust and reusable service for managing file deletions in Unity projects. This service supports both immediate and delayed file deletions and is designed to work seamlessly in Unity's runtime environment, including on Android and other platforms.
- Immediate File Deletion: Delete files instantly.
- Delayed File Deletion: Schedule file deletions with customizable delays.
- Batch File Deletion: Delete multiple files at once, either immediately or with a delay.
- Singleton Design: Ensures a single instance of the service is accessible globally.
- Persistent Object: The service persists across scene loads, ensuring its availability throughout the game lifecycle.
- MonoSingleton: A generic singleton implementation for Unity components.
- ImmortalGameObject: Ensures the game object persists across scenes.
namespace AbyssMoth.Internal.Codebase.Runtime.Common.Components
{
[DisallowMultipleComponent]
public sealed class ImmortalGameObject : MonoBehaviour
{
[SerializeField] private bool setParentNull = true;
private void Awake()
{
if (setParentNull)
transform.SetParent(null);
DontDestroyOnLoad(gameObject);
}
}
}
- WaitForSecondsCache: A utility for reusing
WaitForSeconds
objects to optimize coroutines.
- Attach the
FileDeletionService
to a GameObject or let it initialize automatically as a singleton. - The service requires no manual configuration and will persist across scenes.
FileDeletionService.Instance.DeleteFileImmediately("/path/to/file.json");
FileDeletionService.Instance.DeleteFileWithDelay("/path/to/file.json", 5f); // Delete after 5 seconds
string[] filesToDelete = {
"/path/to/file1.json",
"/path/to/file2.json"
};
FileDeletionService.Instance.DeleteMultipleFilesWithDelay(filesToDelete, 10f); // Delete after 10 seconds
The FileDeletionService
is implemented as a singleton using the MonoSingleton pattern. It ensures global accessibility and persistence across scenes.
- Performance Optimization: Using
WaitForSecondsCache
reduces memory allocations in coroutines. - Error Handling: All file operations are wrapped in try-catch blocks to prevent crashes due to file system errors.
- Singleton Access: Ensure you use
FileDeletionService.Instance
to access the service.
This project is part of the Murder Drones Endless Way 2D and is licensed under the copyright of RimuruDev aka AbyssMothGames. For any inquiries, contact:
- Email: rimuru.dev@gmail.com
- GitHub: RimuruDev
- LinkedIn: Profile