Пример #1
0
    private void ChangeState(eCampaignCharacterState newState, bool ignoreDeath = false)
    {
        eCampaignCharacterState previousState = _state;

        _state = newState;

        if (_currentHandler != null && !_currentHandler.IsFinished)
        {
            _currentHandler.End(newState);

            CodeObjectManager.GetCharacterStateManager(_currentHandler.GetType()).Destroy(_currentHandler);
        }

        System.Type handlerType = _stateHandlers[State];

        _currentHandler = (CharacterStateHandler)CodeObjectManager.GetCharacterStateManager(handlerType).GetNext();

        _currentHandler.Controller     = _controller;
        _currentHandler.MoveController = _moveController;
        //_currentHandler.Stats = _statsComponent;
        _currentHandler.Locomotion = LocomotionComponent;
        _currentHandler.Combat     = _combatController;
        _currentHandler.ViewRPC    = _viewRPC;
        //_currentHandler.EffectReceiver = _effectReceiver;
        _currentHandler.Conditions = _conditionComponent;
        _currentHandler.Targeting  = _targetingComponent;
        _currentHandler.Character  = this;

        _currentHandler.Begin(previousState);

        _moveController.SetPlaybackSpeed(1.0f);
    }
Пример #2
0
    public static InternalObjManagerNonGeneric GetEventManager(System.Type t)
    {
        CodeObjectManager instance = GameStateManager.Instance.ObjectManager;

        if (!instance._eventManagers.ContainsKey(t))
        {
            instance._eventManagers.Add(t, new InternalObjManagerNonGeneric(t));
        }
        return(instance._eventManagers[t]);
    }
Пример #3
0
    void OnDisable()
    {
        CharacterComponentManager.sCharacterComponents.Remove(this);

        if (_currentHandler != null)
        {
            _currentHandler.End(eCampaignCharacterState.Idle);
            CodeObjectManager.GetCharacterStateManager(_currentHandler.GetType()).Destroy(_currentHandler);
            _currentHandler = null;
        }
    }
Пример #4
0
    public void SetGameState <T>(System.Action <T> transition = null) where T : GameState
    {
        T newStateObj               = typeof(T).GetConstructor(System.Type.EmptyTypes).Invoke(null) as T;
        GameStateAttribute attr     = typeof(T).GetCustomAttributes(typeof(GameStateAttribute), false) [0] as GameStateAttribute;
        eGameState         newState = attr.State;

        StopAllCoroutines();

        if (transition != null)
        {
            transition(newStateObj);
        }

        GameState oldStateObj = _state;

        if (null != oldStateObj)
        {
            oldStateObj.End(newStateObj);
        }
        eGameState previousState = _eState;

        _eState = newState;
        _state  = newStateObj;

        PerformanceManager.Instance.OnGameStateTransition(newState);
        if (ObjectManager != null)
        {
            ObjectManager.End();
        }
        ObjectManager = new CodeObjectManager();
        ObjectManager.Start();

        mNewStateObjs.Add(newStateObj);
        moldStateObjs.Add(oldStateObj);
        EventManager.instance.Raise(new GameStateChangedEvent(previousState, newState));
    }
Пример #5
0
    private void EndSingleTouch(TouchWrapper touch,
                                Transform target,
                                Vector3 location,
                                Vector3 direction,
                                Vector3 groundPosition,
                                bool hasValidNavPoint)
    {
        float singleTouchDuration = Time.time - _singleTouchStartTime;

        if (singleTouchDuration < TapLength)
        {
            if (Time.time - _lastTapTime > DoubleTapLength)
            {
                TapEvent tapEvent = (null != target) ? new TapEvent(touch.position, target, location) : new TapEvent(touch.position, location);
                tapEvent.direction        = direction;
                tapEvent.groundPosition   = groundPosition;
                tapEvent.hasValidNavPoint = hasValidNavPoint;
#if BUFFER_SINGLE_TAPS
                StartCoroutine(QueueSingleTap(tapEvent));
#else
                _lastTapTime  = Time.time;
                _didDoubleTap = false;
                RaiseEvent(tapEvent);
#endif
            }
            else
            {
                DoubleTapEvent doubleTapEvent = (null != target) ? new DoubleTapEvent(touch.position, target, location) : new DoubleTapEvent(touch.position, location);
                doubleTapEvent.direction = direction;
                DoDoubleTap(doubleTapEvent);
            }
        }
        else if (_touchStartedOnPlayer)
        {
            DragFromPlayerGestureEndEvent evt = null;
            if (target)
            {
                evt = new DragFromPlayerGestureEndEvent(touch.position, target);
            }
            else
            {
                evt = new DragFromPlayerGestureEndEvent(touch.position, location);
            }
            evt.direction      = direction;
            evt.groundPosition = groundPosition;
            RaiseEvent(evt);
            _touchStartedOnPlayer = false;
        }

        TouchEndEvent endEvent = (TouchEndEvent)CodeObjectManager.GetEventManager(typeof(TouchEndEvent)).GetNext();;
        if (target != null)
        {
            endEvent.Initialize(touch.position, target, location);
        }
        else
        {
            endEvent.Initialize(touch.position, location);
        }
        endEvent.direction      = direction;
        endEvent.groundPosition = groundPosition;
        RaiseEvent(endEvent);
        CodeObjectManager.GetEventManager(typeof(TouchEndEvent)).Destroy(endEvent);

        //check for flick gesture
        float flick_history_check = 1.5f;
        float time_look_back      = 0.0f;
        int   i           = 0;
        int   touch_index = m_touch_history_index - 1 > 0 ? m_touch_history_index - 1: TOUCH_HISTORY_LENGTH - 1;

        Vector3 flick_vel  = Vector3.zero;
        float   last_time  = _touchHistory[touch_index]._time;
        Vector3 last_flick = touch.position;
        while (time_look_back < flick_history_check && i < TOUCH_HISTORY_LENGTH - 1)
        {
            if (_touchHistory[touch_index]._time == 0.0f)
            {
                break;
            }

            float time = last_time - _touchHistory[touch_index]._time;
            last_time = _touchHistory[touch_index]._time;

            time_look_back += time;
            flick_vel      += _touchHistory[touch_index]._position - last_flick;
            last_flick      = _touchHistory[touch_index]._position;

            i++;
            touch_index = touch_index - 1 > 0 ? touch_index - 1 : TOUCH_HISTORY_LENGTH - 1;
        }

        //EB.Debug.Log (i);
        if (time_look_back > 0.0f)
        {
            flick_vel *= time_look_back;
            if (flick_vel.magnitude > 0.2f)
            {
                FlickEvent flickEvent = new FlickEvent();
                flickEvent.Initialize(touch.position, flick_vel);
                RaiseEvent(flickEvent);
            }
            else
            {
                //EB.Debug.Log ("VEL FAIL");
            }
        }
        else
        {
            //EB.Debug.Log ("TIME FAIL");
        }


        ResetTouchHistory();
    }
