Exemplo n.º 1
0
    public void MakePixelPerfect()
    {
        float s = 1.0f;
        tk2dPixelPerfectHelper pph = tk2dPixelPerfectHelper.inst;

        if (pph)
        {
            if (pph.CameraIsOrtho)
            {
                s = pph.scaleK;
            }
            else
            {
                s = pph.scaleK + pph.scaleD * transform.position.z;
            }
        }
        else if (Camera.main)
        {
            if (Camera.main.isOrthoGraphic)
            {
                s = Camera.main.orthographicSize;
            }
            else
            {
                float zdist = (transform.position.z - Camera.main.transform.position.z);
                s = tk2dPixelPerfectHelper.CalculateScaleForPerspectiveCamera(Camera.main.fov, zdist);
            }
        }
        scale = new Vector3(Mathf.Sign(scale.x) * s, Mathf.Sign(scale.y) * s, Mathf.Sign(scale.z) * s);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Makes the sprite pixel perfect to the active camera.
    /// Automatically detects <see cref="tk2dCamera"/> if present
    /// Otherwise uses Camera.main
    /// </summary>
    public void MakePixelPerfect()
    {
        float s = 1.0f;
        tk2dPixelPerfectHelper pph = tk2dPixelPerfectHelper.inst;

        if (pph)
        {
            if (pph.CameraIsOrtho)
            {
                s = pph.scaleK;
            }
            else
            {
                s = pph.scaleK + pph.scaleD * transform.position.z;
            }
        }
        else if (tk2dCamera.inst)
        {
            if (collection.version < 2)
            {
                Debug.LogError("Need to rebuild sprite collection.");
            }

            s = collection.halfTargetHeight;
        }
        else if (Camera.main)
        {
            if (Camera.main.isOrthoGraphic)
            {
                s = Camera.main.orthographicSize;
            }
            else
            {
                float zdist = (transform.position.z - Camera.main.transform.position.z);
                s = tk2dPixelPerfectHelper.CalculateScaleForPerspectiveCamera(Camera.main.fov, zdist);
            }
        }
        else
        {
            Debug.LogError("Main camera not found.");
        }

        s *= collection.invOrthoSize;

        scale = new Vector3(Mathf.Sign(scale.x) * s, Mathf.Sign(scale.y) * s, Mathf.Sign(scale.z) * s);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Makes the text mesh pixel perfect to the active camera.
    /// Automatically detects <see cref="tk2dCamera"/> if present
    /// Otherwise uses Camera.main
    /// </summary>
    public void MakePixelPerfect()
    {
        float s = 1.0f;
        tk2dPixelPerfectHelper pph = tk2dPixelPerfectHelper.inst;

        if (pph)
        {
            if (pph.CameraIsOrtho)
            {
                s = pph.scaleK;
            }
            else
            {
                s = pph.scaleK + pph.scaleD * transform.position.z;
            }
        }
        else if (tk2dCamera.inst != null)
        {
            if (_fontInst.version < 1)
            {
                Debug.LogError("Need to rebuild font.");
            }

            s = _fontInst.invOrthoSize * _fontInst.halfTargetHeight;
        }
        else if (Camera.main)
        {
            if (Camera.main.isOrthoGraphic)
            {
                s = Camera.main.orthographicSize;
            }
            else
            {
                float zdist = (transform.position.z - Camera.main.transform.position.z);
                s = tk2dPixelPerfectHelper.CalculateScaleForPerspectiveCamera(Camera.main.fieldOfView, zdist);
            }
        }
        scale = new Vector3(Mathf.Sign(scale.x) * s, Mathf.Sign(scale.y) * s, Mathf.Sign(scale.z) * s);
    }
 void Awake()
 {
     Setup();
     _inst = this;
 }
Exemplo n.º 5
0
 void Awake()
 {
     Setup();
     _inst = this;
 }
 private void Awake()
 {
     this.Setup();
     _inst = this;
 }