1
This commit is contained in:
@@ -15,18 +15,27 @@ namespace BITFALL.Cosmetic
|
||||
public struct CosmeticServiceSingleton:ICosmeticService
|
||||
{
|
||||
public ICosmetic[] Cosmetics=>CosmeticService.Singleton.Cosmetics;
|
||||
public event Action OnCosmeticsChange
|
||||
{
|
||||
add => CosmeticService.Singleton.OnCosmeticsChange += value;
|
||||
remove => CosmeticService.Singleton.OnCosmeticsChange -= value;
|
||||
}
|
||||
|
||||
public event Action OnCosmeticsChanged
|
||||
{
|
||||
add => CosmeticService.Singleton.OnCosmeticsChanged += value;
|
||||
remove => CosmeticService.Singleton.OnCosmeticsChanged -= value;
|
||||
}
|
||||
|
||||
public void SetDirty()=>CosmeticService.Singleton.SetDirty();
|
||||
|
||||
public IDictionary<IModifyElement, object> Modifies => CosmeticService.Singleton.Modifies;
|
||||
public IDictionary<IModifyElement, object> Modified => CosmeticService.Singleton.Modified;
|
||||
public void Add(IModifyElement modify, object obj)=>CosmeticService.Singleton.Add(modify,obj);
|
||||
|
||||
public void Remove(IModifyElement modify, out object obj)=>CosmeticService.Singleton.Remove(modify,out obj);
|
||||
}
|
||||
[DisallowMultipleComponent]
|
||||
public class CosmeticService : MonoBehaviour,ICosmeticService
|
||||
{
|
||||
[DictionaryReferenceConfig(nameof(Cosmetic_Saved_Layout))]
|
||||
@@ -35,7 +44,8 @@ namespace BITFALL.Cosmetic
|
||||
|
||||
[SerializeField] private AssetableCosmetic[] initialCosmetics;
|
||||
public ICosmetic[] Cosmetics { get; set; } = Array.Empty<ICosmetic>();
|
||||
|
||||
public event Action OnCosmeticsChange;
|
||||
|
||||
public event Action OnCosmeticsChanged;
|
||||
|
||||
private void Awake()
|
||||
@@ -68,14 +78,13 @@ namespace BITFALL.Cosmetic
|
||||
}
|
||||
}
|
||||
|
||||
OnCosmeticsChanged?.Invoke();
|
||||
|
||||
destroyCancellationToken.Register(() =>
|
||||
{
|
||||
var array = _modifyManager.Modified.Values.Select(x => x.As<ICosmetic>().AddressablePath).ToArray();
|
||||
PlayerPrefs.SetString(Cosmetic_Saved_Layout, JsonConvert.SerializeObject(array));
|
||||
PlayerPrefs.Save();
|
||||
});
|
||||
SetDirty();
|
||||
}
|
||||
|
||||
private readonly IModifyManager _modifyManager = new ModifyManager();
|
||||
@@ -89,13 +98,30 @@ namespace BITFALL.Cosmetic
|
||||
Modified.Remove(modify);
|
||||
}
|
||||
_modifyManager.Add(modify, obj);
|
||||
OnCosmeticsChanged?.Invoke();
|
||||
|
||||
SetDirty();
|
||||
}
|
||||
public void Remove(IModifyElement modify, out object obj)
|
||||
{
|
||||
_modifyManager.Remove(modify, out obj);
|
||||
OnCosmeticsChanged?.Invoke();
|
||||
SetDirty();
|
||||
}
|
||||
public async void SetDirty()
|
||||
{
|
||||
try
|
||||
{
|
||||
OnCosmeticsChange?.Invoke();
|
||||
await UniTask.NextFrame();
|
||||
await UniTask.SwitchToMainThread();
|
||||
if (destroyCancellationToken.IsCancellationRequested) return;
|
||||
OnCosmeticsChanged?.Invoke();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user