76 lines
1.7 KiB
C#
76 lines
1.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using Module.Log;
|
|
|
|
public class HitTipLogic : UIControllerBase<HitTipLogic> {
|
|
|
|
Image m_Image = null;
|
|
float m_time = 0.0f;
|
|
private Keyframe[] keyframs; // 动画曲线关键帧
|
|
private int length; // 动画曲线关键帧个数
|
|
public AnimationCurve m_AnimationCurve;
|
|
public AudioSource _AudioSource;
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
|
|
m_Image = GetComponent<Image>();
|
|
RectTransform transform = GetComponent<RectTransform>();
|
|
keyframs = m_AnimationCurve.keys; // 获取动画曲线关键帧
|
|
|
|
length = m_AnimationCurve.length; // 获取动画曲线关键帧个数
|
|
|
|
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
SetInstance(this);
|
|
RefreshVolumn();
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
SetInstance(null);
|
|
}
|
|
|
|
public void RefreshVolumn()
|
|
{
|
|
if (PlayerPreferenceData.SystemSoundEffect)
|
|
{
|
|
_AudioSource.volume = PlayerPreferenceData.SystemSoundVolum;
|
|
}
|
|
else
|
|
{
|
|
_AudioSource.volume = 0;
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
|
|
if (m_Image == null)
|
|
return;
|
|
if (keyframs.Length <= 0)
|
|
{
|
|
LogModule.WarningLog("Keyframs Length is 0");
|
|
return;
|
|
}
|
|
|
|
if (m_time < keyframs[length - 1].time)
|
|
{
|
|
m_time += Time.deltaTime;
|
|
float value = m_AnimationCurve.Evaluate(m_time);
|
|
m_Image.color = new Color(m_Image.color.r, m_Image.color.g, m_Image.color.b, value);
|
|
}
|
|
else
|
|
{
|
|
m_time = 0;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|