ProjectDDD/Assets/_DDD/_Scripts/Restaurant/State/FlowStates/RestaurantEnvironmentState.cs

107 lines
4.0 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
namespace DDD.Restaurant
{
[Serializable]
public class RestaurantPropLocation
{
public string Id;
public Vector2 Position;
public RestaurantPropLocation(string id, Vector2 position)
{
Id = id;
Position = position;
}
}
public class RestaurantEnvironmentState : ScriptableObject
{
public List<RestaurantPropLocation> Props = new List<RestaurantPropLocation>();
public List<RestaurantPropLocation> Objects = new List<RestaurantPropLocation>();
// 인터랙션 가능한 객체(IInteractable)를 관리하기 위한 리스트 (런타임 전용)
private readonly List<IInteractable> _registeredInteractables = new List<IInteractable>();
private readonly List<IEnvironmentPointProvider> _registeredPointProviders = new List<IEnvironmentPointProvider>();
/// <summary>
/// 인터랙션 가능한 객체를 등록합니다
/// </summary>
public void RegisterInteractable(IInteractable interactable)
{
if (interactable == null) return;
if (_registeredInteractables.Contains(interactable)) return;
_registeredInteractables.Add(interactable);
}
public void RegisterPointProvider(IEnvironmentPointProvider provider)
{
if (provider == null) return;
if (_registeredPointProviders.Contains(provider)) return;
_registeredPointProviders.Add(provider);
}
/// <summary>
/// 인터랙션 가능한 객체를 해제합니다
/// </summary>
public void UnregisterInteractable(IInteractable interactable)
{
if (interactable == null) return;
_registeredInteractables.Remove(interactable);
}
public void UnRegisterPointProvider(IEnvironmentPointProvider provider)
{
if (provider == null) return;
_registeredPointProviders.Remove(provider);
}
/// <summary>
/// 특정 InteractionType에 해당하는 인터랙션 객체들을 반환합니다
/// </summary>
public List<IInteractable> GetInteractablesByType(InteractionType interactionType)
{
var result = new List<IInteractable>();
// null 또는 Destroyed 오브젝트 정리
_registeredInteractables.RemoveAll(item => item == null || (item as UnityEngine.Object) == null);
foreach (var interactable in _registeredInteractables)
{
if (interactable.GetInteractionType() == interactionType)
{
result.Add(interactable);
}
}
return result;
}
public List<IEnvironmentPointProvider> GetPointProviderByType(PointType pointType)
{
var result = new List<IEnvironmentPointProvider>();
// null 또는 Destroyed 오브젝트 정리
_registeredPointProviders.RemoveAll(item => item == null || (item as UnityEngine.Object) == null);
foreach (var provider in _registeredPointProviders)
{
if (!provider.IsSupportsType(pointType)) continue;
result.Add(provider);
}
return result;
}
/// <summary>
/// 모든 등록된 인터랙션 객체들을 반환합니다
/// </summary>
public List<IInteractable> GetAllInteractables()
{
_registeredInteractables.RemoveAll(item => item == null || (item as UnityEngine.Object) == null);
return new List<IInteractable>(_registeredInteractables);
}
public List<IEnvironmentPointProvider> GetAllPointProviders()
{
_registeredPointProviders.RemoveAll(item => item == null || (item as UnityEngine.Object) == null);
return new List<IEnvironmentPointProvider>(_registeredPointProviders);
}
}
}