备份CatanBuilding瘦身独立工程
This commit is contained in:
75
Assets/Scripts/UI/Washing/EventWashingBatterylevel.cs
Normal file
75
Assets/Scripts/UI/Washing/EventWashingBatterylevel.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class EventWashingBatteryLevel : MonoBehaviour
|
||||
{
|
||||
public TMP_Text txt_battery_num;
|
||||
public GameObject[] m_Lowbatterys;
|
||||
public GameObject[] m_Lights;
|
||||
|
||||
public void UpdateToken(int token)
|
||||
{
|
||||
txt_battery_num.text = "x" + token;
|
||||
}
|
||||
public void SetPercentage(float percentage)
|
||||
{
|
||||
int count = m_Lights.Length;
|
||||
float step = 1f / count;
|
||||
int belongStep = (percentage > 0) ? (int)math.floor(percentage / step) + 1 : 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var item = m_Lights[i];
|
||||
if (i < belongStep)
|
||||
{
|
||||
if (item.activeSelf == false)
|
||||
{
|
||||
item.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.activeSelf == true)
|
||||
{
|
||||
item.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SetEnergyShortage()
|
||||
{
|
||||
int count = m_Lowbatterys.Length;
|
||||
for (int i = 0;i < count; i++)
|
||||
{
|
||||
if (m_Lowbatterys[i].activeSelf == false)
|
||||
{
|
||||
m_Lowbatterys[i].SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (txt_battery_num.gameObject.activeSelf == true)
|
||||
{
|
||||
txt_battery_num.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
public void SetEnergyEnough()
|
||||
{
|
||||
int count = m_Lowbatterys.Length;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (m_Lowbatterys[i].activeSelf == true)
|
||||
{
|
||||
m_Lowbatterys[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (txt_battery_num.gameObject.activeSelf == false)
|
||||
{
|
||||
txt_battery_num.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user