/// <summary>
        /// Create and add a new state to track given the new state name.  Also sets the state's event configuration.
        /// </summary>
        /// <param name="stateName">The name of the state to add</param>
        /// <returns>The new state added</returns>
        public InteractionState AddNewState(string stateName)
        {
            // Check if the state name is an empty string
            if (stateName == string.Empty)
            {
                Debug.LogError("The state name entered is empty, please add characters to the state name.");
                return(null);
            }

            // If the state does not exist, then add it
            if (!statesDictionary.ContainsKey(stateName))
            {
                InteractionState newState = new InteractionState(stateName);

                statesDictionary.Add(newState.Name, newState);

                // Add the state to the States list to ensure the inspector displays the new state
                interactionStates.Add(newState);

                // Set the event configuration if one exists for the core interaction state
                EventReceiverManager.SetEventConfiguration(newState);

                // Set special cases for specific states
                SetStateSpecificSettings(newState);

                return(newState);
            }
            else
            {
                Debug.Log($" The {stateName} state is already being tracked and does not need to be added.");
                return(GetState(stateName));
            }
        }
        /// <summary>
        /// Create a new state manager with a given states scriptable object.
        /// </summary>
        /// <param name="states">List of Interaction States for this state manager to watch</param>
        /// <param name="interactiveElement">The interactive element source</param>
        public StateManager(List <InteractionState> states, BaseInteractiveElement interactiveElementSource)
        {
            interactionStates = states;

            // Add the list of InteractionStates to an internal dictionary
            foreach (InteractionState state in states)
            {
                statesDictionary.Add(state.Name, state);
            }

            InteractiveElement = interactiveElementSource;

            // Create a new event receiver manager for this state manager
            EventReceiverManager = new EventReceiverManager(this);

            // Add listeners to the OnStateActivated and OnStateDeactivated events
            AddStateEventListeners();
        }
        // Add listeners to the OnStateActivated and OnStateDeactivated events
        private void AddStateEventListeners()
        {
            // Add listeners to invoke a state event.
            OnStateActivated.AddListener((state) =>
            {
                // If the event configuration for a state is of type StateEvents, this means that the state
                // does not have associated dynamic event data. Therefore, the state event can be invoked when
                // the state value changes without passing in event data.
                if (state.EventConfiguration is StateEvents)
                {
                    EventReceiverManager.InvokeStateEvent(state.Name);
                }
            });

            OnStateDeactivated.AddListener((previousState, currentState) =>
            {
                if (previousState.EventConfiguration is StateEvents)
                {
                    EventReceiverManager.InvokeStateEvent(previousState.Name);
                }
            });
        }
        /// <summary>
        /// Create and add a new state given the state name and the associated existing event configuration.
        /// </summary>
        /// <param name="stateName">The name of the state to create</param>
        /// <param name="eventConfiguration">The existing event configuration for the new state</param>
        /// <returns>The new state added</returns>
        public InteractionState AddNewStateWithCustomEventConfiguration(string stateName, BaseInteractionEventConfiguration eventConfiguration)
        {
            InteractionState state = GetState(stateName);

            if (state == null)
            {
                // Check if the new state name defined is considered a core state
                if (!coreStates.Contains(stateName))
                {
                    InteractionState newState = AddNewState(stateName);

                    if (eventConfiguration != null)
                    {
                        // Set the event configuration if one exists for the core interaction state
                        EventReceiverManager.SetEventConfiguration(newState);
                    }
                    else
                    {
                        Debug.LogError("The event configuration entered is null and the event configuration was not set");
                    }

                    // Add the state to the States list to ensure the inspector displays the new state
                    interactionStates.Add(newState);

                    statesDictionary.Add(newState.Name, newState);
                    return(newState);
                }
                else
                {
                    Debug.LogError($"The state name {stateName} is a defined core state, please use AddCoreState() to add to the States list.");
                    return(null);
                }
            }
            else
            {
                Debug.LogError($"The {stateName} state is already tracking, please use another name.");
                return(state);
            }
        }