티스토리 뷰

반응형

이 글은 정확한 주석이 아닙니다.

 

 

안녕하세요. Base Of Coding입니다.

이번엔, Steam VR에서 제공하는 스크립트 중에, UIElement 라는 스크립트의 주석을 달아봤습니다.

VR에 대해서 많이 아시는 분이시라면, 틀린 부분이 있다면 확인 후 꼭 댓글로 글 남겨주시길 바라겠습니다.

VR 초보라서요ㅠㅠ

 

//======= Copyright (c) Valve Corporation, All rights reserved. ===============
//
// Purpose: UIElement that responds to VR hands and generates UnityEvents
//
//=============================================================================

using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using System;

namespace Valve.VR.InteractionSystem
{
	//-------------------------------------------------------------------------
	[RequireComponent( typeof( Interactable ) )]
	public class UIElement : MonoBehaviour
	{
		public CustomEvents.UnityEventHand onHandClick;     // CustomEvents의 UnityEventHand라는, 이벤트 함수형의 변수, UnityEventHand는 Hand 클래스를 참조한다.

        protected Hand currentHand;         // Hand 클래스 변수

		//-------------------------------------------------
		protected virtual void Awake()
		{
			Button button = GetComponent<Button>();     // 현재 이 스크립트가 붙어있는 곳의 Button 컴포넌트를 참조받는다.
			if ( button )       // button이 null이 아니라면
			{
				button.onClick.AddListener( OnButtonClick );            // OnButtonClick 이란 함수를, button의 Listener로 추가한다.
			}
		}

        /// <summary>
        /// Button에 Contorller를 가져다 올릴 때의 기능 함수
        /// </summary>
        /// <param name="hand">Hand 클래스 매개변수</param>
		protected virtual void OnHandHoverBegin( Hand hand )                    
		{
			currentHand = hand;                                                 // currentHand에 매개변수로 받은 hand를 대입.

            InputModule.instance.HoverBegin( gameObject );                      // 해당 스크립트를 가지고 있는 게임오브젝트를 InputModule에 있는 HoverBegin이라는 함수로 보내서, 
                                                                                // PointerEventData라는, 포인터 이벤트와 관련된 이벤트 페이로드를 생성하여, IPointerEnterHandler와 이벤트 페이로드를
                                                                                // 해당 스크립트를 가지고 있는 GameObject에 보낸다. 
                                                                                // ( 즉, 쉽게 설명하자면, IPointerEnterHandler라는 이벤트를 gameObject에 보낸다. )

            ControllerButtonHints.ShowButtonHint( hand, hand.uiInteractAction); // ControllerButtonHints 클래스의 ShowButtonHint 함수에 hand와 hand의 uiInterctAction -> Interaction 액션을 매개변수로
                                                                                // 사용하여, 버튼의 hint를 보여준다.. 내가 썼는데도 뭔 말인지 모르겠다.
		}

        /// <summary>
        /// Button에 Controller를 뗐을 때의 기능 함수
        /// </summary>
        /// <param name="hand">Hand 클래스 매개변수</param>
        protected virtual void OnHandHoverEnd( Hand hand )                          
		{
			InputModule.instance.HoverEnd( gameObject );                            // 해당 스크립트를 가지고 있는 게임오브젝트를 InputModule에 있는 HoverEnd라는 함수로 보내서,
                                                                                    // PointerEventData라는 포인터 이벤트와 관련된 이벤트 페이로드를 생성하여, IPointerExitHandler와 이벤트 페이로드를
                                                                                    // 해당 스크립트를 가지고 있는 GameObject로 보낸다.
                                                                                    // ( 즉, 쉽게 설명하자면, IPointerExitHandler라는 이벤트를 gameObject에 보낸다. )

            ControllerButtonHints.HideButtonHint( hand, hand.uiInteractAction);     // ControllerButtonHints 클래스의 HideButtonHint 함수에 hand와 hand의 uiInterctAction -> Interaction 액션을 매개변수로
                                                                                    // 사용하여, 버튼의 hint를 꺼준다.. 내가 썼는데도 뭔 말인지 모르겠다.

            currentHand = null;                                                     // 버튼에서 손을 뗐기 때문에 currentHand는 null이 된다.
		}


        /// <summary>
        /// Controller가 현재 어느 상태인지( 충돌되거나, 충돌이 안되었을 때 2가지 상태 )를 갱신하여, 상태를 확인하는 함수
        /// </summary>
        /// <param name="hand">Hand 클래스 매개변수</param>
        protected virtual void HandHoverUpdate( Hand hand )
		{
			if ( hand.uiInteractAction != null && hand.uiInteractAction.GetStateDown(hand.handType) )       // InteractAction이 비어있지 않고, 충돌되고 나서, 버튼을 누른 상태라면
			{
				InputModule.instance.Submit( gameObject );                                  // gameObject를 InputModule의 Submit 함수에 매개변수로 넘긴다.
                                                                                            // 컨트롤러가 버튼에 붙고, 트리거를 클릭한다면, OnSubmit 함수를 실행시키게 한다.
                                                                                            // ( 확실하진 않음, 한 70% 확실한 듯함. )

                ControllerButtonHints.HideButtonHint( hand, hand.uiInteractAction);         // 트리거를 클릭했다면, 힌트는 필요없기 때문에, HidButtonHint 함수를 실행시킨다.
			}
		}

        /// <summary>
        /// 버튼을 클릭했을 때의 함수.
        /// </summary>
        protected virtual void OnButtonClick()
		{
			onHandClick.Invoke( currentHand );          // onHandClick 이벤트에. 등록되어 있는 콜백을 실행시킨다. currentHand를 매개변수로 보내서!
		}
	}

#if UNITY_EDITOR
	//-------------------------------------------------------------------------
	[UnityEditor.CustomEditor( typeof( UIElement ) )]
	public class UIElementEditor : UnityEditor.Editor
	{
		//-------------------------------------------------
		// Custom Inspector GUI allows us to click from within the UI
		//-------------------------------------------------
		public override void OnInspectorGUI()
		{
			DrawDefaultInspector();         // 내장 인스펙터를 그려낸다.

			UIElement uiElement = (UIElement)target;        // UIElement를 target으로 잡는다.
			if ( GUILayout.Button( "Click" ) )              // UIElement 스크립트에, Click이라는, 버튼을 생성한다.
			{
				InputModule.instance.Submit( uiElement.gameObject );        // Click이라는, 버튼을 클릭하면
                                                                            // InputModule이라는 클래스에 있는 Submit 함수에, uiElement를 넘기고, OnSubmit 함수를 실행시키게 한다.
            }
        }
	}
#endif
}

 

지금까지 VR 초보 Base Of Coding이였습니다. 감사합니다.

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
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
글 보관함