public virtual void CloseLight() { if (lightStatus == LightStatusEnum.Close) { return; } lightStatus = LightStatusEnum.Close; if (light2D != null) { light2D.gameObject.SetActive(false); } }
/// <summary> /// A generic method to define the status of a four light row on the clock /// </summary> /// <param name="numberOfSwitchedOnLights">Number of lights switched on on the clock</param> /// <param name="switchedOnColor">Color of the lights in the row</param> /// <returns>An ordered list of chars, each one representing the status of a light in the row</returns> private List <char> GetFourLightsRowStatus(int numberOfSwitchedOnLights, LightStatusEnum switchedOnColor) { /* * Notes on design: * 1) Since the business logic to control the UI of the first, the second and the last row of the clock is the same, * a generic method has been created, where the only two variables are the number of lights to be switched on and the color * 2) Ternary conditional operator was used to keep code concise, since the resulting expression is still easy to read and understand. */ List <char> lightRow = new List <char>(); for (int i = 0; i < 4; i++) { LightStatusEnum lightStatus = numberOfSwitchedOnLights-- > 0 ? switchedOnColor : LightStatusEnum.Off; lightRow.Add(GetLightColorCode(lightStatus)); } return(lightRow); }
public virtual void OpenLight() { if (lightStatus == LightStatusEnum.Open) { return; } lightStatus = LightStatusEnum.Open; float targetIntensity = light2D.intensity; light2D.intensity = 0; if (light2D != null) { light2D.gameObject.SetActive(true); } float changeIntensity = 0; Tween tween = DOTween .To(() => changeIntensity, x => changeIntensity = x, targetIntensity, 10) .OnUpdate(() => { light2D.intensity = changeIntensity; }) .OnKill(() => { light2D.intensity = targetIntensity; }); }
/// <summary> /// Defines the status of the top light on the clock /// </summary> /// <returns>A char representing the status of the top light on the clock private char GetTopLightUiStatus() { LightStatusEnum lightStatus = currentDateTime.Second % 2 == 0 ? LightStatusEnum.Yellow : LightStatusEnum.Off; return(GetLightColorCode(lightStatus)); }
private char GetLightColorCode(LightStatusEnum lightStatus) { return((char)lightStatus); }
private void Awake() { lightStatus = LightStatusEnum.Close; }