1
This commit is contained in:
61
Assets/Artists/Scripts/CosmeticInventory/CosmeticService.cs
Normal file
61
Assets/Artists/Scripts/CosmeticInventory/CosmeticService.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITKit.Modification;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Cosmetic
|
||||
{
|
||||
[Serializable]
|
||||
public struct CosmeticServiceSingleton:ICosmeticService
|
||||
{
|
||||
public ICosmetic[] Cosmetics=>CosmeticService.Singleton.Cosmetics;
|
||||
public event Action OnCosmeticsChanged
|
||||
{
|
||||
add => CosmeticService.Singleton.OnCosmeticsChanged += value;
|
||||
remove => CosmeticService.Singleton.OnCosmeticsChanged -= value;
|
||||
}
|
||||
|
||||
public IDictionary<IModifyElement, object> Modifies { get; set; }
|
||||
public IDictionary<IModifyElement, object> Modified { get; set; }
|
||||
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);
|
||||
}
|
||||
public class CosmeticService : MonoBehaviour,ICosmeticService
|
||||
{
|
||||
internal static ICosmeticService Singleton { get; private set; }
|
||||
|
||||
[SerializeField] private AssetableCosmetic[] initialCosmetics;
|
||||
public ICosmetic[] Cosmetics { get; set; } = Array.Empty<ICosmetic>();
|
||||
|
||||
public event Action OnCosmeticsChanged;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Singleton = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Cosmetics = initialCosmetics.OfType<ICosmetic>().ToArray();
|
||||
OnCosmeticsChanged?.Invoke();
|
||||
}
|
||||
private readonly IModifyManager _modifyManager = new ModifyManager();
|
||||
public IDictionary<IModifyElement, object> Modifies => _modifyManager.Modifies;
|
||||
public IDictionary<IModifyElement, object> Modified => _modifyManager.Modified;
|
||||
|
||||
public void Add(IModifyElement modify, object obj)
|
||||
{
|
||||
_modifyManager.Add(modify, obj);
|
||||
OnCosmeticsChanged?.Invoke();
|
||||
}
|
||||
public void Remove(IModifyElement modify, out object obj)
|
||||
{
|
||||
_modifyManager.Remove(modify, out obj);
|
||||
OnCosmeticsChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user