コード例 #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;
    }
コード例 #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);
        }
コード例 #3
0
    public void StoreState()
    {
        ++stateIndex;
        ITimeState temp = GetState();

        if (states.Count <= stateIndex)
        {
            states.Add(temp);
            timeStamps.Add(instanceTime);
        }
        else
        {
            states [stateIndex]     = temp;
            timeStamps [stateIndex] = instanceTime;
        }
    }
コード例 #4
0
    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);
    }
コード例 #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;
        }
    }
コード例 #6
0
 protected abstract ITimeState GetInterpolatedState(ITimeState previousState, ITimeState nextState, float ratio);
コード例 #7
0
 protected abstract void SetToState(ITimeState s);
コード例 #8
0
 public Meal(ITimeState nowState)
 {
     this.nowState = nowState;
 }
コード例 #9
0
 public void TimeProceed()
 {
     nowState = nowState.TimeProceed();
 }