Exemplo n.º 1
0
 public void Awake()
 {
     if (_container == null)
     {
         _container = GetComponent <RageCanvasAlign>();
     }
 }
Exemplo n.º 2
0
    /// <summary> Offsets the characters positions on X according to the alignment.
    /// Stores the rotation, sets it to default and restores it after the operation, to avoid distortions.
    /// </summary>
    private void ApplyAlignment()
    {
        try{
            if (_container == null)
            {
                _container = GetComponent <RageCanvasAlign>();
            }

            float offset;
            var   currentRotation = gameObject.transform.localRotation;
            switch (Alignment)
            {
            case AlignmentTypes.Left:
                gameObject.transform.localRotation = Quaternion.identity;
                offset = gameObject.collider.bounds.min.x - GetDisplayChar(0).collider.bounds.min.x;
                OffsetHorizontal(offset);
                gameObject.transform.localRotation = currentRotation;
                ContainerApplyAlignment(RageCanvasAlign.HorizontalAlignType.Left);
                break;

            case AlignmentTypes.Center:
                gameObject.transform.localRotation = Quaternion.identity;
                offset = gameObject.collider.bounds.center.x -
                         (GetDisplayChar(0).collider.bounds.min.x +
                          GetDisplayChar(Text.Length - 1).collider.bounds.max.x) / 2;
                OffsetHorizontal(offset);
                gameObject.transform.localRotation = currentRotation;
                ContainerApplyAlignment(RageCanvasAlign.HorizontalAlignType.Center);
                break;

            case AlignmentTypes.Right:
                offset = gameObject.collider.bounds.max.x - GetDisplayChar(DisplaySize - 1).collider.bounds.max.x;
                OffsetHorizontal(offset);
                gameObject.transform.localRotation = currentRotation;
                ContainerApplyAlignment(RageCanvasAlign.HorizontalAlignType.Right);
                break;
            }
        }catch (NullReferenceException) { /*ignore*/ }
    }