Files
JJBB/Assets/Project/Script/GUI/SkillBar/LiveSkillProgress.cs
2024-08-23 15:49:34 +08:00

192 lines
4.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Module.Log;
using UnityEngine;
using UnityEngine.UI;
using System.Text;
public class LiveSkillProgress : MonoBehaviour {
private static LiveSkillProgress _instance;
private static ProgressBarLoadingState state = ProgressBarLoadingState.NotLoad;
private static int _handleId;
private static float _duration;
private static float _startTime;
private static ProgressModel _playModel;
private static string _skillName;
private static bool _needDotAnim; // 是否需要显示 "......." 的动画
public UIBackRayBehind bgMask;
public float dotAnimInternal;
private float passedTime;
public int dotIndex = 0;
public int dotCount = 6;
public Slider progressSlider;
public GameObject _SkillNameGO;
public Text skillNameText;
public Text dotAnim;
public static void PlayProcess(ProgressModel playModel, float fContinTime, string skillName = default(string), int handleId = 0)
{
_startTime = Time.time;
_duration = fContinTime;
_handleId = handleId;
_playModel = playModel;
_skillName = skillName;
string str = GCGame.Table.StrDictionary.GetClientDictionaryString("#{4753}");
if (_skillName.IndexOf(str) != -1)
{
_needDotAnim = true;
}
else
{
_needDotAnim = false;
}
if (state == ProgressBarLoadingState.NotLoad)
{
state = ProgressBarLoadingState.Loading;
UIManager.ShowUI(UIInfo.LiveSkillProgress, ShowUiOver, null);
}
else if (state == ProgressBarLoadingState.Loaded)
PlayProgress();
}
private static void ShowUiOver(bool bSuccess, object param)
{
if (bSuccess)
{
state = ProgressBarLoadingState.Loaded;
PlayProgress();
}
else
LogModule.ErrorLog(string.Format("{0}加载结束,但预制物不存在!", UIInfo.SkillProgress));
}
private static void PlayProgress()
{
if (_instance == null)
LogModule.ErrorLog(string.Format("{0}已经加载但是_instance不存在", UIInfo.SkillProgress));
else
_instance.PlaySkillProgress();
}
public static void StopProcess(int handleId)
{
if (_handleId == handleId)
{
if (_instance != null)
{
_instance.progressSlider.value = 0f;
_instance.CloseWindow();
}
}
}
private void Awake()
{
_instance = this;
bgMask._BackClick.AddListener(Cancel);
}
private void Cancel()
{
GameManager.gameManager.StopAllCoroutines();
Singleton<ObjManager>.GetInstance().MainPlayer.OnSwithObjAnimState(Games.GlobeDefine.GameDefine_Globe.OBJ_ANIMSTATE.STATE_NORMOR);
CloseWindow();
}
private void OnDestroy()
{
state = ProgressBarLoadingState.NotLoad;
_instance = null;
}
public void PlaySkillProgress()
{
if (_needDotAnim == true)
{
dotAnim.gameObject.SetActive(true);
dotAnim.text = "";
}
else
{
dotAnim.gameObject.SetActive(false);
}
gameObject.SetActive(true);
if (string.IsNullOrEmpty(_skillName))
_SkillNameGO.SetActive(false);
else
{
skillNameText.text = _skillName;
_SkillNameGO.SetActive(true);
}
}
// Update is called once per frame
private void Update()
{
if (_startTime + _duration > Time.time)
{
var ratio = (Time.time - _startTime) / _duration;
if (_playModel == ProgressModel.REVERSEDMODE)
ratio = 1 - ratio;
progressSlider.value = ratio;
if (_needDotAnim == true)
{
passedTime += Time.deltaTime;
if (passedTime > dotAnimInternal)
{
if (dotIndex < 6)
{
if (dotIndex == 3)
{
dotAnim.text += " .";
}
else
{
dotAnim.text += ".";
}
++dotIndex;
}
else
{
dotIndex = 0;
dotAnim.text = "";
}
passedTime -= dotAnimInternal;
}
}
}
else
CloseWindow();
}
public void CloseWindow()
{
_handleId = 0;
gameObject.SetActive(false);
}
public enum ProgressModel
{
INVALD_TYPE = -1,
ORDERMODEL,
REVERSEDMODE
}
private enum ProgressBarLoadingState
{
NotLoad,
Loading,
Loaded,
}
}