Skip to content
Snippets Groups Projects
ProtocolHandler.cs 1.5 KiB
Newer Older
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class ProtocolHandler : MonoBehaviour
{
    public GameObject numCyclesInput;
    public GameObject blockControl;
    public float TotalRuntime { get; private set; }

    BlockHandler blockHandler;
    List<GameObject> blockStack = new List<GameObject>();
    int nCycles = 1;
    int currentBlockIndex = 0;
    int currentCycle = 0;

    float timeBetweenBlocks = 3f; // seconds, not implemented
    
    // Start is called before the first frame update
    void Start()
    {
        UpdateTotalRuntime();
    }

    // Update is called once per frame
    void Update()
    {

    }

    // Update runtime by adding each block runtime, adding 3s for each block,
    // and multiplying by cycles
    public void UpdateTotalRuntime()
    {
        blockHandler = blockControl.GetComponent<BlockHandler>();
        TotalRuntime = blockHandler.blockStackRuntime;
        TotalRuntime *= nCycles;
    }

    public void UpdateNumCycles()
    {
        TMP_InputField inputField = numCyclesInput.GetComponent<TMP_InputField>();
        nCycles = (int)Convert.ToInt32(inputField.text);
    }

    public void SetBlockStack()
    {
        blockStack = blockHandler.GetBlockStack();
        int i = 0;
        foreach (var block in blockStack)
        {
            BlockObjectClass boc = block.GetComponent<BlockObjectClass>();
            Debug.Log("boc " + i + " inhale: " + boc.InhalePeriod);
            i++;
        }
    }
}