111 lines
2.3 KiB
C#
111 lines
2.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CanvasThrowingBar : MonoBehaviour
|
|
{
|
|
public Image bar;
|
|
|
|
public Image targetBar;
|
|
|
|
public Image glowImage;
|
|
|
|
public float barValue;
|
|
|
|
public float barMinValue;
|
|
|
|
public bool isStop;
|
|
|
|
private float timer;
|
|
|
|
private float dstFactor = 1f;
|
|
|
|
private float contentBarWidth;
|
|
|
|
private float targetBarWidth;
|
|
|
|
public bool isTargetValid = true;
|
|
|
|
private RectTransform targetBarRect;
|
|
|
|
public Color throwValidBarColor = Color.white;
|
|
|
|
public Color throwInvalidBarColor = Color.gray;
|
|
|
|
private void Start()
|
|
{
|
|
dstFactor = 1f;
|
|
timer = 0f;
|
|
barValue = 0f;
|
|
targetBarRect = targetBar.GetComponent<RectTransform>();
|
|
contentBarWidth = GetComponent<RectTransform>().rect.width;
|
|
targetBarWidth = targetBarRect.rect.width;
|
|
targetBar.gameObject.SetActive(value: false);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
bar.fillAmount = barValue;
|
|
if (barValue < barMinValue)
|
|
{
|
|
bar.color = throwInvalidBarColor;
|
|
}
|
|
else
|
|
{
|
|
bar.color = throwValidBarColor;
|
|
}
|
|
}
|
|
|
|
public float SetTargetBar(float value, float max_value)
|
|
{
|
|
if (value == 0f)
|
|
{
|
|
targetBar.gameObject.SetActive(value: false);
|
|
return 0f;
|
|
}
|
|
targetBar.gameObject.SetActive(value: true);
|
|
glowImage.gameObject.SetActive(value: false);
|
|
if (!targetBarRect)
|
|
{
|
|
targetBarRect = targetBar.GetComponent<RectTransform>();
|
|
}
|
|
dstFactor = 0.5f + value;
|
|
targetBarRect.sizeDelta = new Vector2(250f * (1f - value + 0.1f), targetBarRect.rect.height);
|
|
targetBarWidth = targetBarRect.sizeDelta.x;
|
|
float num = contentBarWidth * value;
|
|
targetBarRect.anchoredPosition = new Vector2(num, 0f);
|
|
float num2 = num + targetBarRect.rect.width;
|
|
float num3 = contentBarWidth * barValue;
|
|
if (num3 >= num - targetBarWidth / 2f && num3 < num2 - targetBarWidth / 2f)
|
|
{
|
|
isTargetValid = true;
|
|
targetBar.color = Color.green;
|
|
}
|
|
else
|
|
{
|
|
isTargetValid = false;
|
|
targetBar.color = Color.white;
|
|
if (num3 < num - targetBarWidth / 2f)
|
|
{
|
|
return num3 - (num - targetBarWidth / 2f);
|
|
}
|
|
if (num3 > num2 - targetBarWidth / 2f)
|
|
{
|
|
return num3 - (num2 - targetBarWidth / 2f);
|
|
}
|
|
}
|
|
return 0f;
|
|
}
|
|
|
|
public float Stop()
|
|
{
|
|
isStop = true;
|
|
ScriptsHandler.Instance.m_PlayerMain.currentRod.isTargetValid = isTargetValid;
|
|
return barValue;
|
|
}
|
|
|
|
private void DestroyBar()
|
|
{
|
|
Object.Destroy(base.gameObject);
|
|
}
|
|
}
|