File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed
Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change 55
66public class MultiTouchControlButton : Button {
77 private static bool _touchable = true ;
8-
8+
99 public bool multiTouchable = true ;
1010
11+ private Coroutine _touchableTimerCoroutine ;
12+
13+ private void OnDestroy ( ) {
14+ StopTouchableTimer ( ) ;
15+ }
16+
1117 public override void OnPointerClick ( PointerEventData eventData ) {
1218 if ( ! IsTouchable ( ) )
1319 return ;
14-
20+
1521 base . OnPointerClick ( eventData ) ;
1622 }
1723
1824 public override void OnSubmit ( BaseEventData eventData ) {
1925 if ( ! IsTouchable ( ) )
2026 return ;
21-
27+
2228 base . OnSubmit ( eventData ) ;
2329 }
2430
2531 private bool IsTouchable ( ) {
2632 if ( ! multiTouchable && ! _touchable )
2733 return false ;
2834
29- StartCoroutine ( StartTouchableTimer ( ) ) ;
35+ _touchableTimerCoroutine = StartCoroutine ( StartTouchableTimer ( ) ) ;
3036 return true ;
3137 }
3238
3339 private IEnumerator StartTouchableTimer ( ) {
3440 _touchable = false ;
35-
41+
3642 yield return new WaitForSeconds ( 0.1f ) ;
37-
43+
44+ StopTouchableTimer ( ) ;
45+ }
46+
47+ private void StopTouchableTimer ( ) {
48+ if ( _touchableTimerCoroutine == null )
49+ return ;
50+
51+ StopCoroutine ( _touchableTimerCoroutine ) ;
52+
3853 _touchable = true ;
54+ _touchableTimerCoroutine = null ;
3955 }
4056}
You can’t perform that action at this time.
0 commit comments