привет помоги с рефакторингом public class HandIndicator : MonoBehaviour, IDisposable {…
- User
привет помоги с рефакторингом public class HandIndicator : MonoBehaviour, IDisposable { [SerializeField] private Image leftHand; [SerializeField] private Image upHand; [SerializeField] private Image rightHand; [SerializeField] private float blinkDuration; [SerializeField] private int blinkCount;
private bool isBlink = false; private KeyInputCheck keyInputCheck; private bool isUpArrowKeyPressed; private bool isLeftArrowKeyPressed; private bool isRightArrowKeyPressed; public void Initialize(KeyInputCheck keyInputCheck) { this.keyInputCheck = keyInputCheck; keyInputCheck.OnUpdate += UpdateKey; keyInputCheck.OnLeftArrowKeyPressed += LeftArrowKeyPressed; keyInputCheck.OnUpArrowKeyPressed += UpArrowKeyPressed; keyInputCheck.OnRightArrowKeyPressed += RightArrowKeyPressed; } public void Dispose() { keyInputCheck.OnUpdate -= UpdateKey; keyInputCheck.OnLeftArrowKeyPressed -= LeftArrowKeyPressed; keyInputCheck.OnUpArrowKeyPressed -= UpArrowKeyPressed; keyInputCheck.OnRightArrowKeyPressed -= RightArrowKeyPressed; } private void UpdateKey() { if (isLeftArrowKeyPressed && !isBlink) { StartCoroutine(BlinkImage(leftHand)); } else if (isUpArrowKeyPressed && !isBlink) { StartCoroutine(BlinkImage(upHand)); } else if (isRightArrowKeyPressed && !isBlink) { StartCoroutine(BlinkImage(rightHand)); } } private IEnumerator BlinkImage(Image image) { isBlink = true; for (int count = 0; count < blinkCount; count++) { image.enabled = !image.enabled; yield return new WaitForSeconds(blinkDuration); } image.enabled = false; isBlink = false; } private void UpArrowKeyPressed(bool keyPressed) { isUpArrowKeyPressed = keyPressed; } private void LeftArrowKeyPressed(bool keyPressed) { isLeftArrowKeyPressed = keyPressed; } private void RightArrowKeyPressed(bool keyPressed) { isRightArrowKeyPressed = keyPressed; } } - Assistant
- User
Я бы хотел избежать использование этих переменных private bool isUpArrowKeyPressed; private bool isLeftArrowKeyPressed; private bool isRightArrowKeyPressed;
- Assistant
- User
давай другой вариант
- Assistant