77 lines
1.8 KiB
Plaintext
77 lines
1.8 KiB
Plaintext
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
[System.Serializable]
|
|
public class OnExceedThreshEvent : UnityEvent<bool> { };
|
|
|
|
public class AccumeThreshSlider : AccumeSlider
|
|
{
|
|
[SerializeField]
|
|
private float m_threshold;
|
|
[SerializeField]
|
|
private bool m_bothWay;
|
|
[SerializeField]
|
|
private bool m_decrease;
|
|
|
|
public OnExceedThreshEvent m_onExceedThresh;
|
|
|
|
public void OnExceedThresh(bool positive)
|
|
{
|
|
|
|
}
|
|
|
|
public override void OnEndInteract(Touch touch)
|
|
{
|
|
base.OnEndInteract(touch);
|
|
|
|
if (m_decrease)
|
|
{
|
|
m_accumulation = 0.0f;
|
|
}
|
|
}
|
|
|
|
protected override void VirutalUpdate()
|
|
{
|
|
base.VirutalUpdate();
|
|
|
|
if (Interacting)
|
|
{
|
|
if (m_bothWay)
|
|
{
|
|
if (Mathf.Abs(m_accumulation) > m_threshold)
|
|
{
|
|
bool pos = m_accumulation > 0.0f;
|
|
OnExceedThresh(pos);
|
|
m_onExceedThresh.Invoke(pos);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m_threshold > 0.0f)
|
|
{
|
|
if (m_accumulation > m_threshold)
|
|
{
|
|
OnExceedThresh(true);
|
|
m_onExceedThresh.Invoke(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m_accumulation < m_threshold)
|
|
{
|
|
OnExceedThresh(false);
|
|
m_onExceedThresh.Invoke(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (m_decrease)
|
|
{
|
|
m_accumulation = Mathf.Lerp(m_accumulation, 0.0f, 0.8f);
|
|
}
|
|
}
|
|
}
|
|
}
|