示例#1
0
    public void adjustTransform()
    {
        sr.transform.position  = camera.transform.position;
        sr.transform.position += Vector3.forward; // could rendered by camera
        var     b           = sr.bounds;
        Vector2 size        = VectorUtils.V32(b.size);
        Vector2 camHalfSize = new Vector2(camera.orthographicSize * camera.aspect, camera.orthographicSize);
        Vector2 camSize     = camHalfSize * 2;
        Vector2 deltaScale  = VectorUtils.Division(camSize, size);

        if (componentScaled != Vector2.one)
        {
            if (componentScaled == Vector2.zero)
            {
                deltaScale = Vector2.zero;
            }
            else
            {
                deltaScale = componentScaled.x == 0 ? Vector2.one * deltaScale.y : Vector2.one * deltaScale.x;
            }
        }
        Vector3 scale = sr.transform.localScale;

        scale = VectorUtils.Multiply(scale, VectorUtils.V23(deltaScale, 1));
        sr.transform.localScale = scale;
    }