/// <summary>
        /// Called by the manager when the state machine hierarchy is initializing
        /// </summary>
        public override void Initialize(NavStateContext context, NavStateMachine stateMachine)
        {
            base.Initialize(context, stateMachine);

            NavState[] states = NavStateUtils.GetChildren(this);

            foreach (var state in states)
            {
                state.Initialize(m_context, this);
            }
        }
        private void InternalNavigateTo(NavState destination)
        {
            // TODO: Handle where navigation is requested while a state is loading.
            UnityEngine.Debug.Assert(m_navigationPlan.IsComplete, "Navigation was requested before navigation finished!");

            m_navigationPlan.Reset();
            m_navigationPlan.OriginState = CurrentState;

            NavStateUtils.GetParents(destination, m_parentsScratch);
            m_parentsScratch.Reverse();

            NavStateMachine parentToEnterFrom = null;

            // Determine the states to be entered
            for (var index = 0; index < m_parentsScratch.Count; index++)
            {
                NavStateMachine parent = m_parentsScratch[index];
                if (parentToEnterFrom == null && NavStateUtils.NeedsToBeEntered(parent))
                {
                    parentToEnterFrom = parent;
                }

                if (parentToEnterFrom != null)
                {
                    m_navigationPlan.AddStateToEnter(parent);
                }
            }

            m_navigationPlan.AddStateToEnter(destination);

            // Check if the destination is a state machine and repeatedly add the default state until we get to a leaf.
            if (!AddDefaultStatesToEnter(destination))
            {
                return;
            }

            parentToEnterFrom = parentToEnterFrom == null ? destination.StateMachine : parentToEnterFrom.StateMachine;

            // Determine the states that will be exited
            EnqueueStatesToLeave(parentToEnterFrom);

            m_navigationPlan.NavigationStarted();

            // Begin the unloading process
            StartUnloadingStatesToLeave();

            UpdateCurrentState();
        }