参考文章
http://gototokyo.blog.163.com/blog/static/2838342014382736641/
UICameraEditor
string[] options = new string[] { "3D World", "3D UI", "2D World", "2D UI"};
string[] options = new string[] { "3D World", "3D UI", "2D World", "2D UI" , "UI_2D3D"};
UICamera
添加
else if(cam.eventType == EventType.UI_2D3D)
{
int bufDepth = -1;
if (m2DPlane.Raycast(ray, out dist))
{
lastWorldPosition = ray.GetPoint(dist);
Collider2D[] hits = Physics2D.OverlapPointAll(lastWorldPosition, mask);
if (hits.Length >= 1)
{
for (int b = 0; b < hits.Length; ++b)
{
GameObject go = hits[b].gameObject;
UIWidget w = go.GetComponent<UIWidget>();
if (w != null)
{
if (!w.isVisible) continue;
if (w.hitCheck != null && !w.hitCheck(lastWorldPosition)) continue;
}
else
{
UIRect rect = NGUITools.FindInParents<UIRect>(go);
if (rect != null && rect.finalAlpha < 0.001f) continue;
}
mHit.depth = NGUITools.CalculateRaycastDepth(go);
if (mHit.depth != int.MaxValue)
{
mHit.go = go;
mHit.point = lastWorldPosition;
mHits.Add(mHit);
}
}
mHits.Sort(delegate(DepthEntry r1, DepthEntry r2) { return r2.depth.CompareTo(r1.depth); });
for (int b = 0; b < mHits.size; ++b)
{
#if UNITY_FLASH
if (IsVisible(mHits.buffer[b]))
#else
if (IsVisible(ref mHits.buffer[b]))
#endif
{
bufDepth = mHits[b].depth;
hoveredObject = mHits[b].go;
mHits.Clear();
break;
}
}
mHits.Clear();
}
}
if(true)
{
RaycastHit[] hits = Physics.RaycastAll(ray, dist, mask);
if (hits.Length >= 1)
{
for (int b = 0; b < hits.Length; ++b)
{
GameObject go = hits[b].collider.gameObject;
UIWidget w = go.GetComponent<UIWidget>();
if (w != null)
{
if (!w.isVisible) continue;
if (w.hitCheck != null && !w.hitCheck(hits[b].point)) continue;
}
else
{
UIRect rect = NGUITools.FindInParents<UIRect>(go);
if (rect != null && rect.finalAlpha < 0.001f) continue;
}
mHit.depth = NGUITools.CalculateRaycastDepth(go);
if (mHit.depth != int.MaxValue)
{
mHit.hit = hits[b];
mHit.point = hits[b].point;
mHit.go = hits[b].collider.gameObject;
mHits.Add(mHit);
}
}
mHits.Sort(delegate(DepthEntry r1, DepthEntry r2) { return r2.depth.CompareTo(r1.depth); });
for (int b = 0; b < mHits.size; ++b)
{
#if UNITY_FLASH
if (IsVisible(mHits.buffer[b]))
#else
if (IsVisible(ref mHits.buffer[b]))
#endif
{
if(hoveredObject == null || bufDepth < mHits[b].depth)
{
lastHit = mHits[b].hit;
hoveredObject = mHits[b].go;
lastWorldPosition = mHits[b].point;
mHits.Clear();
break;
}
}
}
mHits.Clear();
}
}
if(hoveredObject != null)
{
return true;
}
continue;
}