Пример #6
0
    private void UpdateSingleTouch(TouchWrapper touch,
                                   Transform target,
                                   Vector3 location,
                                   Vector3 direction,
                                   Vector3 groundPosition,
                                   bool hasValidNavPoint)
    {
        float touchDuration = Time.time - _singleTouchStartTime;

        float selfSelectRadiusSq = GlobalBalanceData.Instance.selfSelectRadius;

        selfSelectRadiusSq *= selfSelectRadiusSq;

        if (touchDuration < TapLength)
        {
            // Do nothing yet
        }
        else if (!_longPressStarted)
        {
            // This press is longer than a tap
            _longPressStarted = true;

            TouchStartEvent startEvent = (TouchStartEvent)CodeObjectManager.GetEventManager(typeof(TouchStartEvent)).GetNext();
            if (target)
            {
                startEvent.Initialize(touch.position, target, location);
            }
            else
            {
                startEvent.Initialize(touch.position, location);
            }
            startEvent.direction      = direction;
            startEvent.groundPosition = groundPosition;
            startEvent.deltaPosition  = touch.deltaPosition;
            RaiseEvent(startEvent);
            CodeObjectManager.GetEventManager(typeof(TouchStartEvent)).Destroy(startEvent);
        }
        else if (_touchStartedOnPlayer)
        {
            if (!_playerLongPressStarted)
            {
                if (GameUtils.GetDistSqXZ(groundPosition, _playerTransform.position) > selfSelectRadiusSq)
                {
                    DragFromPlayerGestureStartEvent evt = null;
                    if (target)
                    {
                        evt = new DragFromPlayerGestureStartEvent(touch.position, target);
                    }
                    else
                    {
                        evt = new DragFromPlayerGestureStartEvent(touch.position, location);
                    }
                    evt.direction      = direction;
                    evt.groundPosition = groundPosition;
                    RaiseEvent(evt);
                    _playerLongPressStarted = true;
                }
            }
            else
            {
                DragFromPlayerGestureUpdateEvent evt = null;
                if (target)
                {
                    evt = new DragFromPlayerGestureUpdateEvent(touch.position, target);
                }
                else
                {
                    evt = new DragFromPlayerGestureUpdateEvent(touch.position, location);
                }
                evt.direction      = direction;
                evt.groundPosition = groundPosition;
                RaiseEvent(evt);
            }
        }
        else
        {
            TouchUpdateEvent updateEvent = (TouchUpdateEvent)CodeObjectManager.GetEventManager(typeof(TouchUpdateEvent)).GetNext();;
            if (target != null)
            {
                updateEvent.Initialize(touch.position, target, location);
            }
            else
            {
                updateEvent.Initialize(touch.position, location);
            }
            updateEvent.direction        = direction;
            updateEvent.groundPosition   = groundPosition;
            updateEvent.hasValidNavPoint = hasValidNavPoint;
            RaiseEvent(updateEvent);
            CodeObjectManager.GetEventManager(typeof(TouchUpdateEvent)).Destroy(updateEvent);
        }

        //add the touch to the touch history for gesture checking on end
        _touchHistory[m_touch_history_index]._time     = Time.realtimeSinceStartup;
        _touchHistory[m_touch_history_index]._position = touch.position;
        m_touch_history_index = (m_touch_history_index + 1) % TOUCH_HISTORY_LENGTH;
    }