yyl
20 小时以前 5d3366f2e0f687995eb7ad2107c4379fe7acd4e8
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.EventSystems;
using System;
 
 
public class ButtonEx : Button
{
 
    public event Action ableTimeChangeEvent;
 
    public float interval;
    public bool customPositiveSound = false;
    public bool customNegativeSound = false;
    public int positiveSound = 0;
    public int negativeSound = 0;
 
    float m_AbleTime = 0f;
    public float ableTime {
        get { return m_AbleTime; }
        private set {
            m_AbleTime = value;
            if (ableTimeChangeEvent != null)
            {
                ableTimeChangeEvent();
            }
        }
    }
 
    public override void OnPointerClick(PointerEventData eventData)
    {
        if (Time.realtimeSinceStartup < ableTime)
        {
            PlayNegativeSound();
            return;
        }
 
        base.OnPointerClick(eventData);
 
        PlayPositiveSound();
        ableTime = Time.realtimeSinceStartup + Mathf.Clamp(interval, 0, float.MaxValue);
    }
 
    protected override void Awake()
    {
        base.Awake();
    }
 
    private void PlayPositiveSound()
    {
        if (customPositiveSound)
        {
            SoundPlayer.Instance.PlayUIAudio(positiveSound);
        }
        else
        {
            SoundPlayer.Instance.PlayUIAudio(SoundPlayer.defaultClickPositiveAudio);
        }
    }
 
    private void PlayNegativeSound()
    {
        if (customNegativeSound)
        {
            SoundPlayer.Instance.PlayUIAudio(negativeSound);
        }
        else
        {
            SoundPlayer.Instance.PlayUIAudio(SoundPlayer.defaultClickNegativeAudio);
        }
    }
 
}