Пример #1
0
    // Update is called once per frame
    void Update()
    {
        preTimer = timer;
        timer   += Time.deltaTime;

        switch (state)
        {
        case State.None:
            nextState = State.Play;
            break;

        case State.Play:
            if (pieceFinishedNum == pieceNum)
            {
                nextState = State.Clear;
            }

            break;

        case State.Clear:
        {
            const float playSEDelay = 0.4f;
            if (preTimer < playSEDelay && playSEDelay <= timer)
            {
                gameSceneControl.PlaySound(GameSceneControl.SoundEffect.Complete);
                isDisplayCleared = true;
            }
        }
        break;
        }

        if (nextState != State.None)
        {
            switch (nextState)
            {
            case State.Play:
            {
                activePieces.Clear();
                activePieces.AddRange(allPieces);
                pieceFinishedNum = 0;
                ShufflePieces();
                foreach (var piece in activePieces)
                {
                    piece.Restart();
                }

                SetHeightOffsetToPieces();
                break;
            }
            }

            state     = nextState;
            nextState = State.None;
            timer     = 0.0f;
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case State.None:
            nextState = State.Restart;
            break;

        case State.Idle:
            if (isDragging)
            {
                nextState = State.Dragging;
            }
            break;

        case State.Dragging:
        {
            DoDragging();
            var color = Color.white;
            if (IsInAttachRange())
            {
                color = Color.green;
                if (!isDragging)
                {
                    nextState    = State.Attaching;
                    attachTarget = finishedPositon;
                    gameSceneControl.PlaySound(GameSceneControl.SoundEffect.Attach);
                }
            }
            else
            {
                if (!isDragging)
                {
                    nextState = State.Idle;
                    gameSceneControl.PlaySound(GameSceneControl.SoundEffect.Release);
                }
            }
            GetComponent <Renderer>().material.color = color;
            break;
        }

        case State.Attaching:
            var distance = attachTarget - transform.position;
            distance *= 0.5f;
            float minMoveDistance = AttachSpeedMin * Time.deltaTime;
            float maxMoveDistacne = AttachSpeedMax * Time.deltaTime;
            if (distance.magnitude < minMoveDistance)
            {
                transform.position = attachTarget;
            }
            else if (distance.magnitude > maxMoveDistacne)
            {
                distance *= maxMoveDistacne / distance.magnitude;
            }

            transform.position = transform.position + distance;

            if (Vector3.Distance(transform.position, attachTarget) < 0.0001f)
            {
                nextState = State.Finished;
            }
            break;
        }

        if (nextState != State.None)
        {
            switch (nextState)
            {
            case State.Idle:
                SetHeightOffset(heightOffset);
                break;

            case State.Restart:
                transform.position = startPositon;
                nextState          = State.Idle;
                break;

            case State.Dragging:
                BeginDragging();
                puzzleControl.PickPiece(this);
                gameSceneControl.PlaySound(GameSceneControl.SoundEffect.Grab);
                break;

            case State.Finished:
                transform.position = finishedPositon;
                puzzleControl.FinishPiece(this);
                GetComponent <Renderer>().material.color = Color.white;
                break;
            }
            state     = nextState;
            nextState = State.None;
        }
    }