TownShopUIDebugger.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. [System.Serializable]
  4. public class TownShopUIDebugger : MonoBehaviour
  5. {
  6. [ContextMenu("Debug Shop UI State")]
  7. public void DebugShopUIState()
  8. {
  9. var shopUIs = FindObjectsByType<TownShopUI>(FindObjectsSortMode.None);
  10. Debug.Log($"Found {shopUIs.Length} TownShopUI instances");
  11. foreach (var shopUI in shopUIs)
  12. {
  13. Debug.Log($"=== TownShopUI: {shopUI.gameObject.name} ===");
  14. var uiDoc = shopUI.GetComponent<UIDocument>();
  15. if (uiDoc != null)
  16. {
  17. Debug.Log($"UIDocument found - enabled: {uiDoc.enabled}");
  18. Debug.Log($"PanelSettings: {uiDoc.panelSettings != null}");
  19. Debug.Log($"SortingOrder: {uiDoc.sortingOrder}");
  20. Debug.Log($"VisualTreeAsset: {uiDoc.visualTreeAsset != null}");
  21. if (uiDoc.rootVisualElement != null)
  22. {
  23. var root = uiDoc.rootVisualElement;
  24. Debug.Log($"Root element - visible: {root.visible}, display: {root.style.display.value}, position: {root.style.position.value}");
  25. Debug.Log($"Root worldBound: {root.worldBound}");
  26. var shopContainer = root.Q<VisualElement>("shop-container");
  27. if (shopContainer != null)
  28. {
  29. Debug.Log($"Shop container - visible: {shopContainer.visible}, display: {shopContainer.style.display.value}");
  30. Debug.Log($"Shop container worldBound: {shopContainer.worldBound}");
  31. }
  32. else
  33. {
  34. Debug.LogError("shop-container element not found!");
  35. }
  36. }
  37. else
  38. {
  39. Debug.LogError("Root visual element is null!");
  40. }
  41. }
  42. else
  43. {
  44. Debug.LogError("No UIDocument component found!");
  45. }
  46. }
  47. // Check all UIDocuments in scene
  48. var allUIDocuments = FindObjectsByType<UIDocument>(FindObjectsSortMode.None);
  49. Debug.Log($"\n=== All UIDocuments in scene ({allUIDocuments.Length}) ===");
  50. foreach (var doc in allUIDocuments)
  51. {
  52. var panelSort = doc.panelSettings?.sortingOrder ?? -999;
  53. Debug.Log($"UIDocument '{doc.gameObject.name}' - sortingOrder: {doc.sortingOrder}, PanelSettings sortingOrder: {panelSort}");
  54. }
  55. }
  56. [ContextMenu("Force Open Test Shop")]
  57. public void ForceOpenTestShop()
  58. {
  59. // Create a test shop
  60. var testShop = new TownShop
  61. {
  62. buildingName = "Test Shop",
  63. shopkeeperName = "Test Keeper",
  64. shopType = ShopType.General
  65. };
  66. var townManager = FindFirstObjectByType<TownManager>();
  67. if (townManager != null)
  68. {
  69. townManager.OnBuildingClicked(testShop);
  70. }
  71. else
  72. {
  73. Debug.LogError("TownManager not found!");
  74. }
  75. }
  76. }