問題描述:
在開發中,經常會遇到需要判斷UI層次的問題,比如imagetop 在 imageCenter上層 ,imageCenter 在 imageBottom上層,注意這裏的層次關係指的是實際的UI顯示層次
與UI在Hierachy中的層級無關,此時就要判斷出這種層次關係來;
解決思路:
public RectTransform rect;
public Canvas ca;
public Vector2 v2;
void OnGUI(){
if(GUILayout.Button("dddfffff"))
{
v2= RectTransformUtility.WorldToScreenPoint (ca.worldCamera, rect.position);
PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
eventDataCurrentPosition.position = v2;
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
for (int i = 0; i < results.Count; i++) {
Debug.Log (results[i].gameObject.name);
}
}
}