AntiAddictionConst.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. public class AntiAddictionConst
  4. {
  5. public const string MAIN_CANVAS_NAME = "Prefabs/TaptapAntiAddictionMainCanvas";
  6. private const string MOBILE_UI_FOLDER = "Prefabs/Mobile";
  7. private const string STANDALONE_UI_FOLDER = "Prefabs/Standalone";
  8. public const string TIME_SELECTOR_PANEL_NAME = "TapTapVietnamTimeSelectorPanel";
  9. public const string ID_NUMBER_INPUT_PANEL_NAME = "TapTapChinaIDInputPanel";
  10. public const string RETRY_ALERT_PANEL_NAME = "TapTapAntiAddictionRetryAlert";
  11. public const string HEALTH_REMINDER_PANEL_NAME = "TapTapHealthReminderPanel";
  12. public const string VERIFY_FINISH_PANEL_NAME = "TapTapChinaVerifyFinishPanel";
  13. public const string HEALTH_PAYMENT_PANEL_NAME = "TapTapHealthPaymentPanel";
  14. /// <summary>
  15. /// 获取预制体全路径
  16. /// </summary>
  17. /// <param name="prefabName">预制体名字</param>
  18. /// <param name="isMobile">是否需要移动版 Prefab,否则即为 Standalone 版本</param>
  19. /// <param name="fallback">如果寻找失败,是否用另一版本 UI 作为备选方案.比如: 找不到 Standalone 版本时, 自动使用移动版 UI</param>
  20. /// <returns></returns>
  21. public static string GetPrefabPath(string prefabName, bool isMobile = true, bool fallback = true)
  22. {
  23. var firstFolder = isMobile ? MOBILE_UI_FOLDER : STANDALONE_UI_FOLDER;
  24. var secondFolder = isMobile ? STANDALONE_UI_FOLDER : MOBILE_UI_FOLDER;
  25. var fullPath = $"{firstFolder}/{prefabName}";
  26. if (prefabStubs.TryGetValue(fullPath, out bool val) && val)
  27. return fullPath;
  28. if (Resources.Load<GameObject>(fullPath) != null)
  29. {
  30. prefabStubs[fullPath] = true;
  31. return fullPath;
  32. }
  33. if (!fallback) return null;
  34. fullPath = $"{secondFolder}/{prefabName}";
  35. if (prefabStubs.TryGetValue(fullPath, out bool val2) && val2)
  36. return fullPath;
  37. if (Resources.Load<GameObject>(fullPath) == null) return null;
  38. prefabStubs[fullPath] = true;
  39. return fullPath;
  40. }
  41. private static readonly Dictionary<string, bool> prefabStubs = new Dictionary<string, bool>();
  42. }