Files
Continentis/Assets/OtherPlugins/I2/Localization/Scripts/LanguageSource/LanguageSourceData_Assets.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2026-03-20 11:56:50 -04:00
using System;
2025-10-03 00:02:43 -04:00
using System.Linq;
2026-03-20 11:56:50 -04:00
using Object = UnityEngine.Object;
2025-10-03 00:02:43 -04:00
namespace I2.Loc
{
2026-03-20 11:56:50 -04:00
public partial class LanguageSourceData
{
2025-10-03 00:02:43 -04:00
#region Assets
public void UpdateAssetDictionary()
{
Assets.RemoveAll(x => x == null);
mAssetDictionary = Assets.Distinct()
2026-03-20 11:56:50 -04:00
.GroupBy(o => o.name, StringComparer.Ordinal)
.ToDictionary(g => g.Key, g => g.First(), StringComparer.Ordinal);
2025-10-03 00:02:43 -04:00
}
2026-03-20 11:56:50 -04:00
public Object FindAsset(string Name)
{
if (Assets != null)
{
if (mAssetDictionary == null || mAssetDictionary.Count != Assets.Count) UpdateAssetDictionary();
2025-10-03 00:02:43 -04:00
Object obj;
2026-03-20 11:56:50 -04:00
if (mAssetDictionary.TryGetValue(Name, out obj)) return obj;
//for (int i=0, imax=Assets.Length; i<imax; ++i)
// if (Assets[i]!=null && Name.EndsWith( Assets[i].name, StringComparison.OrdinalIgnoreCase))
// return Assets[i];
}
return null;
}
public bool HasAsset(Object Obj)
{
return Assets.Contains(Obj);
}
public void AddAsset(Object Obj)
{
2025-10-03 00:02:43 -04:00
if (Assets.Contains(Obj))
return;
Assets.Add(Obj);
UpdateAssetDictionary();
2026-03-20 11:56:50 -04:00
}
2025-10-03 00:02:43 -04:00
2026-03-20 11:56:50 -04:00
#endregion
}
2025-10-03 00:02:43 -04:00
}