TestTownShopUI.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. public class TestTownShopUI : MonoBehaviour
  4. {
  5. public void TestShopUI()
  6. {
  7. Debug.Log("Creating test shop UI...");
  8. var shopUIObject = new GameObject("TestTownShopUI");
  9. var uiDocument = shopUIObject.AddComponent<UIDocument>();
  10. // Load the UXML
  11. uiDocument.visualTreeAsset = Resources.Load<VisualTreeAsset>("UI/TownShopUI");
  12. if (uiDocument.visualTreeAsset == null)
  13. {
  14. Debug.LogError("Failed to load UXML!");
  15. return;
  16. }
  17. Debug.Log("UXML loaded successfully");
  18. // Get the root and shop container
  19. var root = uiDocument.rootVisualElement;
  20. var shopContainer = root?.Q<VisualElement>("shop-container");
  21. Debug.Log($"Root: {root != null}, ShopContainer: {shopContainer != null}");
  22. if (shopContainer != null)
  23. {
  24. shopContainer.style.display = DisplayStyle.Flex;
  25. Debug.Log("Shop container made visible");
  26. // Test setting some content
  27. var shopName = root.Q<Label>("shop-name");
  28. if (shopName != null)
  29. {
  30. shopName.text = "TEST SHOP";
  31. Debug.Log("Shop name set");
  32. }
  33. }
  34. }
  35. }