Beispiel #1
0
	void Update () {

        if (Dragging)
        {
            CurSpeed = 0;
        }
        else
        {
            // -- check stability every update
            // we have to keeps checking stable grid in case someelse took it, even during falling !

            Vector2 oldStableGrid = fallTargetGrid;
            Vector2 stableGrid = FindStableGrid();

            //if(!oldStableGrid.Equals(stableGrid))
            //{
            //    Debug.LogWarning("更新稳定位置 " + stableGrid.ToString());
            //}

            if (State == EEleCompState.Stable)
            {
                // basically switch state from stable to falling
                if (!Grid.Equals(stableGrid))
                {
                    // Debug.LogWarning("因底部抽取再次下落");
                    State = EEleCompState.Falling;
                    fallTargetGrid = stableGrid;
                }
                //else if(name == "L")
                //{
                //    print("why " + Grid.ToString() + " -- " + stableGrid.ToString());
                //}
            }

            fallTargetGrid = stableGrid;

            if (State == EEleCompState.Falling)
            {
                Vector3 oldPos = transform.position;
                if (transform.position.y > fallTargetPos.y)
                {
                    CurSpeed += Time.deltaTime * Gravity;
                    CurSpeed = Mathf.Clamp(CurSpeed, 0, MaxSpeed);
                    transform.position = new Vector3(fallTargetPos.x, oldPos.y - Time.deltaTime * CurSpeed, 0);
                }

                if (transform.position.y < fallTargetPos.y)
                {
                    State = EEleCompState.Stable;
                    transform.position = fallTargetPos; 
                }
            }
        }
	}
Beispiel #2
0
    void Update()
    {
        if (Dragging)
        {
            CurSpeed = 0;
        }
        else
        {
            // -- check stability every update
            // we have to keeps checking stable grid in case someelse took it, even during falling !

            Vector2 oldStableGrid = fallTargetGrid;
            Vector2 stableGrid    = FindStableGrid();

            //if(!oldStableGrid.Equals(stableGrid))
            //{
            //    Debug.LogWarning("更新稳定位置 " + stableGrid.ToString());
            //}

            if (State == EEleCompState.Stable)
            {
                // basically switch state from stable to falling
                if (!Grid.Equals(stableGrid))
                {
                    // Debug.LogWarning("因底部抽取再次下落");
                    State          = EEleCompState.Falling;
                    fallTargetGrid = stableGrid;
                }
                //else if(name == "L")
                //{
                //    print("why " + Grid.ToString() + " -- " + stableGrid.ToString());
                //}
            }

            fallTargetGrid = stableGrid;

            if (State == EEleCompState.Falling)
            {
                Vector3 oldPos = transform.position;
                if (transform.position.y > fallTargetPos.y)
                {
                    CurSpeed          += Time.deltaTime * Gravity;
                    CurSpeed           = Mathf.Clamp(CurSpeed, 0, MaxSpeed);
                    transform.position = new Vector3(fallTargetPos.x, oldPos.y - Time.deltaTime * CurSpeed, 0);
                }

                if (transform.position.y < fallTargetPos.y)
                {
                    State = EEleCompState.Stable;
                    transform.position = fallTargetPos;
                }
            }
        }
    }