Example #1
0
        void OverCamera(Camera cam)
        {
            if (cam != null)
            {
                int w = cam.pixelWidth;
                int h = cam.pixelHeight;


#if UNITY_IPHONE || UNITY_ANDROID
                float ss = Mathf.Sqrt(w * w + h * h);
#if UNITY_EDITOR
                ss /= 334;
#else
                ss /= Screen.dpi;
#endif
                float ps = 1;
                float r  = (ss - A.x) / (D.x - A.x);
                if (r < 0)
                {
                    ps = A.y;
                }
                else if (r > 1)
                {
                    ps = D.y;
                }
                else
                {
                    ps = MathH.BezierPoint(r, ref A, ref B, ref C, ref D).y;
                }
                PhysicalScale = ps;
#else
                if (scaleType == ScaleType.FillX)
                {
                    PhysicalScale = w / DesignSize.x;
                }
                else if (scaleType == ScaleType.FillY)
                {
                    PhysicalScale = h / DesignSize.y;
                }
                float ps = PhysicalScale;
                if (ps < 0.01f)
                {
                    ps = 0.01f;
                }
#endif
                m_sizeDelta.x = w / ps;
                m_sizeDelta.y = h / ps;
                float near = cam.nearClipPlane + NearPlane;
                if (cam.orthographic)
                {
                    float os = cam.orthographicSize * 2;
                    float s  = os / (float)h;
                    s *= ps;
                    transform.localScale = new Vector3(s, s, s);
                    Vector3 pos     = cam.transform.position;
                    Vector3 forward = cam.transform.forward;
                    transform.position = pos + forward * near;
                    transform.forward  = forward;
                }
                else
                {
                    float s = 2 / (float)h;
                    float o = MathH.Tan(cam.fieldOfView) / near;
                    s /= o;
                    s *= ps;
                    transform.localScale = new Vector3(s, s, s);
                    Vector3 pos     = cam.transform.position;
                    Vector3 forward = cam.transform.forward;
                    transform.position = pos + forward * near;
                    transform.forward  = forward;
                }
                transform.rotation = cam.transform.rotation;
            }
        }