InteractionType 비트연산으로 프리팹에서 설정하기
This commit is contained in:
parent
a3e6818810
commit
eb9ac5a34f
@ -1,14 +1,17 @@
|
|||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DDD
|
namespace DDD
|
||||||
{
|
{
|
||||||
public enum InteractionType
|
[Flags]
|
||||||
|
public enum InteractionType : uint
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0u,
|
||||||
RestaurantManagementUi,
|
RestaurantManagementUi = 1u << 0,
|
||||||
OpenRestaurant,
|
OpenRestaurant = 1u << 1,
|
||||||
Count
|
All = 0xFFFFFFFFu
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IInteractable
|
public interface IInteractable
|
||||||
{
|
{
|
||||||
bool CanInteract();
|
bool CanInteract();
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
|
using Sirenix.OdinInspector;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DDD
|
namespace DDD
|
||||||
{
|
{
|
||||||
public class RestaurantCharacter : MonoBehaviour, IGameCharacter, IInteractor
|
public class RestaurantCharacter : MonoBehaviour, IGameCharacter, IInteractor
|
||||||
{
|
{
|
||||||
|
[EnumToggleButtons, SerializeField] protected InteractionType _interactionType;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
// TODO : Add event solvers dynamically
|
foreach (var typeToSolver in RestaurantInteractionEventSolvers.TypeToSolver)
|
||||||
for (int i = 0; i < (int)InteractionType.Count; i++)
|
|
||||||
{
|
{
|
||||||
InteractionType interactionType = (InteractionType)i;
|
var flag = typeToSolver.Key;
|
||||||
// TODO : if this character should handle the interaction?
|
if (flag == InteractionType.None) continue;
|
||||||
if (RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(interactionType, out var solverType))
|
|
||||||
|
if ((_interactionType & flag) == 0) continue;
|
||||||
|
|
||||||
|
if (!TryGetComponent(typeToSolver.Value, out _))
|
||||||
{
|
{
|
||||||
gameObject.AddComponent(solverType);
|
gameObject.AddComponent(typeToSolver.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user