Newer
Older
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System.Collections;
using System.Collections.Generic;
using System;
using System.Linq;
using UnityEngine;
using TMPro;
public class BlockHandler : MonoBehaviour
{
public GameObject nblock_input;
public GameObject block_object;
public AnimateCircle animateCircle;
public int max_num_blocks { get; private set; }
TMP_Dropdown dropdown;
List<GameObject> block_objects = new List<GameObject>();
GameObject running_block;
int current_block_index = 0;
private Vector3 block_home_position = new Vector3(-104f, -345f, 0f);
// Start is called before the first frame update
void Start()
{
dropdown = this.GetComponent<TMP_Dropdown>();
GameObject first_block = GetBlockObjectPrefab();
block_objects.Add(first_block);
block_objects[0].SetActive(true);
running_block = block_objects[0];
UpdateOptions();
SetRunningBlockIndex();
UpdateRunningBlock();
}
// Update is called once per frame
void Update()
{
}
public void UpdateOptions()
{
UpdateMaxNumBlocks();
dropdown.ClearOptions();
for (int i = 1; i < max_num_blocks + 1; i++)
{
dropdown.AddOptions(new List<string> { i.ToString() });
}
}
public void UpdateMaxNumBlocks()
{
TMP_InputField input_field;
input_field = nblock_input.GetComponent<TMP_InputField>();
max_num_blocks = Int32.Parse(input_field.text);
}
public void SetRunningBlockIndex()
{
current_block_index = dropdown.value;
Debug.Log("current block index: " + current_block_index);
}
public void UpdateBlockObjects()
{
bool is_empty = !block_objects.Any();
int num_block_objects = 0;
if (!is_empty)
{
num_block_objects = block_objects.Count;
}
if (max_num_blocks > num_block_objects)
{
for (int i = num_block_objects; i < max_num_blocks; i++)
{
block_objects.Add(GetBlockObjectPrefab());
block_objects[i].SetActive(false);
}
}
else if (max_num_blocks < num_block_objects)
{
for (int i = num_block_objects; i > max_num_blocks; i--)
{
block_objects.RemoveAt(i);
}
}
current_block_index = 0;
SetRunningBlock();
UpdateRunningBlock();
}
public void SetRunningBlock()
{
running_block.SetActive(false);
running_block = block_objects[current_block_index];
running_block.SetActive(true);
}
public void UpdateRunningBlock()
{
animateCircle.block_obj = running_block;
}
GameObject GetBlockObjectPrefab()
{
GameObject block = Instantiate(
block_object,
new Vector3(0f, 0f, 0f),
Quaternion.identity
);
block.transform.parent = this.transform;
block.transform.localPosition = block_home_position;
block.transform.localScale = new Vector3(1f, 1f, 0f);
return block;
}
}