TA/Unity
ngui - 계속 누르기 버튼 스크립트
프리랜서 디자이너
2017. 1. 22. 20:35
스크립트(ngui -> UI 폴더)
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class UIRepeatButton : MonoBehaviour
- {
- public float interval = 0.0001525F;
- bool mIsPressed = false;
- float mNextClick = 0f;
- void OnPress (bool isPressed) { mIsPressed = isPressed; mNextClick = Time.realtimeSinceStartup + interval; }
- void Update ()
- {
- if (mIsPressed && Time.realtimeSinceStartup > mNextClick)
- {
- mNextClick = Time.realtimeSinceStartup + interval;
- // Do what you need to do, or simply:
- //SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
- //cleaner:
- EventDelegate.Execute(onPressListeners);
- }
- }
- }
에디터 스크립트(ngui -> editer폴더)
- using UnityEngine;
- using UnityEditor;
- [CanEditMultipleObjects]
- public class UIRepeatButtonEditor : UIWidgetContainerEditor
- {
- public override void OnInspectorGUI ()
- {
- serializedObject.Update();
- UIRepeatButton button = target as UIRepeatButton;
- //this allows to more conveniently set the event handler:
- NGUIEditorTools.DrawEvents("On Repeated Press", button, button.onPressListeners);
- }
- enum Highlight
- {
- DoNothing,
- Press,
- }
- }