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

public class ProtocolHandler : MonoBehaviour
{
rchia16's avatar
rchia16 committed
    public static ProtocolHandler Instance;
    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;

rchia16's avatar
rchia16 committed
    static float timeBetweenBlocks = 3f; // seconds, not implemented

    private void Awake()
    {
        if (Instance != null)
        {
            Destroy(gameObject);
            return;
        }
        Instance = this;
        DontDestroyOnLoad(gameObject);
    }

    // Start is called before the first frame update
    void Start()
    {
rchia16's avatar
rchia16 committed
        
    }

    // 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++;
        }
    }
rchia16's avatar
rchia16 committed

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

public class ProtocolVariables
{
    List<BlockObjectClass>