Exemple #1
0
    protected override void SetToState(ITimeState state)
    {
        UnityEngine.Assertions.Assert.IsTrue(state is State);

        tf.position = ((State)state).position;

        Rigidbody rb = GetComponent <Rigidbody> ();

        if (rb != null)
        {
            rb.WakeUp();
        }
        isDead = false;
    }
Exemple #2
0
        private static void Main(string[] args)
        {
            ITimeState currentTimeState = TimeStateFactory.GetTimeState();

            List <string> menuItems = currentTimeState.GetMenu();

            DrawMenu(menuItems);
            string selectedMenuItem = GetUserSelectedMenuItem(menuItems);

            IFoodProductFactory foodFactory = currentTimeState.GetFoodFactory();
            FoodProduct         foodProduct = foodFactory.GetFoodProduct(selectedMenuItem);

            Console.WriteLine("You have bought " + foodProduct.ToString() + " leva");
            Console.ReadKey(true);
        }
    public void StoreState()
    {
        ++stateIndex;
        ITimeState temp = GetState();

        if (states.Count <= stateIndex)
        {
            states.Add(temp);
            timeStamps.Add(instanceTime);
        }
        else
        {
            states [stateIndex]     = temp;
            timeStamps [stateIndex] = instanceTime;
        }
    }
    protected override ITimeState GetInterpolatedState(ITimeState previousTimeState, ITimeState nextTimeState, float lerpRatio)
    {
        PhysicsState interpolatedState = new PhysicsState();
        PhysicsState previousState     = (PhysicsState)previousTimeState;
        PhysicsState nextState         = (PhysicsState)nextTimeState;

        interpolatedState.position = Vector3.Lerp(previousState.position, nextState.position, lerpRatio);

        //Chose discontinuous rotation over slerp to match how it's done in-game
        //interpolatedState.rotation = Quaternion.Slerp (previousState.rotation, nextState.rotation, lerpRatio);
        interpolatedState.rotation = nextState.rotation;

        interpolatedState.velocity                 = Mathf.Lerp(previousState.velocity, nextState.velocity, lerpRatio);
        interpolatedState.velocityDirection        = Vector3.Slerp(previousState.velocityDirection, nextState.velocityDirection, lerpRatio);
        interpolatedState.angularVelocity          = Mathf.Lerp(previousState.angularVelocity, nextState.angularVelocity, lerpRatio);
        interpolatedState.angularVelocityDirection = Vector3.Slerp(previousState.angularVelocityDirection, nextState.angularVelocityDirection, lerpRatio);

        interpolatedState.storedVelocity        = Mathf.Lerp(previousState.storedVelocity, nextState.storedVelocity, lerpRatio);
        interpolatedState.storedAngularVelocity = Mathf.Lerp(previousState.storedAngularVelocity, nextState.storedAngularVelocity, lerpRatio);

        return(interpolatedState);
    }
Exemple #5
0
    private void StoreStates(int numberOfStates = 1)
    {
        Debug.Assert(numberOfStates > 0);

        ITimeState currentState = GetCurrentState();

        if (currentStateIndex >= 0 && numberOfStates > 1)
        {
            ITimeState previousState = states [currentStateIndex];
            for (int i = 1; i < numberOfStates; ++i)
            {
                ++currentStateIndex;
                float      ratio    = (float)i / (float)numberOfStates;
                ITimeState midState = GetInterpolatedState(previousState, currentState, ratio);
                //
                if (states.Count <= currentStateIndex)
                {
                    states.Add(midState);
                }
                else
                {
                    states [currentStateIndex] = midState;
                }
            }
        }

        ++currentStateIndex;
        if (states.Count <= currentStateIndex)
        {
            states.Add(currentState);
        }
        else
        {
            states [currentStateIndex] = currentState;
        }
    }
Exemple #6
0
 protected abstract ITimeState GetInterpolatedState(ITimeState previousState, ITimeState nextState, float ratio);
 protected abstract void SetToState(ITimeState s);
Exemple #8
0
 public Meal(ITimeState nowState)
 {
     this.nowState = nowState;
 }
Exemple #9
0
 public void TimeProceed()
 {
     nowState = nowState.TimeProceed();
 }