-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoneSelectPanel.cs
More file actions
73 lines (66 loc) · 2.39 KB
/
StoneSelectPanel.cs
File metadata and controls
73 lines (66 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using UnityEngine;
using System;
using UnityEngine.UI;
using TMPro;
using System.Collections.Generic;
public class StoneSelectPanel : MonoBehaviour
{
[SerializeField] public Toggle[] ToggleComponents;
public Dictionary<StoneType, TextMeshProUGUI> Label { get; set; } = new Dictionary<StoneType, TextMeshProUGUI>();
public Dictionary<StoneType, TextMeshProUGUI> Count { get; set; } = new Dictionary<StoneType, TextMeshProUGUI>();
public AvailableStoneCount AvailableStoneCount { get; private set; } = new AvailableStoneCount();
private void Awake()
{
foreach (StoneType stoneType in Enum.GetValues(typeof(StoneType)))
{
// LabelとCountのテキストを取得
TextMeshProUGUI[] targetTexts = ToggleComponents[(int)stoneType].GetComponentsInChildren<TextMeshProUGUI>();
foreach (TextMeshProUGUI targetText in targetTexts)
{
if (targetText.name.Equals("Label"))
{
Label[stoneType] = targetText;
Label[stoneType].text = stoneType.ToString();
}
else if (targetText.name == "Count")
{
Count[stoneType] = targetText;
}
else
{
Debug.LogWarning($"正しくないテキスト名が含まれています: {targetText.name}");
}
}
}
AvailableStoneCount.Count.OnValueChanged += (selectStoneType, availableCount) =>
{
UpdateCount(selectStoneType, availableCount);
};
foreach (StoneType stoneType in Enum.GetValues(typeof(StoneType)))
{
if (AvailableStoneCount.Count.ContainsKey(stoneType))
{
UpdateCount(stoneType, AvailableStoneCount.Count[stoneType]);
}
else
{
Debug.LogWarning($"StoneType {stoneType} is not present in AvailableStoneCount.Count");
}
}
}
private void Start()
{
}
public void UpdateCount(StoneType selectStoneType, int availableCount)
{
Debug.Log("UpdateCount");
if (Count.ContainsKey(selectStoneType))
{
Count[selectStoneType].text = availableCount.ToString();
}
else
{
Debug.LogWarning($"Count dictionary does not contain key: {selectStoneType}");
}
}
}