You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Operation {
public int idx, val, op;
}
public class Initalize : MonoBehaviour
{
public GameObject AllBoxes;
public GameObject[] Boxes;
public NewTextModify[] Label;
public DoorAnimation[] Door;
public int IndexChange = -1, ActionChange = -1;
public bool ActionExisted = false, ActionMoving = false;
Queue<Operation> AllOperation = new Queue<Operation>();
// Start is called before the first frame update
void Start()
{
for(int i = 0; i < 100; ++i) {
Boxes[i] = AllBoxes.gameObject.transform.GetChild(i).gameObject;
Label[i] = Boxes[i].GetComponent<NewTextModify>();
Door[i] = Boxes[i].gameObject.transform.GetChild(0).GetChild(0).GetComponent<DoorAnimation>();
Label[i].Init(i);
}
}
public Operation Cope(int idx, int val, int op) {
var Op = new Operation();
Op.idx = idx; Op.val = val; Op.op = op;
return Op;
}
void UpdateValue(int idx, int value) {
AllOperation.Enqueue(Cope(idx, 0, 1));
AllOperation.Enqueue(Cope(idx, value, 0));
AllOperation.Enqueue(Cope(idx, 0, 2));
}
// Update is called once per frame
void Update()
{
if(ActionExisted) {
if(!Door[IndexChange].DoorIsMoving) {
if(ActionChange == 1) Door[IndexChange].OpenDoor();
else Door[IndexChange].CloseDoor();
}
if(Door[IndexChange].TimeRotation == 900) {
ActionExisted = false;
IndexChange = -1;
ActionChange = -1;
}
}
else {
if(AllOperation.Count == 0) return;
var Current = AllOperation.Peek(); AllOperation.Dequeue();
if(Current.op == 0) {
Label[Current.idx].ChangeValue(Current.val);
}
else {
ActionExisted = true;
IndexChange = Current.idx;
ActionChange = Current.op;
}
}
}
}