/
crypt
/
NumbersPlay
Обзор
Документация
Войти
/
crypt
/
NumbersPlay
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Assets/Code/Blocks/Block.cs
85 строк
2 KB
Crypt
start
16 ноя 2025, 14:28
16 ноя 2025, 14:28
1482007
Код
Авторство
О чём код?
using System; using UnityEngine; using UnityEngine.EventSystems; using DG.Tweening; namespace Code.Blocks { public class Block : MonoBehaviour, IPointerClickHandler { public int Number; public int x, y; private BlockView _blockView; private PlayingField _playingField; private readonly Vector2 _normalSize = Vector2.one; private readonly Vector2 _selectedSize = new Vector2(0.75f, 0.75f); private Vector3 targetPosition; private float _speedMove; private bool _selected; public event Action<Block> Selected; public event Action<Block> Deselected; private void Awake() => _blockView = GetComponent<BlockView>(); private void Start() { DOTween.Init(); } public void Initialize(PlayingField playingField, Transform parent, Vector3 position, int coordX, int coordY) { _playingField = playingField; transform.SetParent(parent); transform.position = position; targetPosition = transform.localPosition; x = coordX; y = coordY; Number = UnityEngine.Random.Range(1, 5); _blockView.SetSprite(_playingField.GetSpriteById(Number)); _blockView.SetNumber(Number); _speedMove = 1f; transform.localScale = _normalSize; gameObject.SetActive(true); _selected = false; } public void ResetBlock() { _selected = false; transform.localScale = _normalSize; } private void Select() { _selected = true; transform.localScale = _selectedSize; Selected?.Invoke(this); } private void Deselect() { _selected = false; transform.localScale = _normalSize; Deselected?.Invoke(this); } public void Move() { targetPosition += Vector3.down; y--; transform.DOMove(targetPosition, _speedMove); } public void OnPointerClick(PointerEventData eventData) { if (_selected) Deselect(); else Select(); } } }