using System; using System.Collections; using System.Collections.Generic; using System.Linq; using BITFALL.Guns.Modify; using BITKit; using BITKit.Modification; using UnityEngine; namespace BITFALL.Props { public class Prop_Modify : MonoBehaviour { private readonly ValidHandle _allowModify = new(); public IValidHandle AllowModify => _allowModify; private Prop_ModifyObject[] _modified = Array.Empty(); private Prop_ModifyObject[] _modifies = Array.Empty(); private void Start() { _modifies = GetComponentsInChildren(true); _allowModify.AddListener(OnAllowModify); _allowModify.AddElement(this); Modify(); } private void OnAllowModify(bool obj) { foreach (var x in _modifies) { EnabledModify(x, false); } if (!obj) return; foreach (var x in _modified) { EnabledModify(x, true); } } [BIT] private void Modify() { Modify(null); OnAllowModify(true); } public void Modify(IModifyManager modify) { ClearModify(); if (modify is null) { if (TryGetComponent(out var item) is false || item.TryGetProperty(out modify) is false) { return; } } var _newModified = modify.Modified.Values; _modified = _modifies.Where(x=>_newModified.Contains(x.scriptableObject)).ToArray(); _allowModify.Invoke(); } [BIT] public void ClearModify() { foreach (var x in GetComponentsInChildren(true)) { EnabledModify(x,false); } } private void EnabledModify(Prop_ModifyObject modifyObject, bool isModify) { foreach (var obj in modifyObject.originalObjects) { if (obj) obj.gameObject.SetActive(!isModify); } foreach (var obj in modifyObject.modifyObjects) { if (obj) obj.gameObject.SetActive(isModify); } } } }