LanguageSourceData_Assets.cs 1.3 KB

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