ShanxiKnowledgeBase/SXElectricalInspection/Assets/GuYuan/FractionManager/FractionManager.cs

103 lines
2.6 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
public class FractionManager : MonoBehaviour
{
public static FractionManager Instance;
[SerializeField] float Totalscore;
public bool isok = true;
public bool isYanDian = false;
public int sum = 0;//工器具分数
public bool isDianBi = true;
public List<Fraction> testPen = new List<Fraction>();
public void Awake()
{
if (Instance != null)
{
Destroy(Instance);
return;
}
Instance = this;
isDianBi = true;
DontDestroyOnLoad(Instance);
}
private void OnDestroy()
{
try
{
if (isYanDian)
{
//await overAsync(6, 10, "测量窃电点");
isok = false;
}
}
catch (System.Exception ex)
{
Debug.LogError(ex.Message);
throw;
}
}
/// <summary>
/// 分数上传
/// </summary>
/// <param name="id"></param>
/// <param name="score"></param>
/// <param name="tips"></param>
/// <returns></returns>
public async Task overAsync(int id, int score, string tips)
{
if (isok)
{
isok = false;
await load(id, score, tips);
}
}
async Task load(int id, int score, string tips)
{
ExaminationLoad examinationLoad = new ExaminationLoad();
ExaminationData data = new ExaminationData
{
tip = tips,
id_card = UIManager.Instance.loginController.PassWord,
real_name = UIManager.Instance.loginController.userName,
score = score,
step = id
};
await examinationLoad.LoadAsync(data);
isok = true;
}
public void SwitchTestPenStep(Fraction f, ref bool isOnce)
{
if (isDianBi)
{
if (f.orderName == "验电")
{
if (!testPen.Contains(f))
testPen.Add(f);
}
if (testPen.Count == 3)
{
if (testPen[0].stepName.Equals("插座One") && testPen[1].stepName.Equals("柜门") && testPen[2].stepName.Equals("插座Two"))
{
overAsync(4, 5, "验电");
Debug.Log("验电结束");
testPen[1].isOnce = false;
testPen[2].isOnce = false;
isOnce = false;
isDianBi = false;
testPen.Clear();
}
}
}
}
}