55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
[Serializable]
|
|
public class Step
|
|
{
|
|
public int id;
|
|
public string parentName;
|
|
public string stepName;
|
|
public string stepType;
|
|
public string maxScore;
|
|
public int score;
|
|
}
|
|
public class KaoHeManager : MonoBehaviour
|
|
{
|
|
public List<Step> results = new();
|
|
string parentName;
|
|
string stepName;
|
|
public string stepType;
|
|
public string maxScore;
|
|
public int totalScore;
|
|
List<string> recorder = new();
|
|
public void AddData(string parentName, string stepName, string stepType, string maxScore)
|
|
{
|
|
if (string.IsNullOrEmpty(maxScore)) return;
|
|
this.parentName = parentName;
|
|
this.stepName = stepName;
|
|
this.stepType = stepType;
|
|
this.maxScore = maxScore;
|
|
}
|
|
public void AddScore(int score,int id,Action<int,int> action)
|
|
{
|
|
Step step = results.Find(e => e.parentName == parentName && e.stepName == stepName && e.stepType == stepType);
|
|
if (recorder.Contains(parentName + stepName + id)) return;
|
|
if (step != null)
|
|
{
|
|
step.score += score;
|
|
}
|
|
else
|
|
{
|
|
step = new Step();
|
|
step.id = id;
|
|
step.parentName = parentName;
|
|
step.stepName = stepName;
|
|
step.stepType = stepType;
|
|
step.maxScore = maxScore;
|
|
step.score = score;
|
|
results.Add(step);
|
|
}
|
|
totalScore += score;
|
|
recorder.Add(parentName + stepName + id);
|
|
action?.Invoke(score,totalScore);
|
|
//Debug.Log(JsonConvert.SerializeObject(results));
|
|
}
|
|
} |