当前位置: 首页>>代码示例>>C#>>正文


C# Camera.WorldToScreenPoint方法代码示例

本文整理汇总了C#中Camera.WorldToScreenPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.WorldToScreenPoint方法的具体用法?C# Camera.WorldToScreenPoint怎么用?C# Camera.WorldToScreenPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Camera的用法示例。


在下文中一共展示了Camera.WorldToScreenPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: applyPlanarMapping

    void applyPlanarMapping(float imageWidth, float imageHeight, float _offsetX, float _offsetY, Camera mainCamera)
    {
        Mesh mesh = GetComponent<MeshFilter> ().mesh;
        Vector3[] vertices = mesh.vertices;
        Vector2[] uvs = mesh.uv;
        int count = mesh.vertexCount;
        //Debug.Log("mask count : "+count);

        if (vertices.Length != 0) {
            for (int i = 0; i < count; i++) {
                Vector3 vertexPos = vertices[i];
                //	Debug.Log("mask applyPlanarMapping count : "+count);
                if (vertexPos == null)
                    return;
                //	Debug.Log("mask applyPlanarMapping vertexPos : ");
                if (mainCamera == null)
                    return;
                //	Debug.Log("mask applyPlanarMapping mainCamera : ");
                vertexPos = localToWorld (vertexPos, mesh);
                Vector3 screenPos = mainCamera.WorldToScreenPoint (vertexPos);

                // calcul des nouvelles coordonées de texture
                float xT = (screenPos.x + _offsetX) / imageWidth;
                float yT = (screenPos.y + _offsetY) / imageHeight;
                uvs[i] = new Vector2 (xT, yT);
            }
        }
        mesh.uv = uvs;
    }
开发者ID:gviaud,项目名称:OS-unity-5,代码行数:29,代码来源:Mask.cs

示例2: CheckWithinScreen

	public static bool CheckWithinScreen (Vector2 position, Camera camera, float distance) {
		Vector3 minScreenPosition = camera.WorldToScreenPoint(new Vector2(position.x - distance, position.y - distance));
		Vector3 screenPosition = camera.WorldToScreenPoint(position);
		float distanceInScreen = Math.Abs(screenPosition.x - minScreenPosition.x);
		return !(screenPosition.x + distanceInScreen <= 0 || screenPosition.x - distanceInScreen >= camera.pixelWidth || 
		         screenPosition.y + distanceInScreen <= 0 || screenPosition.y - distanceInScreen >= camera.pixelHeight);
	}
开发者ID:Cyberbanan,项目名称:2D-Light-of-Sight-Unity,代码行数:7,代码来源:SHelper.cs

示例3: Start

    void Start()
    {
        graphics = gameObject.GetComponent<MeshFilter>();
        screen = graphics.mesh;
        mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
        math = new screenMath(width, height, screen);

        lowerLeft = mainCamera.WorldToScreenPoint(screen.vertices[math.lookup(0, 0)[0]] + transform.position);
        upperRight = mainCamera.WorldToScreenPoint(screen.vertices[math.lookup(width-1, height-1)[3]] + transform.position);
    }
开发者ID:Bcadren,项目名称:AdventureTime,代码行数:10,代码来源:editorScreen.cs

示例4: DrawLine

 public static void DrawLine(Camera cam, Vector3 pointA, Vector3 pointB, Color color, float width)
 {
     Vector2 p1 = Vector2.zero;
      p1.x = cam.WorldToScreenPoint(pointA).x;
      p1.y = cam.pixelHeight - cam.WorldToScreenPoint(pointA).y;
      Vector2 p2 = Vector2.zero;
      p2.x = cam.WorldToScreenPoint(pointB).x;
      p2.y = cam.pixelHeight - cam.WorldToScreenPoint(pointB).y;
      DrawLine(p1,p2,color,width);
 }
开发者ID:BrianShiau,项目名称:TeamGimli,代码行数:10,代码来源:Drawing.cs

