From 9378096a4650dbcff939652825c6b7d4a0599ca2 Mon Sep 17 00:00:00 2001 From: OpOpYaDev Date: Sun, 19 May 2024 20:32:18 +0000 Subject: [PATCH] Merge pull request #15 from techno-dwarf-works/feature/clean-up Version 0.1.8 --- Runtime/Modules/CacheModule.cs | 16 ++++++++++++++-- package.json | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Runtime/Modules/CacheModule.cs b/Runtime/Modules/CacheModule.cs index a1da988..b3f5a77 100644 --- a/Runtime/Modules/CacheModule.cs +++ b/Runtime/Modules/CacheModule.cs @@ -90,8 +90,20 @@ public T GetState() DebugUtility.LogException(message); return state; } - - public bool RemoveState() where T : TState + + public T GetOrAddState() + where T : TState, new() + { + if (!TryGetState(out T state)) + { + state = CacheState(); + } + + return state; + } + + public bool RemoveState() + where T : TState { var type = typeof(T); return _stateLocator.Remove(type); diff --git a/package.json b/package.json index cdab267..44f8d4a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.tdw.better.statemachine", "displayName": "Better State Machine", - "version": "0.1.7", + "version": "0.1.8", "unity": "2021.3", "description": " ", "dependencies": {