using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
namespace KairoEngine.GameTools.InteractionTools
{
///
/// Manages which interaction tool is currently on.
///
public class InteractionToolsManager : MonoBehaviour
{
public static InteractionToolsManager instance;
[ReadOnly] public int currentTools = 0;
public bool showDebug = false;
public List tools = new List();
[HideInInspector] public List toolInterfaces = new List();
private void Awake()
{
if(instance == null) instance = this;
else Destroy(this);
}
private void Start()
{
RegisterInterfaces();
ChangeTool(currentTools);
}
private void RegisterInterfaces()
{
toolInterfaces = new List();
for (int i = 0; i < tools.Count; i++)
{
IInteractionTool toolInterface = tools[i].GetComponent();
if(toolInterface == null) toolInterface = tools[i].GetComponentInChildren();
if(toolInterface != null)
{
if(showDebug) Debug.Log($"Registered tool: {tools[i].name} ({i})");
toolInterfaces.Add(toolInterface);
}
else Debug.LogError($"No Interaction tool interface found in components on \"{tools[i].name}\"", tools[i]);
}
}
public void ChangeTool(int toolIndex)
{
if(toolIndex == currentTools) return;
if(showDebug) Debug.Log($"Changing tool to {tools[toolIndex].name} ({toolIndex})");
currentTools = toolIndex;
for (int i = 0; i < toolInterfaces.Count; i++)
{
if(i != toolIndex) toolInterfaces[i].DisableTool();
else toolInterfaces[i].EnableTool();
}
}
}
}