protected virtual void Update()
    {
        try
        {
            if (_currentBaseControlHandler != null)
            {
                while (!_currentBaseControlHandler.Update())
                {
                    BaseControlHandler poppedHandler = _controlHandlers.Pop();
                    poppedHandler.Dispose();

                    Logger.Info("Popped handler: " + poppedHandler.ToString());
                    TryActivateCurrentControlHandler(poppedHandler);
                }

                // after we updated the control handler, we now want to notify all stack members (excluding the current handler/peek) that an update
                // has occurred. This is necessary in case stacked handlers need to react to actions, for example: melee attack is interrupted by wall jump handler
                for (int i = _controlHandlers.Count - 2; i >= 0; i--)
                {
                    _controlHandlers[i].OnAfterStackPeekUpdate();
                }
            }
        }
        catch (Exception err)
        {
            Logger.Error("Game object " + this.name + " misses default control handler.", err);
            throw;
        }
    }
    /// <summary>
    /// Pushes the control handler.
    /// </summary>
    /// <param name="controlHandler">The control handler.</param>
    public void PushControlHandler(BaseControlHandler controlHandler)
    {
        Logger.Info("Pushing handler: " + controlHandler.ToString());

        _controlHandlers.Push(controlHandler);
        TryActivateCurrentControlHandler(_currentBaseControlHandler);
    }
예제 #3
0
    public void InsertControlHandlerBeforeCurrent(BaseControlHandler controlHandler)
    {
        var index = Mathf.Max(0, _controlHandlers.Count - 1);

        Logger.Info("Inserting handler: " + controlHandler.ToString() + " at index " + index);

        _controlHandlers.Insert(index, controlHandler);
    }
예제 #4
0
    public void InsertControlHandler(int index, BaseControlHandler controlHandler)
    {
        Logger.Info("Inserting handler: " + controlHandler.ToString() + " at index " + index);

        if (index >= _controlHandlers.Count)
        {
            PushControlHandler(controlHandler);
        }
        else
        {
            _controlHandlers.Insert(index, controlHandler);
        }
    }
    private void TryActivateCurrentControlHandler(BaseControlHandler previousControlHandler)
    {
        _currentBaseControlHandler = _controlHandlers.Peek();

        while (_currentBaseControlHandler != null &&
               !_currentBaseControlHandler.TryActivate(previousControlHandler))
        {
            previousControlHandler = _controlHandlers.Pop();
            Logger.Info("Popped handler: " + previousControlHandler.ToString());
            previousControlHandler.Dispose();

            _currentBaseControlHandler = _controlHandlers.Peek();
        }
    }
    /// <summary>
    /// Removes the control handler.
    /// </summary>
    /// <param name="controlHandler">The control handler.</param>
    public void RemoveControlHandler(BaseControlHandler controlHandler)
    {
        Logger.Info("Removing handler: " + controlHandler.ToString());

        if (controlHandler == _currentBaseControlHandler)
        {
            BaseControlHandler poppedHandler = _controlHandlers.Pop();
            poppedHandler.Dispose();

            TryActivateCurrentControlHandler(poppedHandler);
        }
        else
        {
            _controlHandlers.Remove(controlHandler);
            controlHandler.Dispose();
        }
    }
예제 #7
0
    public void ExchangeControlHandler(int index, BaseControlHandler controlHandler)
    {
        Logger.Info("Exchanging handler " + _controlHandlers[index].ToString() + " (index: " + index + ") with " + controlHandler.ToString());

        if (_controlHandlers[index] == _activeControlHandler)
        {
            var poppedHandler = _controlHandlers.Exchange(index, controlHandler);

            poppedHandler.Dispose();

            TryActivateCurrentControlHandler(poppedHandler);
        }
        else
        {
            _controlHandlers.Exchange(index, controlHandler);
        }
    }