示例5: SpriteScreenSize

 public Vector2 SpriteScreenSize(GameObject o, Camera cam = null)
 {
     if (cam == null) cam = Camera.main;
     Vector2 sdim = new Vector2();
     Renderer ren = o.GetComponent<Renderer>() as Renderer;
     if (ren)
     {
         sdim = cam.WorldToScreenPoint(ren.bounds.max) -
             cam.WorldToScreenPoint(ren.bounds.min);
     }
     return sdim;
 }
开发者ID:YaFengYi,项目名称:Unity,代码行数:12,代码来源:PlayerProjectile.cs

示例6: CalculateBox

    /// <summary>
    /// Calculates the box surrounding the collider
    /// </summary>
    /// <returns>The box</returns>
    /// <param name="collider">The collider of the element</param>
    public static Rect CalculateBox(Collider collider, Camera cam)
    {
        Rect box = new Rect();
        //Calculate size of overlay based on the objects size
        Vector3 max = collider.bounds.max;
        Vector3 min = collider.bounds.min;

        Vector3 lowerTopLeft = cam.WorldToScreenPoint(new Vector3(min.x, min.y, max.z));
        Vector3 lowerTopRight = cam.WorldToScreenPoint(new Vector3(max.x, min.y, max.z));
        Vector3 lowerBottomLeft = cam.WorldToScreenPoint(new Vector3(min.x, min.y, min.z));
        Vector3 lowerBottomRight = cam.WorldToScreenPoint(new Vector3(max.x, min.y, min.z));

        Vector3 upperTopLeft = cam.WorldToScreenPoint(new Vector3(min.x, max.y, max.z));
        Vector3 upperTopRight = cam.WorldToScreenPoint(new Vector3(max.x, max.y, max.z));
        Vector3 upperBottomLeft = cam.WorldToScreenPoint(new Vector3(min.x, max.y, min.z));
        Vector3 upperBottomRight = cam.WorldToScreenPoint(new Vector3(max.x, max.y, min.z));


        box.xMin = Mathf.Min(lowerTopLeft.x, lowerTopRight.x, lowerBottomLeft.x, lowerBottomRight.x, upperTopLeft.x, upperTopRight.x, upperBottomRight.x, upperBottomLeft.x) - 5;
        box.xMax = Mathf.Max(lowerTopLeft.x, lowerTopRight.x, lowerBottomLeft.x, lowerBottomRight.x, upperTopLeft.x, upperTopRight.x, upperBottomRight.x, upperBottomLeft.x) + 5;
        box.yMin = Screen.height - Mathf.Max(lowerTopLeft.y, lowerTopRight.y, lowerBottomLeft.y, lowerBottomRight.y, upperTopLeft.y, upperTopRight.y, upperBottomRight.y, upperBottomLeft.y) - 15;
        box.yMax = Screen.height - Mathf.Min(lowerTopLeft.y, lowerTopRight.y, lowerBottomLeft.y, lowerBottomRight.y, upperTopLeft.y, upperTopRight.y, upperBottomRight.y, upperBottomLeft.y) + 5;
        return box;

    }
开发者ID:srferran,项目名称:ES2015A,代码行数:30,代码来源:AreaMarker.cs

