반응형
250x250
Notice
Recent Posts
Recent Comments
Link
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

가끔 보자, 하늘.

ui 이벤트가 일반 input 이벤트 구분하기 본문

개발 이야기/개발 및 서비스

ui 이벤트가 일반 input 이벤트 구분하기

가온아 2016. 1. 11. 14:10

유니티에서 ui를 클릭 혹은 터치해도 게임 중 입력 이벤트를 처리하는 부분에서 계속 문제가 발생했다. 


게임 ui를 유니티의 ui로 만들지 않았을때는 몰랐는데, 이거 어떻게 처리해야 할지 한동안 고민이 많았는데...


EventSystem.current.IsPointerOverGameObject 라는 함수가 있는지 몰라서 한참 고생했네;;


아래와 같은 클래스를 하나 추가해서 처리.

using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;

public class InputEventManager : MonoBehaviour {
     public bool GetMouseDown(int _idx){
        if (EventSystem.current.IsPointerOverGameObject())
            return false;

        return Input.GetMouseButtonDown(_idx);
    }

    public bool GetMouseUp(int _idx){
        if (EventSystem.current.IsPointerOverGameObject())
            return false;

        return Input.GetMouseButtonUp(_idx);
    }

    public bool GetMouse(int _idx){
        if (EventSystem.current.IsPointerOverGameObject())
            return false;

        return Input.GetMouseButton(_idx);
    }

    static InputEventManager mInst;
    public static InputEventManager Inst {
        get{
            if (mInst == null) {
                GameObject go = new GameObject ();
                go.name = "InputEventManager";
                mInst = go.AddComponent<InputEventManager> ();
            }
            return mInst;
        }
    }
}




이전 버전에서는 IsPointerOverEventSystemObject  라는 이름으로 쓰였는데, 이름이 조금 달라져서 애매한데, 일단 잘 작동은 하는 듯. 

반응형