| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using System; |
| | | using TableConfig; |
| | | using System.IO; |
| | | |
| | | public class UILoader |
| | | { |
| | | readonly static string PREFAB_EXTERSION = ".prefab"; |
| | | readonly static string SPRITE_EXTERSION = ".png"; |
| | | |
| | | public static GameObject LoadWindow(string _name) |
| | | { |
| | | GameObject window = null; |
| | | if (AssetSource.uiFromEditor) |
| | | { |
| | | #if UNITY_EDITOR |
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name); |
| | | |
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, |
| | | isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX : ResourcesPath.UI_WINDOW_SUFFIX, "/", |
| | | _name, |
| | | PREFAB_EXTERSION); |
| | | |
| | | window = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name); |
| | | var bundleName = isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX.ToLower() : ResourcesPath.UI_WINDOW_SUFFIX.ToLower(); |
| | | var assetInfo = new AssetInfo(bundleName, _name); |
| | | |
| | | window = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject; |
| | | } |
| | | |
| | | if (window == null) |
| | | { |
| | | DesignDebug.LogErrorFormat("UILoader.LoadWindow() => 加载不到资源: {0}.", _name); |
| | | } |
| | | |
| | | return window; |
| | | } |
| | | |
| | | public static void LoadWindowAsync(string _name, Action<bool, UnityEngine.Object> _callBack) |
| | | { |
| | | GameObject window = null; |
| | | if (AssetSource.uiFromEditor) |
| | | { |
| | | #if UNITY_EDITOR |
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name); |
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, |
| | | isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX : ResourcesPath.UI_WINDOW_SUFFIX, "/", |
| | | _name, |
| | | PREFAB_EXTERSION); |
| | | |
| | | window = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path); |
| | | if (_callBack != null) |
| | | { |
| | | _callBack(window != null, window); |
| | | } |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name); |
| | | var bundleName = isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX.ToLower() : ResourcesPath.UI_WINDOW_SUFFIX.ToLower(); |
| | | var assetInfo = new AssetInfo(bundleName, _name); |
| | | |
| | | AssetBundleUtility.Instance.Co_LoadAsset(assetInfo, _callBack); |
| | | } |
| | | } |
| | | |
| | | public static void UnLoadWindowAsset(string _assetName) |
| | | { |
| | | if (!AssetSource.uiFromEditor) |
| | | { |
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_assetName); |
| | | var bundleName = isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX.ToLower() : ResourcesPath.UI_WINDOW_SUFFIX.ToLower(); |
| | | |
| | | AssetBundleUtility.Instance.UnloadAsset(bundleName, _assetName); |
| | | } |
| | | } |
| | | |
| | | public static GameObject LoadPrefab(string _name) |
| | | { |
| | | GameObject prefab = null; |
| | | if (AssetSource.uiFromEditor) |
| | | { |
| | | #if UNITY_EDITOR |
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, |
| | | ResourcesPath.UI_PREFAB_SUFFIX, "/", |
| | | _name, |
| | | PREFAB_EXTERSION); |
| | | |
| | | prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | var bundleName = ResourcesPath.UI_PREFAB_SUFFIX.ToLower(); |
| | | var assetInfo = new AssetInfo(bundleName, _name); |
| | | |
| | | prefab = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject; |
| | | } |
| | | |
| | | if (prefab == null) |
| | | { |
| | | DesignDebug.LogErrorFormat("UILoader.LoadPrefab() => 加载不到资源: {0}.", _name); |
| | | } |
| | | |
| | | return prefab; |
| | | } |
| | | |
| | | public static void UnLoadPrefab(string _assetName) |
| | | { |
| | | if (!AssetSource.uiFromEditor) |
| | | { |
| | | AssetBundleUtility.Instance.UnloadAsset("ui/prefab", _assetName); |
| | | } |
| | | } |
| | | |
| | | public static Sprite LoadSprite(string _iconKey) |
| | | { |
| | | var iconConfig = ConfigManager.Instance.GetTemplate<IconConfig>(_iconKey); |
| | | if (iconConfig == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return LoadSprite(iconConfig.folder, iconConfig.sprite); |
| | | } |
| | | |
| | | public static Sprite LoadSprite(string _folder, string _file) |
| | | { |
| | | var folder = _folder; |
| | | var file = _file; |
| | | |
| | | Sprite sprite = null; |
| | | if (AssetSource.uiFromEditor) |
| | | { |
| | | #if UNITY_EDITOR |
| | | var relativePath = StringUtility.Contact(folder, "/", file); |
| | | var rootPath = ResourcesPath.UI_SPRITE_SUFFIX; |
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, |
| | | rootPath, "/", |
| | | relativePath, |
| | | SPRITE_EXTERSION); |
| | | |
| | | sprite = UnityEditor.AssetDatabase.LoadAssetAtPath<Sprite>(path); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | var bundleName = StringUtility.Contact("ui/sprite/", folder.ToLower()); |
| | | var assetInfo = new AssetInfo(bundleName, file); |
| | | |
| | | sprite = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(Sprite)) as Sprite; |
| | | } |
| | | |
| | | if (sprite == null) |
| | | { |
| | | DesignDebug.LogErrorFormat("UILoader.LoadSprite() => 加载不到资源: {0}.", file); |
| | | } |
| | | |
| | | return sprite; |
| | | } |
| | | |
| | | public static void UnLoadSprite(string _iconKey) |
| | | { |
| | | if (!AssetSource.uiFromEditor) |
| | | { |
| | | var iconConfig = ConfigManager.Instance.GetTemplate<IconConfig>(_iconKey); |
| | | if (iconConfig != null) |
| | | { |
| | | var bundleName = StringUtility.Contact("ui/sprite/", iconConfig.folder.ToLower()); |
| | | AssetBundleUtility.Instance.UnloadAsset(bundleName, iconConfig.sprite); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | public static Font LoadFont(string _fontName) |
| | | { |
| | | Font font = null; |
| | | if (AssetSource.uiFromEditor) |
| | | { |
| | | #if UNITY_EDITOR |
| | | var rootPath = ResourcesPath.UI_FONT_SUFFIX; |
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, rootPath, "/", _fontName, ".ttf"); |
| | | font = UnityEditor.AssetDatabase.LoadAssetAtPath<Font>(path); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | var assetInfo = new AssetInfo("ui/font", _fontName); |
| | | font = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(Font)) as Font; |
| | | } |
| | | |
| | | if (font == null) |
| | | { |
| | | DesignDebug.LogErrorFormat("UILoader.LoadFont() => 加载不到资源: {0}.", _fontName); |
| | | } |
| | | |
| | | return font; |
| | | } |
| | | |
| | | public static void UnLoadFont(string _fontName) |
| | | { |
| | | if (!AssetSource.uiFromEditor) |
| | | { |
| | | AssetBundleUtility.Instance.UnloadAsset("ui/font", _fontName); |
| | | } |
| | | } |
| | | |
| | | } |
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | | using UnityEngine;
|
| | | using System;
|
| | | using TableConfig;
|
| | | using System.IO;
|
| | |
|
| | | [XLua.LuaCallCSharp]
|
| | | public class UILoader
|
| | | {
|
| | | readonly static string PREFAB_EXTERSION = ".prefab";
|
| | | readonly static string SPRITE_EXTERSION = ".png";
|
| | |
|
| | | public static GameObject LoadWindow(string _name)
|
| | | {
|
| | | GameObject window = null;
|
| | | if (AssetSource.uiFromEditor)
|
| | | {
|
| | | #if UNITY_EDITOR
|
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name);
|
| | |
|
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
| | | isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX : ResourcesPath.UI_WINDOW_SUFFIX, "/",
|
| | | _name,
|
| | | PREFAB_EXTERSION);
|
| | |
|
| | | window = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
| | | #endif
|
| | | }
|
| | | else
|
| | | {
|
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name);
|
| | | var bundleName = isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX.ToLower() : ResourcesPath.UI_WINDOW_SUFFIX.ToLower();
|
| | | var assetInfo = new AssetInfo(bundleName, _name);
|
| | |
|
| | | window = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject;
|
| | | }
|
| | |
|
| | | if (window == null)
|
| | | {
|
| | | DebugEx.LogErrorFormat("UILoader.LoadWindow() => 加载不到资源: {0}.", _name);
|
| | | }
|
| | |
|
| | | return window;
|
| | | }
|
| | |
|
| | | public static void LoadWindowAsync(string _name, Action<bool, UnityEngine.Object> _callBack)
|
| | | {
|
| | | GameObject window = null;
|
| | | if (AssetSource.uiFromEditor)
|
| | | {
|
| | | #if UNITY_EDITOR
|
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name);
|
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
| | | isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX : ResourcesPath.UI_WINDOW_SUFFIX, "/",
|
| | | _name,
|
| | | PREFAB_EXTERSION);
|
| | |
|
| | | window = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
| | | if (_callBack != null)
|
| | | {
|
| | | _callBack(window != null, window);
|
| | | }
|
| | | #endif
|
| | | }
|
| | | else
|
| | | {
|
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name);
|
| | | var bundleName = isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX.ToLower() : ResourcesPath.UI_WINDOW_SUFFIX.ToLower();
|
| | | var assetInfo = new AssetInfo(bundleName, _name);
|
| | |
|
| | | AssetBundleUtility.Instance.Co_LoadAsset(assetInfo, _callBack);
|
| | | }
|
| | | }
|
| | |
|
| | | public static void UnLoadWindowAsset(string _assetName)
|
| | | {
|
| | | if (!AssetSource.uiFromEditor)
|
| | | {
|
| | | var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_assetName);
|
| | | var bundleName = isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX.ToLower() : ResourcesPath.UI_WINDOW_SUFFIX.ToLower();
|
| | |
|
| | | AssetBundleUtility.Instance.UnloadAsset(bundleName, _assetName);
|
| | | }
|
| | | }
|
| | |
|
| | | public static GameObject LoadPrefab(string _name)
|
| | | {
|
| | | GameObject prefab = null;
|
| | | if (AssetSource.uiFromEditor)
|
| | | {
|
| | | #if UNITY_EDITOR
|
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
| | | ResourcesPath.UI_PREFAB_SUFFIX, "/",
|
| | | _name,
|
| | | PREFAB_EXTERSION);
|
| | |
|
| | | prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
| | | #endif
|
| | | }
|
| | | else
|
| | | {
|
| | | var bundleName = ResourcesPath.UI_PREFAB_SUFFIX.ToLower();
|
| | | var assetInfo = new AssetInfo(bundleName, _name);
|
| | |
|
| | | prefab = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject;
|
| | | }
|
| | |
|
| | | if (prefab == null)
|
| | | {
|
| | | DebugEx.LogErrorFormat("UILoader.LoadPrefab() => 加载不到资源: {0}.", _name);
|
| | | }
|
| | |
|
| | | return prefab;
|
| | | }
|
| | |
|
| | | public static void UnLoadPrefab(string _assetName)
|
| | | {
|
| | | if (!AssetSource.uiFromEditor)
|
| | | {
|
| | | AssetBundleUtility.Instance.UnloadAsset("ui/prefab", _assetName);
|
| | | }
|
| | | }
|
| | |
|
| | | public static Sprite LoadSprite(string _iconKey)
|
| | | {
|
| | | var iconConfig = Config.Instance.Get<IconConfig>(_iconKey);
|
| | | if (iconConfig == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | return LoadSprite(iconConfig.folder, iconConfig.sprite);
|
| | | }
|
| | |
|
| | | public static Sprite LoadSprite(string _folder, string _file)
|
| | | {
|
| | | var folder = _folder;
|
| | | var file = _file;
|
| | |
|
| | | Sprite sprite = null;
|
| | | if (AssetSource.uiFromEditor)
|
| | | {
|
| | | #if UNITY_EDITOR
|
| | | var relativePath = StringUtility.Contact(folder, "/", file);
|
| | | var rootPath = ResourcesPath.UI_SPRITE_SUFFIX;
|
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
| | | rootPath, "/",
|
| | | relativePath,
|
| | | SPRITE_EXTERSION);
|
| | |
|
| | | sprite = UnityEditor.AssetDatabase.LoadAssetAtPath<Sprite>(path);
|
| | | #endif
|
| | | }
|
| | | else
|
| | | {
|
| | | var bundleName = StringUtility.Contact("ui/sprite/", folder.ToLower());
|
| | | var assetInfo = new AssetInfo(bundleName, file);
|
| | |
|
| | | sprite = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(Sprite)) as Sprite;
|
| | | }
|
| | |
|
| | | if (sprite == null)
|
| | | {
|
| | | DebugEx.LogErrorFormat("UILoader.LoadSprite() => 加载不到资源: {0}.", file);
|
| | | }
|
| | |
|
| | | return sprite;
|
| | | }
|
| | |
|
| | | public static void UnLoadSprite(string _iconKey)
|
| | | {
|
| | | if (!AssetSource.uiFromEditor)
|
| | | {
|
| | | var iconConfig = Config.Instance.Get<IconConfig>(_iconKey);
|
| | | if (iconConfig != null)
|
| | | {
|
| | | var bundleName = StringUtility.Contact("ui/sprite/", iconConfig.folder.ToLower());
|
| | | AssetBundleUtility.Instance.UnloadAsset(bundleName, iconConfig.sprite);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public static Font LoadFont(string _fontName)
|
| | | {
|
| | | Font font = null;
|
| | | if (AssetSource.uiFromEditor)
|
| | | {
|
| | | #if UNITY_EDITOR
|
| | | var rootPath = ResourcesPath.UI_FONT_SUFFIX;
|
| | | var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, rootPath, "/", _fontName, ".ttf");
|
| | | font = UnityEditor.AssetDatabase.LoadAssetAtPath<Font>(path);
|
| | | #endif
|
| | | }
|
| | | else
|
| | | {
|
| | | var assetInfo = new AssetInfo("ui/font", _fontName);
|
| | | font = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(Font)) as Font;
|
| | | }
|
| | |
|
| | | if (font == null)
|
| | | {
|
| | | DebugEx.LogErrorFormat("UILoader.LoadFont() => 加载不到资源: {0}.", _fontName);
|
| | | }
|
| | |
|
| | | return font;
|
| | | }
|
| | |
|
| | | public static void UnLoadFont(string _fontName)
|
| | | {
|
| | | if (!AssetSource.uiFromEditor)
|
| | | {
|
| | | AssetBundleUtility.Instance.UnloadAsset("ui/font", _fontName);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|