private PulseStatus ConvertToPulseStatus(double pulse, bool critical) { PulseStatus status = PulseStatus.Invalid; if (pulse >= 40 && pulse <= 100) { status = PulseStatus.Normal; } else if (pulse > 120 && pulse <= 140) { status = PulseStatus.High; } else if (pulse > 140) { status = critical ? PulseStatus.CriticallyHigh : PulseStatus.VeryHigh; } else if (pulse < 40 && pulse > 20) { status = PulseStatus.Low; } else { status = critical ? PulseStatus.CriticallyLow : PulseStatus.VeryLow; } return(status); }
public void pulse() { if(currentStatus != PulseStatus.active && cooldown == 0) { currentStatus = PulseStatus.grow; } }
void Start() { //init as idle and set the base scale currentStatus = PulseStatus.idle; initialScale = transform.localScale; cooldown = 0; }
public void deactivate() { currentStatus = PulseStatus.idle; //hide the cube when idle renderer.enabled = false; renderer.material.color = Color.white; transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); }
void Update() { if(cooldown > 0) { cooldown--; } if(currentStatus == PulseStatus.grow) { //unhide the cube renderer.enabled = true; //scale the cube up transform.localScale = new Vector3(transform.localScale.x + pulseIncrement, transform.localScale.y + pulseIncrement, transform.localScale.z + pulseIncrement); //if the current scale is partway to the maximum scale, start scaling its neighbours //only pulse neighbours that are idle! if(transform.localScale.x > ((pulseScale - initialScale.x) / 1.25f)) { if(topNeighbour && topNeighbour.currentStatus == PulseStatus.idle) { topNeighbour.pulse(); } if(bottomNeighbour && bottomNeighbour.currentStatus == PulseStatus.idle) { bottomNeighbour.pulse(); } if(leftNeighbour && leftNeighbour.currentStatus == PulseStatus.idle) { leftNeighbour.pulse(); } if(rightNeighbour && rightNeighbour.currentStatus == PulseStatus.idle) { rightNeighbour.pulse(); } } //once you hit the max scale, set the GridCube to shrink if(transform.localScale.x > pulseScale) { currentStatus = PulseStatus.shrink; } } else if(currentStatus == PulseStatus.shrink) { //shrink if the GridCube is still bigger than it started, otherwise set it to idle if(transform.localScale.x > initialScale.x) { transform.localScale = new Vector3(transform.localScale.x - pulseIncrement, transform.localScale.y - pulseIncrement, transform.localScale.z - pulseIncrement); } else { cooldown = 60; currentStatus = PulseStatus.idle; } } else if(currentStatus == PulseStatus.idle) { //hide the cube when idle renderer.enabled = false; transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); } else if(currentStatus == PulseStatus.active) { //set colour to red and grow the cube to the active size renderer.enabled = true; renderer.material.color = Color.red; if(transform.localScale.x < (pulseScale / 1.1f)) { //scale the cube up transform.localScale = new Vector3(transform.localScale.x + pulseIncrement, transform.localScale.y + pulseIncrement, transform.localScale.z + pulseIncrement); } } }
public void activate() { currentStatus = PulseStatus.active; }