1
This commit is contained in:
86
Assets/Artists/Scripts/Props/Prop_Modify.cs
Normal file
86
Assets/Artists/Scripts/Props/Prop_Modify.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
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<Prop_ModifyObject>();
|
||||
private Prop_ModifyObject[] _modifies = Array.Empty<Prop_ModifyObject>();
|
||||
private void Start()
|
||||
{
|
||||
_modifies = GetComponentsInChildren<Prop_ModifyObject>(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<IBasicItem>(out var item) is false || item.TryGetProperty<IModifyManager>(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<Prop_ModifyObject>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user