- 最后登录
- 2021-7-6
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 76145
- 纳金币
- 53488
- 精华
- 316
|
- /// <summary>
- /// 判断一个物体是否可见
- /// </summary>
- /// <returns><c>true</c> if this instance is visible the specified go; otherwise, <c>false</c>.</returns>
- /// <param name="go">如果不可见返回0,可见=1.</param>
- int IsVisible(GameObject go)
- {
- int ret = -1;
- if(go!=null && Camera.main!=null)
- {
- Vector3 pos = Camera.main.WorldToViewportPoint(go.transform.position);
- bool isVisible = ( Camera.main.orthographic || pos.z > 0f)
- && ( (pos.x > 0f && pos.x < 1f && pos.y > 0f && pos.y < 1f));
- ret = isVisible==true ?1:0;
- return ret;
- }
- return ret;
- }
- //这个是通过render来判断,但是感觉没上面那个好用
- bool ReaderIsVisible(GameObject gameObjcet)
- {
- bool isVisbel = false;
- MeshRenderer[] renders = gameObject.GetComponentsInChildren<MeshRenderer> ();
- foreach(MeshRenderer render in renders)
- {
- if( render.isVisible ==true)
- {
- isVisbel =true;
- }
- }
- return isVisbel;
- }
复制代码 |
|