예제 #1
0
    public void TakePlanViewScreenshot()
    {
        UnityEngine.Object o = Resources.Load("prefabs/ScreenshotCam");
        goPlanCam = (GameObject)GameObject.Instantiate(o);
        Camera PlanCam = goPlanCam.GetComponent <Camera>();

        PlanCam.orthographic = true;
        //find the major axis (two Ctrlpts c1 and c2 furthest apart)
        float     dist = 0;
        BezCtrlPt c1 = new BezCtrlPt(Bez, Vector3.zero), c2 = new BezCtrlPt(Bez, Vector3.zero);

        foreach (BezCtrlPt p1 in Bez.CtrlPts)
        {
            foreach (BezCtrlPt p2 in Bez.CtrlPts)
            {
                float thisdist = Mathf.Pow(p1.Pos.x - p2.Pos.x, 2) + Mathf.Pow(p1.Pos.z - p2.Pos.z, 2);
                if (thisdist > dist)
                {
                    dist = thisdist; c1 = p1; c2 = p2;
                }
            }
        }
        Vector3 c1Pos = new Vector3(c1.Pos.x, 500, c1.Pos.z);
        Vector3 c2Pos = new Vector3(c2.Pos.x, 500, c2.Pos.z);

        PlanCam.transform.position = (c1Pos + c2Pos) / 2;
        PlanCam.transform.LookAt(c1Pos);
        PlanCam.transform.Rotate(Vector3.up, 90);
        float _distFwd = 0, _distBwd = 0;

        foreach (BezCtrlPt p1 in Bez.CtrlPts)
        {
            Vector3 RelPos = PlanCam.transform.InverseTransformPoint(new Vector3(p1.Pos.x, 500, p1.Pos.z));
            if (RelPos.z > _distFwd)
            {
                _distFwd = RelPos.z;
            }
            if (RelPos.z < _distBwd)
            {
                _distBwd = RelPos.z;
            }
        }
        PlanCam.transform.Translate(0, 0, (_distFwd + _distBwd) / 2, Space.Self);
        PlanCam.transform.Rotate(Vector3.right, 90, Space.Self);
        PlanCam.orthographicSize = Mathf.Pow(dist, 0.5f) * (float)Screen.height / (float)Screen.width / 2 * 1.1f;
        //_canvas.SetActive(false);
        goPlanCam.GetComponent <ScreenshotCam>().goCanvas = _canvas;
        goPlanCam.GetComponent <ScreenshotCam>().Grab     = true;
        Bez.SetWidth(10);
        Rd.goRoad.SetActive(false);
        foreach (GameObject t in GameObject.FindGameObjectsWithTag("Terrain"))
        {
            t.GetComponent <Terrain>().enabled = false;
        }
        //Debug.Break();
    }