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 List tools = new List(); private 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) toolInterfaces.Add(toolInterface); else Debug.LogError($"No Interaction tool interface found in components on \"{tools[i].name}\"", tools[i]); } } public void ChangeTool(int toolIndex) { currentTools = toolIndex; for (int i = 0; i < toolInterfaces.Count; i++) { if(i != toolIndex) toolInterfaces[i].DisableTool(); else toolInterfaces[i].EnableTool(); } } } }