146 lines
3.9 KiB
C#
146 lines
3.9 KiB
C#
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace EventPartnerGather.Mining
|
|
{
|
|
// 记录一下OreData
|
|
public class OreController : MonoBehaviour
|
|
{
|
|
//
|
|
public int maxScore;
|
|
//
|
|
// public int Score = 0;
|
|
//
|
|
public int maxTimes = 3;
|
|
|
|
public int validTimes = 3;
|
|
|
|
public int miningTimes; // 挖掘了几斧头
|
|
|
|
//
|
|
private Transform basicGather1;
|
|
|
|
private Transform rock1, break01;
|
|
|
|
private Transform rock2, break02;
|
|
|
|
private Transform rock3, break03;
|
|
|
|
|
|
public bool InQueue { get; set; } = false;
|
|
private void Awake()
|
|
{
|
|
|
|
basicGather1 = transform.Find("fx_basic_gather1");
|
|
rock1 = transform.Find("rock1");
|
|
rock2 = transform.Find("rock2");
|
|
rock3 = transform.Find("rock3");
|
|
|
|
break01 = transform.Find("fx_break01");
|
|
break02 = transform.Find("fx_break02");
|
|
break03 = transform.Find("fx_break03");
|
|
}
|
|
|
|
|
|
public void ResetValues()
|
|
{
|
|
// Score = 0;
|
|
//
|
|
maxTimes = 3;
|
|
|
|
validTimes = 3;
|
|
|
|
miningTimes = 0; // 挖掘了几斧头
|
|
|
|
InQueue = false;
|
|
}
|
|
|
|
public void OnMining(int progress)
|
|
{
|
|
Log($"OnMining -> {progress}");
|
|
if (InQueue)
|
|
{
|
|
if (progress <= miningTimes)
|
|
{
|
|
PlayMining(miningTimes);
|
|
return;
|
|
}
|
|
miningTimes = progress;
|
|
}
|
|
else
|
|
{
|
|
miningTimes += 1;
|
|
}
|
|
|
|
PlayMining(miningTimes);
|
|
}
|
|
|
|
public void UpdateMiningTimes(int times )
|
|
{
|
|
Log($"UpdateMiningTimes -> {times}");
|
|
miningTimes = times;
|
|
foreach (var child in transform.Cast<Transform>())
|
|
{
|
|
child.gameObject.SetActive(false);
|
|
}
|
|
switch (miningTimes)
|
|
{
|
|
case 1:
|
|
// break01.gameObject.SetActive(true);
|
|
rock2.gameObject.SetActive(true);
|
|
break;
|
|
case 2:
|
|
// break02.gameObject.SetActive(true);
|
|
rock3.gameObject.SetActive(true);
|
|
break;
|
|
case 3:
|
|
default:
|
|
break03.gameObject.SetActive(true);
|
|
break;
|
|
}
|
|
}
|
|
//
|
|
public async void PlayMining(int time)
|
|
{
|
|
Log($"PlayMining -> {time} {validTimes}, {maxTimes}");
|
|
if (time > validTimes)
|
|
{
|
|
time = validTimes;
|
|
miningTimes = validTimes;
|
|
}
|
|
|
|
foreach (var child in transform.Cast<Transform>())
|
|
{
|
|
child.gameObject.SetActive(false);
|
|
}
|
|
basicGather1.gameObject.SetActive(true);
|
|
await Awaiters.NextFrame;
|
|
|
|
switch (time)
|
|
{
|
|
case 1:
|
|
break01.gameObject.SetActive(true);
|
|
rock2.gameObject.SetActive(true);
|
|
break;
|
|
case 2:
|
|
break02.gameObject.SetActive(true);
|
|
rock3.gameObject.SetActive(true);
|
|
break;
|
|
default:
|
|
break03.gameObject.SetActive(true);
|
|
await Awaiters.Seconds(2f);
|
|
break;
|
|
}
|
|
|
|
if (time >= maxTimes)
|
|
{
|
|
gameObject?.SetActive(false);
|
|
}
|
|
}
|
|
// 是否在队列中
|
|
private void Log(object t)
|
|
{
|
|
// Debug.Log($"<Color=cyan> OreController {gameObject.name} {t} </color>");
|
|
}
|
|
}
|
|
} |