๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Unity

์ฝ”๋ฃจํ‹ด ์‹คํ–‰ ์ค‘์ธ์ง€ ์ฒดํฌํ•˜๊ธฐ

by ใ…Ž-ใ…Ž 2022. 12. 31.

1. bool ๋ณ€์ˆ˜

 

2. int

- ์ฝ”๋ฃจํ‹ด ์‹คํ–‰ ์‹œ +1, ์ข…๋ฃŒ ์‹œ -1

 

3. Action

- IEnumerator ๋ฉ”์†Œ๋“œ์— ์ข…๋ฃŒ ์‹œ ์ˆ˜ํ–‰ํ•  Action ๋„ฃ์–ด์ฃผ๊ธฐ


private void Update()
{
    bool test1, test2;

    StartCoroutine(MoveToDirection(swappingSlotFrom.slotIndex, dragDirection, () =>
    {
        test1 = true;
    }));
    StartCoroutine(MoveToDirection(swappingSlotTo.slotIndex, -dragDirection, () =>
    {
        test2 = true;
    }));
}

public IEnumerator MoveToDirection(Vector2Int slotIndex, Vector2Int direction, Action onFinished = null)
{
    while(true)
    {
        // ...
    }
    
    onFinished?.Invoke();
}

 

4. ๋ฌถ์Œ IEnumerator

private IEnumerator Swap()
{
    isAnimationPlaying = true;

    bool test1 = false, test2 = false;

    MoveToDirection(swappingSlotFrom.slotIndex, dragDirection, () =>
    {
        test1 = true;
    });

    MoveToDirection(swappingSlotTo.slotIndex, -dragDirection, () => {

        test2 = true;
    });

    yield return new WaitWhile(() => test1 && test2);

    isAnimationPlaying = false;
}

 

5. Queue

 

6. ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ

- 1) CustomYieldConstruction ์ƒ์†

- 2) ํด๋ž˜์Šค ์•ˆ์—์„œ ์ฝ”๋ฃจํ‹ด ์‹คํ–‰, ์ข…๋ฃŒ๋ฅผ ๊ด€์žฅ

๋Œ“๊ธ€