// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" template class ResComStateManager { protected: TArray stateHistory; EnumType nullobj; public: ResComStateManager() : nullobj(EnumType()) { } bool SetState(const EnumType& newState) { if (GetState() == newState) return false; stateHistory.Push(newState); return true; } const EnumType& GetState() const { return static_cast(stateHistory.Num()) ? stateHistory[stateHistory.Num() - 1] : nullobj; } bool SetPrevState() { if (stateHistory.Num() < 2) return false; stateHistory.Pop(); return true; } const EnumType& GetPreviousState() const { return (stateHistory.Num() > 1) ? stateHistory[stateHistory.Num() - 2] : GetState(); } void ClearAllStatesBesideLast() { auto lastState = GetState(); stateHistory.Empty(); SetState(lastState); } const TArray& GetHistory() const { return stateHistory; } };