using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
///
/// XR UIが反応しない原因を自動判定する超安全な診断スクリプト
///
public class XRUIDiagnoser : MonoBehaviour
{
private void Start()
{
Debug.Log("============== 🔍 XR UI 自動診断スタート ==============");
// 1. EventSystem の重複・存在チェック
var eventSystems = FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None);
if (eventSystems.Length == 0)
{
Debug.LogError("🚨【原因】シーンに EventSystem が存在しません!");
}
else if (eventSystems.Length > 1)
{
Debug.LogError($"🚨【原因】EventSystem がシーンに {eventSystems.Length} 個あります!これが最大の原因になりやすいです。不要な方を削除してください。");
foreach (var es in eventSystems) Debug.Log($" ・配置場所: {es.gameObject.name}", es.gameObject);
}
else
{
var module = eventSystems[0].GetComponent();
Debug.Log($"⭕ EventSystem: OK [{eventSystems[0].name}] | Module: {(module != null ? module.GetType().Name : "なし")}");
}
// 2. Ray Interactor (ビーム発射体) の存在チェック (名前で動的探索するためバージョンエラーになりません)
var allComponents = FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None);
int rayCount = 0;
foreach (var c in allComponents)
{
if (c != null && c.GetType().Name.Contains("RayInteractor"))
{
rayCount++;
bool active = c.gameObject.activeInHierarchy;
if (!active)
Debug.LogError($"🚨【原因】[{c.gameObject.name}] の RayInteractor オブジェクトが非アクティブ(OFF)になっています!", c.gameObject);
else
Debug.Log($"⭕ Ray Interactor 発見: [{c.gameObject.name}] ({c.GetType().Name}) | Active: OK");
}
}
if (rayCount == 0)
{
Debug.LogError("🚨【原因】コントローラーの手のオブジェクトに RayInteractor コンポーネントが見つかりません!");
}
// 3. Canvas の設定チェック
var canvases = FindObjectsByType