본문 바로가기
게임 개발/게임 이론+수학

[게임수학 | 유니티] 16진수와 비트 연산의 활용

by 불타는홍당무 2019. 9. 5.

public enum UIState

{

    None = 0x0000,                                // 0000 0000 0000

    TopUI = 0x0001,                                // 0000 0000 0001

    TopDeco = 0x0002,                                // 0000 0000 0010

     ShipUI = 0x0004,                                // 0000 0000 0100

    HideMailNHeart = 0x0008,                        // 0000 0000 1000

    BottomUI = 0x0010,                                // 0000 0001 0000

    EventUI = 0x0020,                                // 0000 0010 0000

    TopFilter = 0x000f,                                // 0000 0000 1111

    BottomFilter = 0x00f0,                                // 0000 1111 0000

    BlueHeart = 0x0100,                                // 0001 0000 0000

    TopNBottom = TopUI | BottomUI,                // 0000 0001 0001

    TopNEvent = TopUI | EventUI,                        // 0000 0010 0001

    TopHideMail = TopUI | HideMailNHeart,        // 0000 0000 1001

};

 

enum을 16진수로 선언하는 것은 비트연산을 하기 위해서 이다.

|와 & 연산을 응용하면 복잡한 if조건문을 간단히 처리할 수 있다.

 

ex)

TopNBottom = TopUI | BottomUI,                        // 0000 0001 0001

if( ( m_UIState & UIState.TopUI ) == UIState.TopUI )

{

   ...

}