Ejemplo n.º 1
0
 public void Init(Transform parent, Transform position)
 {
     collider.enabled        = true;
     rigidbody.simulated     = true;
     transform.localRotation = Quaternion.Euler(0, 0, 0);
     transform.SetParent(parent);
     transform.localPosition = position.localPosition;
     gameObject.SetActive(true);
     _pieceState = PieceStates.Waiting;
 }
Ejemplo n.º 2
0
    public void Move()
    {
        if (!_pieceState.Equals(PieceStates.Active))
        {
            return;
        }

        _moveCoroutine = StartCoroutine(IterateMove());
        _pieceState    = PieceStates.Moving;
    }
Ejemplo n.º 3
0
    private IEnumerator IterateSnap(Vector2 position, float rotation)
    {
        _pieceState = PieceStates.Snapping;
        Quaternion targetQua = Quaternion.Euler(0, 0, rotation);

        while (Vector2.Distance(transform.localPosition, position) > 0.1f)
        {
            transform.localPosition = Vector2.Lerp(transform.localPosition, position, 10f * Time.deltaTime);
            transform.localRotation = Quaternion.Lerp(transform.localRotation, targetQua, 10f * Time.deltaTime);
            yield return(new WaitForEndOfFrame());
        }

        transform.localPosition = position;
        transform.localRotation = targetQua;
        yield return(new WaitForEndOfFrame());

        OnSnapCompleted();
    }
Ejemplo n.º 4
0
 private void OnSnapCompleted()
 {
     // after snap..
     _pieceState = PieceStates.Locked;
 }
Ejemplo n.º 5
0
 public void SetPieceStateActive()
 {
     _pieceState = PieceStates.Active;
 }