示例7: setText

    public void setText(GeneralSoldier soldier, string str)
    {
        if(true)
        {
            return;
        }

        //摄像机对象
        _camera = Camera.main;

        //获取角色head模型
        headTr = soldier.gameObject.transform.Find("head");

        //得到模型head坐标
        float size_y = headTr.position.y;

        //得到模型缩放比例
        float scal_y = transform.localScale.y;

        //乘积就是高度
        playerHeight = scal_y * size_y;

        //计算世界坐标
        worldPostion = new Vector3(soldier.gameObject.transform.position.x, soldier.gameObject.transform.position.y + playerHeight, soldier.gameObject.transform.position.z);

        //根据对象头顶的3D坐标换算成它在2D屏幕中的坐标
        postion = _camera.WorldToScreenPoint(worldPostion);

        //得到真实对象头顶的2D坐标
        postion = new Vector2(postion.x, Screen.height - postion.y);

        //设置伤害
        dmgText.text = str;

        //获取画布
        GameObject canvas = GameObject.Find("Canvas");
        dmgText.transform.SetParent(canvas.transform);

        //设置锚点
        RectTransform rt = dmgText.gameObject.transform as RectTransform;
        rt.anchoredPosition = Vector2.zero;
        dmgText.gameObject.transform.localScale = Vector3.one;

        //设置坐标
        dmgText.transform.position = postion;

        //缓动
        iTween.FadeTo(gameObject, 0.1f, 1);

        iTween.ScaleTo(gameObject, new Vector3(2, 2, 2), 1);

        Hashtable hxb = new Hashtable();
        hxb.Add("position", new Vector3(dmgText.transform.position.x, dmgText.transform.position.y + 180, dmgText.transform.position.z));
        hxb.Add("time", 1.1f);
        hxb.Add("easetype", iTween.EaseType.easeOutCubic);
        hxb.Add("oncomplete", "onAnimationEnd");
        hxb.Add("oncompletetarget", this.gameObject);
        hxb.Add("oncompleteparams", this.gameObject.name);
        iTween.MoveTo(gameObject, hxb);
    }
开发者ID:zhaoyabo,项目名称:GameBase,代码行数:60,代码来源:LifeText.cs

示例8: Awake

 // Use this for initialization
 void Awake()
 {
     _camera = GameObject.Find("Main Camera").GetComponent<Camera>();
     _myTransform = transform;
     _textPos = _camera.WorldToScreenPoint(transform.position);
     _boxSize = new Vector2(80, 25);
 }
开发者ID:Ahbork,项目名称:RemoteRepo,代码行数:8,代码来源:ImageSavePoint.cs

示例9: InCamera

    public static bool InCamera(Camera LookCamera, GameObject go, float VisionDistance)
    {
        #region 檢查是否在指定攝影範圍內
        if (LookCamera == null)
            return false;
        Collider collider = go.GetComponent<Collider>();
        if (collider == null)
            return false;
        Plane[] planes = GeometryUtility.CalculateFrustumPlanes(LookCamera);
        bool isOnCamera = GeometryUtility.TestPlanesAABB(planes, collider.bounds);
        if (!isOnCamera)
            return false;
        #endregion 檢查是否在指定攝影範圍內


        #region 檢查是否有遮蔽物
        //這是簡陋板,只能檢查無體中新點是否有被遮擋無法判定是否有任何地方有顯示
        #region 取得看到的物體
        if (LookCamera == null)
            return false;
        Vector3 screenPoint = LookCamera.WorldToScreenPoint(go.transform.position);
        Ray ray = LookCamera.ScreenPointToRay(screenPoint);
        RaycastHit hit;
        if (!Physics.Raycast(ray, out hit, VisionDistance))
            return false;
        #endregion 取得看到的物體

        //檢查看到的物件是否是自己
        bool result = hit.transform == go.transform;
        #endregion 檢查是否有遮蔽物


        return result;
    }
开发者ID:gmfnasg,项目名称:Look,代码行数:34,代码来源:OnCamera.cs

