예제 #1
0
        private void switchToNextPosition()
        {
            LocomotionActionEvent locomotionActionEvent = positionTimeline.Dequeue();
            LocomotionController  currentController     = locomotionTracker.GetCurrentController();
            Vector3 vector       = ((currentController != null) ? currentController.GetPosition() : base.transform.position);
            Vector3 wsSteerInput = locomotionActionEvent.Position - vector;

            wsSteerInput.y = 0f;
            if (locomotionActionEvent.Direction.HasValue)
            {
                wsSteerInput = locomotionActionEvent.Direction.Value;
                if (locomotionActionEvent.Type.IsMovement())
                {
                    lastStickDirection = wsSteerInput;
                }
            }
            if (currentController != null && !(currentController is SlideController))
            {
                if (locomotionActionEvent.Type.IsMovement())
                {
                    currentController.Steer(wsSteerInput);
                }
                else if (locomotionActionEvent.Type == LocomotionAction.Rotate)
                {
                    currentController.SteerRotation(wsSteerInput);
                }
            }
            desiredStartEvent  = desiredTargetEvent;
            desiredTargetEvent = locomotionActionEvent;
            startPosition      = vector;
            startFacing        = ((currentController != null) ? currentController.GetFacing() : base.transform.forward);
            state = SyncState.INTERPOLATION;
        }
예제 #2
0
        private void Update()
        {
            if (!receivingEnabled)
            {
                return;
            }
            switch (state)
            {
            case SyncState.IDLE:
                if (positionTimeline.Count > 0)
                {
                    desiredTargetEvent = positionTimeline.Peek();
                    snapIfNeeded(desiredTargetEvent.Position);
                    timer.Reset();
                    timer.Start();
                    state = SyncState.WAITING;
                }
                break;

            case SyncState.WAITING:
                if (timer.ElapsedMilliseconds > InterpolationDelay || positionTimeline.PeekLast().Timestamp - desiredTargetEvent.Timestamp >= InterpolationDelay)
                {
                    timer.Reset();
                    timer.Start();
                    switchToNextPosition();
                    motionSequenceStartTime = desiredStartEvent.Timestamp;
                }
                break;

            case SyncState.INTERPOLATION:
                if (!timeForPosition(desiredStartEvent, desiredTargetEvent))
                {
                    break;
                }
                triggerEventAction(desiredTargetEvent);
                if (positionTimeline.Count == 0)
                {
                    LocomotionController currentController = locomotionTracker.GetCurrentController();
                    if (currentController != null && !(currentController is SlideController))
                    {
                        currentController.Steer(lastStickDirection.normalized);
                    }
                    if (lastStickDirection == Vector3.zero)
                    {
                        timer.Stop();
                        state = SyncState.IDLE;
                    }
                    else
                    {
                        state = SyncState.EXTRAPOLATION;
                    }
                }
                else
                {
                    switchToNextPosition();
                }
                break;

            case SyncState.EXTRAPOLATION:
            {
                LocomotionController currentController = locomotionTracker.GetCurrentController();
                if (positionTimeline.Count == 0)
                {
                    if (timer.ElapsedMilliseconds > MaxExtrapolationTime)
                    {
                        if (currentController != null && !(currentController is SlideController))
                        {
                            currentController.Steer(Vector3.zero);
                        }
                        timer.Stop();
                        lastStickDirection = Vector3.zero;
                        state = SyncState.IDLE;
                    }
                }
                else
                {
                    desiredTargetEvent.Position  = ((currentController != null) ? currentController.GetPosition() : base.transform.position);
                    desiredTargetEvent.Timestamp = motionSequenceStartTime + timer.ElapsedMilliseconds;
                    switchToNextPosition();
                }
                break;
            }
            }
        }