Ejemplo n.º 1
0
    private void CreateWallCorner(Facing.Direction a_direction)
    {
        var x      = GetWallCenter(Facing.GetHorizontal(a_direction)).x;
        var y      = GetWallCenter(Facing.GetVertical(a_direction)).y;
        var corner = Instantiate(WallRendererCornerPrefab);

        corner.transform.position = new Vector2(x, y);

        switch (a_direction)
        {
        case Facing.Direction.Northwest: corner.transform.Rotate(Vector3.forward, 90.0f); break;

        case Facing.Direction.Southeast: corner.transform.Rotate(Vector3.forward, -90.0f); break;

        case Facing.Direction.Southwest: corner.transform.Rotate(Vector3.forward, 180.0f); break;
        }

        var sr = corner.GetComponent <SpriteRenderer>();

        if (sr.drawMode == SpriteDrawMode.Simple)
        {
            sr.drawMode = SpriteDrawMode.Tiled;
        }
        sr.size = Vector2.one * WallSize;

        corner.name             = a_direction + " Wall Corner";
        corner.transform.parent = m_wallContainer.transform;

        var wall = corner.gameObject.AddComponent <Wall>();

        wall.Direction = a_direction;
    }
Ejemplo n.º 2
0
    private IEnumerator OnIndexChanged()
    {
        yield return(new WaitForEndOfFrame());

        var halfTargetSize = Vector2.zero;
        var spriteRenderer = CurOption.GetComponent <SpriteRenderer>();

        if (spriteRenderer != null)
        {
            halfTargetSize = spriteRenderer.GetActualSize() / 2.0f;
        }
        else
        {
            var textMeshPro = CurOption.GetComponent <TextMeshPro>();
            if (textMeshPro != null)
            {
                halfTargetSize = new Vector2(textMeshPro.renderedWidth / 2.0f, textMeshPro.renderedHeight / 2.0f);
            }
        }

        var horizontal = Facing.GetHorizontal(m_placementDirection);
        var vertical   = Facing.GetVertical(m_placementDirection);

        var pos = CurOption.transform.position;

        var offset = halfTargetSize + m_halfCursorSize;

        if (horizontal == Facing.Direction.East)
        {
            pos.x += offset.x;
        }
        if (horizontal == Facing.Direction.West)
        {
            pos.x -= offset.x;
        }

        if (vertical == Facing.Direction.North)
        {
            pos.y += offset.y;
        }
        if (vertical == Facing.Direction.South)
        {
            pos.y -= offset.y;
        }

        transform.position = pos;

        m_onChanged.Invoke(CurOption.gameObject);
    }
    private void UpdateAnimation()
    {
        m_prevFacing = m_facing.CurDirection;

        var directionString = m_facing.CurDirection.ToString();

        // if we're sticking to cardinal and not N or S, use horizontal component
        if (!m_useIntercardinal && !Facing.IsVertical(m_facing.CurDirection))
        {
            directionString = Facing.GetHorizontal(m_facing.CurDirection).ToString();
        }

        m_animator.SetAnimation(directionString);
        m_animator.IsPaused = !m_mover.IsMoving;
    }
Ejemplo n.º 4
0
    private void Update()
    {
        if (m_frontBar == null)
        {
            return;
        }

        if (m_stretchMode == SizeMode.Stretch)
        {
            m_frontBar.transform.localScale = PercentVec;
        }
        else
        {
            //m_frontBar.size = m_anchor == Facing.Direction.East ? -PercentVec : PercentVec;
            m_frontBar.size = PercentVec;
            if (Facing.GetHorizontal(m_anchor) == Facing.Direction.East)
            {
                m_frontBar.flipX = true;
            }
            if (Facing.GetVertical(m_anchor) == Facing.Direction.North)
            {
                m_frontBar.flipY = true;
            }
        }

        switch (m_anchor)
        {
        case Facing.Direction.East: AnchorEast(); break;

        case Facing.Direction.North: AnchorNorth(); break;

        case Facing.Direction.Northeast: AnchorEast(); AnchorNorth(); break;

        case Facing.Direction.Northwest: AnchorNorth(); AnchorWest(); break;

        case Facing.Direction.South: AnchorSouth(); break;

        case Facing.Direction.Southeast: AnchorSouth(); AnchorEast(); break;

        case Facing.Direction.Southwest: AnchorSouth(); AnchorEast(); break;

        case Facing.Direction.West: AnchorWest(); break;
        }
    }