示例10: CalculatePositionFromTransformToRectTransform

    // OBTAINED FROM http://answers.unity3d.com/questions/849117/46-ui-image-follow-mouse-position.html

    #region Canvas
    /// <summary>
    /// Calulates Position for RectTransform.position from a transform.position. Does not Work with WorldSpace Canvas!
    /// </summary>
    /// <param name="_Canvas"> The Canvas parent of the RectTransform.</param>
    /// <param name="_Position">Position of in world space of the "Transform" you want the "RectTransform" to be.</param>
    /// <param name="_Cam">The Camera which is used. Note this is useful for split screen and both RenderModes of the Canvas.</param>
    /// <returns></returns>
    public static Vector3 CalculatePositionFromTransformToRectTransform(this Canvas _Canvas, Vector3 _Position, Camera _Cam)
    {
        Vector3 Return = Vector3.zero;
        if (_Canvas.renderMode == RenderMode.ScreenSpaceOverlay)
        {
            Return = _Cam.WorldToScreenPoint(_Position);
        }
        else if (_Canvas.renderMode == RenderMode.ScreenSpaceCamera)
        {
            Vector2 tempVector = Vector2.zero;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(_Canvas.transform as RectTransform, _Cam.WorldToScreenPoint(_Position), _Cam, out tempVector);
            Return = _Canvas.transform.TransformPoint(tempVector);
        }

        return Return;
    }
开发者ID:RotaruDan,项目名称:firstaidgame,代码行数:26,代码来源:TransformUtils.cs

示例11: GUI3D

    public static Rect GUI3D(Camera camera, Vector3 pos, float width = 100, float height = 25)
    {
        Vector2 point = camera.WorldToScreenPoint(pos);

        Rect rect = new Rect(point.x, (Screen.height - point.y), width, height);

        return rect;
    }
开发者ID:JokeIRz,项目名称:Unity-VisualizationTF,代码行数:8,代码来源:GUI2.cs

示例12: WorldToCanvasPosition

 public static Vector3 WorldToCanvasPosition(Vector3 pos, Canvas canvas, Camera viewCam)
 {
     RectTransform canvasRectT = canvas.GetComponent<RectTransform>();
     Vector3 screenPos = viewCam.WorldToScreenPoint(pos);
     Vector3 worldPos = Vector2.zero;
     RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRectT, screenPos, canvas.worldCamera, out worldPos);
     return worldPos;
 }
开发者ID:inoook,项目名称:uGUICanvasTools,代码行数:8,代码来源:CanvasUtils.cs

示例13: Awake

	void Awake()
	{
		mainCamera = GameObject.Find("Main Camera").GetComponent<Camera>();
		enemyStats = new EnemyStats();
		enemyStatBarCreator = GameObject.Find("EnemyStats Canvas").GetComponent<EnemyStatBarCreation>();
		enemyStatBar = enemyStatBarCreator.CreateEnemyStatBar(mainCamera.WorldToScreenPoint(transform.position));
		enemyHealthText = enemyStatBar.transform.GetChild(1).GetComponent<Text>();
		enemySpeedText = enemyStatBar.transform.GetChild(3).GetComponent<Text>();
	}
开发者ID:achynes,项目名称:ChezzScripts,代码行数:9,代码来源:EnemyControl.cs

示例14: GetScreenRect

    public static Rect GetScreenRect(Vector2[] worldPoints, Camera camera)
    {
        Vector2[] screenPoints = new Vector2[worldPoints.Length];
        for (int i = 0; i < worldPoints.Length; i++)
        {
            screenPoints[i] = camera.WorldToScreenPoint(worldPoints[i]);
        }

        return BuildScreenRect(screenPoints);
    }
开发者ID:SharperZeroCool,项目名称:Dark-Watcher,代码行数:10,代码来源:GeometryHelper.cs

示例15: Start

 void Start()
 {
     cam = Camera.mainCamera;
     foreach (Tower t in FindObjectsOfType(typeof(Tower)) as Tower[]) {
         TowerOnScreen nT = new TowerOnScreen(t);
         Vector3 tPos = cam.WorldToScreenPoint(t.transform.position);
         nT.priceRect = new Rect(tPos.x - 25, Screen.height - tPos.y, 50, 20);
         towers.Add(nT);
     }
 }
开发者ID:splashdamage,项目名称:AntsVsMice,代码行数:10,代码来源:Info.cs


注:本文中的Camera.WorldToScreenPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。