LanguageSourceData_Assets.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using UnityEngine;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using Object = UnityEngine.Object;
  6. namespace I2.Loc
  7. {
  8. public partial class LanguageSourceData
  9. {
  10. #region Assets
  11. public void UpdateAssetDictionary()
  12. {
  13. Assets.RemoveAll(x => x == null);
  14. mAssetDictionary = Assets.Distinct()
  15. .GroupBy(o => o.name)
  16. .ToDictionary(g => g.Key, g => g.First());
  17. }
  18. public Object FindAsset( string Name )
  19. {
  20. if (Assets!=null)
  21. {
  22. if (mAssetDictionary==null || mAssetDictionary.Count!=Assets.Count)
  23. {
  24. UpdateAssetDictionary();
  25. }
  26. Object obj;
  27. if (mAssetDictionary.TryGetValue(Name, out obj))
  28. {
  29. return obj;
  30. }
  31. //for (int i=0, imax=Assets.Length; i<imax; ++i)
  32. // if (Assets[i]!=null && Name.EndsWith( Assets[i].name, StringComparison.OrdinalIgnoreCase))
  33. // return Assets[i];
  34. }
  35. return null;
  36. }
  37. public bool HasAsset( Object Obj )
  38. {
  39. return Assets.Contains(Obj);
  40. }
  41. public void AddAsset( Object Obj )
  42. {
  43. if (Assets.Contains(Obj))
  44. return;
  45. Assets.Add(Obj);
  46. UpdateAssetDictionary();
  47. }
  48. #endregion
  49. }
  50. }