UIEditor.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. using CommonLang;
  2. using CommonLang.IO;
  3. using CommonLang.Log;
  4. using CommonLang.Xml;
  5. using CommonUI.Data;
  6. using CommonUnity3D.UGUI;
  7. using CommonUnity3D.UGUIEditor.UI;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Xml;
  11. using UnityEngine;
  12. using AbstractLoader = CommonUI.Loader.AbstractLoader;
  13. using UnityImage = CommonUI_Unity3D.Impl.UnityImage;
  14. using UnityDriver = CommonUI_Unity3D.Impl.UnityDriver;
  15. using CommonUI.Display.Text;
  16. namespace CommonUnity3D.UGUIEditor
  17. {
  18. public class UIEditor : UIFactory
  19. {
  20. #region _全局设置_
  21. public static bool GlobalUseBitmapText { get; set; }
  22. #endregion
  23. //------------------------------------------------------------------------------------------------
  24. public delegate UIComponent UIComponentCreater(UIComponentMeta meta);
  25. public sealed class Decoder
  26. {
  27. public UIEditor editor {get;private set; }
  28. public UIComponentCreater creater { get; private set; }
  29. internal Decoder(UIEditor e, UIComponentCreater r)
  30. {
  31. this.editor = e;
  32. this.creater = r;
  33. }
  34. public UIComponent CreateFromFile(string path)
  35. {
  36. return editor.CreateFromFile(path, this);
  37. }
  38. public UIComponent CreateFromMeta(UIComponentMeta meta)
  39. {
  40. return editor.CreateFromMeta(meta, this);
  41. }
  42. public UILayout CreateLayout(UILayoutMeta e)
  43. {
  44. return editor.CreateLayout(e);
  45. }
  46. public UnityEngine.Font CreateFont(string fontName)
  47. {
  48. return editor.CreateFont(fontName);
  49. }
  50. }
  51. //------------------------------------------------------------------------------------------------
  52. private readonly CommonLang.Log.Logger log;
  53. protected HashMap<string, AbstractLoader> mImageMap = new HashMap<string, AbstractLoader>();
  54. protected HashMap<string, UIComponentMeta> mMetaMap = new HashMap<string, UIComponentMeta>();
  55. public string ResRoot { get; private set; }
  56. public string Root { get; private set; }
  57. public UIEditor(string root)
  58. {
  59. if (!root.EndsWith("/")) { root += "/"; }
  60. this.Root = root;
  61. this.ResRoot = root + "res/";
  62. this.log = LoggerFactory.GetLogger("UIEditor");
  63. switch (Application.platform)
  64. {
  65. case RuntimePlatform.WindowsEditor:
  66. case RuntimePlatform.WindowsPlayer:
  67. case RuntimePlatform.WindowsWebPlayer:
  68. break;
  69. case RuntimePlatform.WP8Player:
  70. UnityDriver.UnityInstance.RedirectImage = this.RedirectImage_DXT;
  71. break;
  72. case RuntimePlatform.Android:
  73. UnityDriver.UnityInstance.RedirectImage = this.RedirectImage_ETC;
  74. break;
  75. case RuntimePlatform.IPhonePlayer:
  76. UnityDriver.UnityInstance.RedirectImage = this.RedirectImage_PVR;
  77. break;
  78. }
  79. }
  80. protected virtual UIComponent CreateComponent(UIComponentMeta meta)
  81. {
  82. switch (meta.ClassName)
  83. {
  84. case UIEditorMeta.UERoot_ClassName:
  85. return new UERoot();
  86. case UIEditorMeta.UEButton_ClassName:
  87. return new UETextButton();
  88. case UIEditorMeta.UEToggleButton_ClassName:
  89. return new UEToggleButton();
  90. case UIEditorMeta.UEImageBox_ClassName:
  91. return new UEImageBox();
  92. case UIEditorMeta.UECheckBox_ClassName:
  93. return new UECheckBox();
  94. case UIEditorMeta.UELabel_ClassName:
  95. return new UELabel();
  96. case UIEditorMeta.UECanvas_ClassName:
  97. return new UECanvas();
  98. case UIEditorMeta.UEGauge_ClassName:
  99. return new UEGauge();
  100. case UIEditorMeta.UEFileNode_ClassName:
  101. return new UEFileNode();
  102. case UIEditorMeta.UEScrollPan_ClassName:
  103. return new UEScrollPan();
  104. case UIEditorMeta.UETextInput_ClassName:
  105. return new UETextInput();
  106. case UIEditorMeta.UETextInputMultiline_ClassName:
  107. return new UETextInputMultiline();
  108. case UIEditorMeta.UETextBox_ClassName:
  109. return new UETextBox();
  110. case UIEditorMeta.UETextBoxHtml_ClassName:
  111. return new UETextBoxHtml();
  112. default:
  113. return new UECanvas();
  114. }
  115. }
  116. protected virtual UIComponent CreateFromFile(string path, Decoder decoder)
  117. {
  118. UIComponentMeta meta = AddMeta(Root + FormatSubPath(path));
  119. if (meta != null)
  120. {
  121. UIComponent ui = CreateFromMeta(meta, decoder);
  122. if (ui != null)
  123. {
  124. ui.Name = path;
  125. }
  126. return ui;
  127. }
  128. return null;
  129. }
  130. protected virtual UIComponent CreateFromMeta(UIComponentMeta meta, Decoder decoder)
  131. {
  132. UIComponent ui = null;
  133. if (decoder.creater != null)
  134. {
  135. ui = decoder.creater(meta);
  136. }
  137. if (ui == null)
  138. {
  139. ui = CreateComponent(meta);
  140. }
  141. if (ui != null)
  142. {
  143. ui.DecodeFromXML(decoder, meta);
  144. }
  145. return ui;
  146. }
  147. /// <summary>
  148. /// 从路径加载UI界面
  149. /// </summary>
  150. /// <param name="path"></param>
  151. /// <param name="creater">自定义构建UI节点代理</param>
  152. /// <returns></returns>
  153. public virtual UIComponent CreateFromFile(string path, UIComponentCreater creater = null)
  154. {
  155. return CreateFromFile(path, new Decoder(this, creater));
  156. }
  157. /// <summary>
  158. /// 从元数据加载UI界面
  159. /// </summary>
  160. /// <param name="meta"></param>
  161. /// <param name="creater">自定义构建UI节点代理</param>
  162. /// <returns></returns>
  163. public virtual UIComponent CreateFromMeta(UIComponentMeta meta, UIComponentCreater creater = null)
  164. {
  165. return CreateFromMeta(meta, new Decoder(this, creater));
  166. }
  167. public virtual UILayout CreateLayout(UILayoutMeta e)
  168. {
  169. if (e == null) return null;
  170. UILayout layout = new UILayout();
  171. layout.DecodeFromXML(this, e);
  172. return layout;
  173. }
  174. public virtual UnityEngine.Font CreateFont(string fontName)
  175. {
  176. return DefaultFont;
  177. }
  178. //-------------------------------------------------------------------------------------------------------------------------------
  179. /// <summary>
  180. /// 从字符串格式获取图片字
  181. /// </summary>
  182. /// <param name="image_font">"^number/output/number.xml|Texts"</param>
  183. /// <param name="text"></param>
  184. /// <returns></returns>
  185. public UGUI.ImageFontSprite ParseImageFont(string image_font, string text)
  186. {
  187. if (image_font.StartsWith("^"))
  188. {
  189. image_font = image_font.Substring(1);
  190. string[] args = image_font.Split('|');
  191. string a_name = args[0];
  192. string a_tg = args[1];
  193. CommonUI.Cell.CPJAtlas mAtlas = this.GetAtlas(a_name, a_tg);
  194. if (mAtlas != null)
  195. {
  196. UGUI.ImageFontSprite ret = new UGUI.ImageFontSprite(image_font);
  197. ret.Text = text;
  198. ret.SetAtlas(mAtlas);
  199. return ret;
  200. }
  201. }
  202. return null;
  203. }
  204. /// <summary>
  205. /// 从字符串格式获取图片字
  206. /// </summary>
  207. /// <param name="image_font">"^number/output/number.xml|Texts"</param>
  208. /// <param name="text"></param>
  209. /// <param name="imageFont"></param>
  210. /// <returns></returns>
  211. public bool ParseImageFont(string image_font, string text, ImageFontGraphics imageFont)
  212. {
  213. if (image_font.StartsWith("^"))
  214. {
  215. image_font = image_font.Substring(1);
  216. string[] args = image_font.Split('|');
  217. string a_name = args[0];
  218. string a_tg = args[1];
  219. CommonUI.Cell.CPJAtlas mAtlas = this.GetAtlas(a_name, a_tg);
  220. if (mAtlas != null)
  221. {
  222. imageFont.Text = text;
  223. imageFont.Atlas = (mAtlas);
  224. return true;
  225. }
  226. }
  227. return false;
  228. }
  229. /// <summary>
  230. /// 从字符串格式获取图片精灵
  231. /// </summary>
  232. /// <param name="atlas_name">"#dynamic/effects/skill/skilllevelup.xml|skill_levelup1|21"</param>
  233. /// <param name="pivot"></param>
  234. /// <returns></returns>
  235. public UGUI.ImageSprite ParseImageSpriteFromAtlas(string atlas_name, Vector2 pivot)
  236. {
  237. if (atlas_name.StartsWith("#"))
  238. {
  239. CommonUI.Gemo.Rectangle2D region;
  240. CommonUI_Unity3D.Impl.UnityImage src = ParseAtlasTile(atlas_name, out region);
  241. if (src != null)
  242. {
  243. var ret = new UGUI.ImageSprite(atlas_name);
  244. ret.SetImage(src, new Rect(region.x, region.y, region.width, region.height), pivot);
  245. ret.mTransform.sizeDelta = new Vector2(region.width, region.height);
  246. return ret;
  247. }
  248. }
  249. return null;
  250. }
  251. /// <summary>
  252. /// 从字符串格式获取图片精灵
  253. /// </summary>
  254. /// <param name="image_name">"static/off_down.png"</param>
  255. /// <param name="pivot"></param>
  256. /// <returns></returns>
  257. public UGUI.ImageSprite ParseImageSpriteFromImage(string image_name, Vector2 pivot)
  258. {
  259. if (!string.IsNullOrEmpty(image_name))
  260. {
  261. CommonUI_Unity3D.Impl.UnityImage src = GetImage(image_name);
  262. if (src != null)
  263. {
  264. var ret = new UGUI.ImageSprite(image_name);
  265. ret.SetImage(src, new Rect(0, 0, src.Width, src.Height), pivot);
  266. ret.mTransform.sizeDelta = new Vector2(src.Width, src.Height);
  267. return ret;
  268. }
  269. }
  270. return null;
  271. }
  272. /// <summary>
  273. /// 从字符串格式获取图集
  274. /// </summary>
  275. /// <param name="atlas_name">"#dynamic/effects/skill/skilllevelup.xml|skill_levelup1|21"</param>
  276. /// <param name="outRegion"></param>
  277. /// <returns></returns>
  278. public CommonUI_Unity3D.Impl.UnityImage ParseAtlasTile(string atlas_name, out CommonUI.Gemo.Rectangle2D outRegion)
  279. {
  280. if (atlas_name.StartsWith("#"))
  281. {
  282. atlas_name = atlas_name.Substring(1);
  283. string[] args = atlas_name.Split('|');
  284. string a_name = args[0];
  285. string a_tg = args[1];
  286. int mAtlasTileID = int.Parse(args[2]);
  287. CommonUI.Cell.CPJAtlas mAtlas = this.GetAtlas(a_name, a_tg);
  288. if (mAtlas != null)
  289. {
  290. CommonUI_Unity3D.Impl.UnityImage outImage = mAtlas.GetTile(mAtlasTileID) as UnityImage;
  291. if (outImage != null)
  292. {
  293. outRegion = mAtlas.GetAtlasRegion(mAtlasTileID);
  294. return outImage;
  295. }
  296. }
  297. }
  298. outRegion = null;
  299. return null;
  300. }
  301. /// <summary>
  302. /// 从字符串格式获取图集
  303. /// </summary>
  304. /// <param name="atlas_name">"#dynamic/effects/skill/skilllevelup.xml|skill_levelup1|21"</param>
  305. /// <param name="pivot"></param>
  306. /// <returns></returns>
  307. public UnityEngine.Sprite ParseAtlasTile(string atlas_name, Vector2 pivot)
  308. {
  309. if (atlas_name.StartsWith("#"))
  310. {
  311. atlas_name = atlas_name.Substring(1);
  312. string[] args = atlas_name.Split('|');
  313. string a_name = args[0];
  314. string a_tg = args[1];
  315. int mAtlasTileID = int.Parse(args[2]);
  316. CommonUI.Cell.CPJAtlas mAtlas = this.GetAtlas(a_name, a_tg);
  317. if (mAtlas != null)
  318. {
  319. CommonUI_Unity3D.Impl.UnityImage src = mAtlas.GetTile(mAtlasTileID) as UnityImage;
  320. if (src != null)
  321. {
  322. CommonUI.Gemo.Rectangle2D clip = mAtlas.GetAtlasRegion(mAtlasTileID);
  323. return UIUtils.CreateSprite(src, new Rect(clip.x, clip.y, clip.width, clip.height), pivot);
  324. }
  325. }
  326. }
  327. return null;
  328. }
  329. /// <summary>
  330. /// 从字符串格式获取精灵
  331. /// </summary>
  332. /// <param name="spr_name">"@actor_001010/output/actor.xml|actor_001010|001010|3"</param>
  333. /// <param name="animIndex"></param>
  334. /// <returns></returns>
  335. public CommonUI.Cell.Game.CSpriteMeta ParseSpriteMeta(string spr_name, out int animIndex)
  336. {
  337. if (spr_name.StartsWith("@"))
  338. {
  339. spr_name = spr_name.Substring(1);
  340. string[] args = spr_name.Split('|');
  341. if (args.Length >= 4)
  342. {
  343. string a_xml_name = args[0];
  344. string a_img_name = args[1];
  345. string a_spr_name = args[2];
  346. animIndex = int.Parse(args[3]);
  347. CommonUI.Cell.CPJResource cpj_res = GetCPJResource(a_xml_name);
  348. if (cpj_res != null)
  349. {
  350. CommonUI.Cell.Game.CSpriteMeta spr_meta = cpj_res.GetSpriteMeta(a_spr_name);
  351. return spr_meta;
  352. }
  353. }
  354. }
  355. animIndex = 0;
  356. return null;
  357. }
  358. //-------------------------------------------------------------------------------------------------------------------------------
  359. /// <summary>
  360. /// 获取 UI XML 对应的单张图片
  361. /// </summary>
  362. /// <param name="image_file_name"></param>
  363. /// <returns></returns>
  364. public CommonUI_Unity3D.Impl.UnityImage GetImage(string image_file_name)
  365. {
  366. string full_path = ResRoot + FormatSubPath(image_file_name);
  367. var img = AddImage(full_path);
  368. return img;
  369. }
  370. /// <summary>
  371. /// 获取 UI XML 对应的CPJ的图集
  372. /// </summary>
  373. /// <param name="cpj_file_name"></param>
  374. /// <param name="atlas_name"></param>
  375. /// <returns></returns>
  376. public CommonUI.Cell.CPJAtlas GetAtlas(string cpj_file_name, string atlas_name)
  377. {
  378. var cpj = GetCPJResource(cpj_file_name);
  379. if (cpj != null)
  380. {
  381. return cpj.GetAtlas(atlas_name);
  382. }
  383. return null;
  384. }
  385. /// <summary>
  386. /// 获取 CPJ 资源
  387. /// </summary>
  388. /// <param name="cpj_file_name"></param>
  389. /// <returns></returns>
  390. public CommonUI.Cell.CPJResource GetCPJResource(string cpj_file_name)
  391. {
  392. string full_path = ResRoot + FormatSubPath(cpj_file_name);
  393. var cpj = AddAtlas(full_path);
  394. return cpj;
  395. }
  396. public CommonUI.Cell.Game.CSpriteMeta GetSpriteMeta(string cpj_file_name, string spr_name)
  397. {
  398. CommonUI.Cell.CPJResource cpj_res = GetCPJResource(cpj_file_name);
  399. if (cpj_res != null)
  400. {
  401. CommonUI.Cell.Game.CSpriteMeta spr_meta = cpj_res.GetSpriteMeta(spr_name);
  402. return spr_meta;
  403. }
  404. return null;
  405. }
  406. public virtual UIComponentMeta GetUIMeta(string path)
  407. {
  408. return AddMeta(Root + FormatSubPath(path));
  409. }
  410. //-------------------------------------------------------------------------------------------------------------------------------
  411. #region _富文本_
  412. public override UGUIRichTextLayer CreateRichTextLayer(DisplayNode parent, bool use_bitmap)
  413. {
  414. return new EditorRichTextLayer(this, parent, use_bitmap);
  415. }
  416. public class EditorRichTextLayer : UGUIRichTextLayer
  417. {
  418. private readonly UIEditor mEditor;
  419. public EditorRichTextLayer(UIEditor editor, DisplayNode parent, bool use_bitmap_font)
  420. : base(parent, use_bitmap_font)
  421. {
  422. this.mEditor = editor;
  423. }
  424. protected override CommonUI.Display.Image AddImage(string file)
  425. {
  426. CommonUI.Display.Image ret = mEditor.GetImage(file);
  427. if (ret == null)
  428. {
  429. ret = base.AddImage(file);
  430. }
  431. return ret;
  432. }
  433. protected override CommonUI.Cell.CPJResource AddCPJResource(string file)
  434. {
  435. var ret = mEditor.GetCPJResource(file);
  436. if (ret == null)
  437. {
  438. ret = base.AddCPJResource(file);
  439. }
  440. return ret;
  441. }
  442. }
  443. #endregion
  444. //-------------------------------------------------------------------------------------------------------------------------------
  445. #region _图片缓冲_
  446. protected virtual string RedirectImage_ETC(string path)
  447. {
  448. string etc = path.Substring(0, path.LastIndexOf('.')) + ".etc.m3z";
  449. if (Resource.ExistData(etc))
  450. {
  451. return etc;
  452. }
  453. return path;
  454. }
  455. protected virtual string RedirectImage_PVR(string path)
  456. {
  457. string pvr = path.Substring(0, path.LastIndexOf('.')) + ".pvr.m3z";
  458. if (Resource.ExistData(pvr))
  459. {
  460. return pvr;
  461. }
  462. return path;
  463. }
  464. protected virtual string RedirectImage_DXT(string path)
  465. {
  466. string dxt = path.Substring(0, path.LastIndexOf('.')) + ".dxt.m3z";
  467. if (Resource.ExistData(dxt))
  468. {
  469. return dxt;
  470. }
  471. return path;
  472. }
  473. /// <summary>
  474. /// 格式化完整路劲
  475. /// </summary>
  476. /// <param name="path"></param>
  477. /// <returns></returns>
  478. protected virtual string FormatPath(string path)
  479. {
  480. path = path.Replace('\\', '/');
  481. return path;
  482. }
  483. /// <summary>
  484. /// 格式化子路劲
  485. /// </summary>
  486. /// <param name="sub_path"></param>
  487. /// <returns></returns>
  488. protected virtual string FormatSubPath(string sub_path)
  489. {
  490. if (sub_path.StartsWith("/"))
  491. {
  492. return sub_path.Substring(1);
  493. }
  494. return sub_path;
  495. }
  496. /// <summary>
  497. /// 添加XML和二进制映射
  498. /// </summary>
  499. /// <param name="path"></param>
  500. /// <returns></returns>
  501. protected virtual UIComponentMeta AddMeta(string path)
  502. {
  503. UIComponentMeta ret = null;
  504. try
  505. {
  506. path = FormatPath(path);
  507. if (!mMetaMap.TryGetValue(path, out ret))
  508. {
  509. string bin_path = path.Substring(0, path.LastIndexOf(".gui.xml")) + ".gui.bin";
  510. // 临时写法 UI全部翻皮完成之后去掉 add by haog 2017-2-6
  511. string strTemp = bin_path;
  512. bin_path = bin_path.Replace("xml/", "xmds_ui/");// 先从新的目录读取 读取不到再去老的目录查找
  513. if (!Resource.ExistData(bin_path))
  514. {
  515. bin_path = strTemp;
  516. }
  517. // 临时写法 end
  518. if (Resource.ExistData(bin_path))
  519. {
  520. var input = Resource.LoadDataAsStream(bin_path);
  521. if (input == null) { return null; }
  522. try
  523. {
  524. ret = UIEditorMeta.CreateFromStream(input);
  525. if (ret != null)
  526. {
  527. mMetaMap.Put(path, ret);
  528. return ret;
  529. }
  530. }
  531. finally
  532. {
  533. input.Dispose();
  534. }
  535. }
  536. // 临时写法 UI全部翻皮完成之后去掉 add by haog 2017-2-6
  537. strTemp = path;
  538. path = path.Replace("xml/", "xmds_ui/");// 先从新的目录读取 读取不到再去老的目录查找
  539. XmlDocument xml = XmlUtil.LoadXML(path);
  540. if (xml == null)
  541. {
  542. path = strTemp;
  543. }
  544. // 临时写法 end
  545. xml = XmlUtil.LoadXML(path);
  546. if (xml != null)
  547. {
  548. ret = UIEditorMeta.CreateFromXml(xml);
  549. if (ret != null)
  550. {
  551. mMetaMap.Put(path, ret);
  552. return ret;
  553. }
  554. }
  555. }
  556. }
  557. catch (Exception err)
  558. {
  559. log.Error(err.Message, err);
  560. }
  561. return ret;
  562. }
  563. /// <summary>
  564. /// 清理XML二进制映射
  565. /// </summary>
  566. public virtual void CleanMetaMap()
  567. {
  568. mMetaMap.Clear();
  569. }
  570. protected virtual UnityImage AddImage(string path)
  571. {
  572. try
  573. {
  574. path = FormatPath(path);
  575. AbstractLoader temp = null;
  576. if (!mImageMap.TryGetValue(path, out temp))
  577. {
  578. temp = new CommonUI.Editor.ImageLoader(path);
  579. mImageMap.Put(path, temp);
  580. }
  581. return temp.GetImage(path) as UnityImage;
  582. }
  583. catch (Exception err)
  584. {
  585. log.Error(err.Message, err);
  586. }
  587. return null;
  588. }
  589. protected virtual CommonUI.Cell.CPJResource AddAtlas(string path)
  590. {
  591. try
  592. {
  593. path = FormatPath(path);
  594. AbstractLoader temp = null;
  595. if (!mImageMap.TryGetValue(path, out temp))
  596. {
  597. temp = new CommonUI.Loader.AtlasLoader(path);
  598. mImageMap.Put(path, temp);
  599. }
  600. return temp.GetAtlasResource(path);
  601. }
  602. catch (Exception err)
  603. {
  604. log.Error(err.Message, err);
  605. }
  606. return null;
  607. }
  608. /// <summary>
  609. /// 清理缓存的图片
  610. /// </summary>
  611. public virtual void CleanImageMap()
  612. {
  613. foreach (KeyValuePair<string, AbstractLoader> kvp in mImageMap)
  614. {
  615. kvp.Value.Dispose();
  616. }
  617. mImageMap.Clear();
  618. }
  619. /// <summary>
  620. /// 释放ui中标记为支持释放(默认)的UnityImage中的指定路径的Texture
  621. /// 当重新被使用时会自动重新加载
  622. /// </summary>
  623. public void ReleaseTexture(string path)
  624. {
  625. if (string.IsNullOrEmpty(path))
  626. return;
  627. string full_path = ResRoot + FormatSubPath(path);
  628. full_path = FormatPath(full_path);
  629. AbstractLoader temp;
  630. if (mImageMap.TryGetValue(full_path, out temp))
  631. {
  632. temp.ReleaseTexture();
  633. }
  634. }
  635. /// <summary>
  636. /// 释放ui中标记为支持释放(默认)的UnityImage中的Texture
  637. /// 当重新被使用时会自动重新加载
  638. /// </summary>
  639. public void ReleaseAllTexture()
  640. {
  641. foreach (var item in mImageMap)
  642. {
  643. item.Value.ReleaseTexture();
  644. }
  645. }
  646. #endregion
  647. }
  648. }