140 lines
2.9 KiB
C#
140 lines
2.9 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Games.Item;
|
|||
|
using System;
|
|||
|
using UnityEngine.Events;
|
|||
|
using GCGame.Table;
|
|||
|
|
|||
|
// 装备自动强化控制
|
|||
|
// 新增中途挂起机制
|
|||
|
public class EquipAutoOpt : MonoBehaviour
|
|||
|
{
|
|||
|
private static int[] AUTO_SPEED = new int[] { 1, 2, 4 };
|
|||
|
|
|||
|
public GameObject _StartBtn;
|
|||
|
public GameObject _StopBtn;
|
|||
|
public Text _SpeedLabel;
|
|||
|
|
|||
|
private int _SpeedIdx;
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class AutoCallBack : UnityEvent
|
|||
|
{
|
|||
|
public AutoCallBack() { }
|
|||
|
}
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
public AutoCallBack _AutoCallBack;
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
public AutoCallBack _AutoStart;
|
|||
|
|
|||
|
void OnDisable()
|
|||
|
{
|
|||
|
StopAuto();
|
|||
|
}
|
|||
|
|
|||
|
public void OnSpeedChange()
|
|||
|
{
|
|||
|
++_SpeedIdx;
|
|||
|
if (_SpeedIdx == AUTO_SPEED.Length)
|
|||
|
{
|
|||
|
_SpeedIdx = 0;
|
|||
|
}
|
|||
|
|
|||
|
_SpeedLabel.text = StrDictionary.GetClientDictionaryString("#{5303}", AUTO_SPEED[_SpeedIdx]);
|
|||
|
|
|||
|
if (!_StartBtn.activeSelf)
|
|||
|
{
|
|||
|
StopAuto();
|
|||
|
StartAuto();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void StartAuto()
|
|||
|
{
|
|||
|
_StartBtn.SetActive(false);
|
|||
|
_StopBtn.SetActive(true);
|
|||
|
|
|||
|
// 重置等待相关设置
|
|||
|
waiting = false;
|
|||
|
recovery = false;
|
|||
|
StopAllCoroutines();
|
|||
|
|
|||
|
float autoTime = 1.0f / AUTO_SPEED[_SpeedIdx];
|
|||
|
if (_AutoStart != null)
|
|||
|
{
|
|||
|
_AutoStart.Invoke();
|
|||
|
}
|
|||
|
InvokeRepeating("CallBackInner", 0, autoTime);
|
|||
|
}
|
|||
|
|
|||
|
public void StopAuto()
|
|||
|
{
|
|||
|
_StartBtn.SetActive(true);
|
|||
|
_StopBtn.SetActive(false);
|
|||
|
CancelInvoke();
|
|||
|
|
|||
|
// 重置等待相关设置
|
|||
|
waiting = false;
|
|||
|
recovery = false;
|
|||
|
StopAllCoroutines();
|
|||
|
}
|
|||
|
|
|||
|
private void CallBackInner()
|
|||
|
{
|
|||
|
// 当处于等待状态时,不执行回调
|
|||
|
if(waiting == true)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_AutoCallBack.Invoke();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 等待状态
|
|||
|
public void TryStop(float time)
|
|||
|
{
|
|||
|
// 防止重复进入等待状态
|
|||
|
if (waiting == false)
|
|||
|
{
|
|||
|
waiting = true;
|
|||
|
StartCoroutine("Wait", 2.0f);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private bool waiting = false; // 是否处于等待状态
|
|||
|
private bool recovery = false; // 是否被恢复
|
|||
|
|
|||
|
// 开始等待状态
|
|||
|
private IEnumerator Wait(float waiteTime)
|
|||
|
{
|
|||
|
for (float i = 0.0f; i < waiteTime; i += Time.deltaTime)
|
|||
|
{
|
|||
|
if (recovery == true)
|
|||
|
{
|
|||
|
waiting = false;
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
yield return 0;
|
|||
|
}
|
|||
|
|
|||
|
// 超过等待时间,强制停止
|
|||
|
StopAuto();
|
|||
|
}
|
|||
|
|
|||
|
// 尝试恢复运行
|
|||
|
public void Restart()
|
|||
|
{
|
|||
|
if(waiting == true)
|
|||
|
{
|
|||
|
recovery = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|