HUULCHM5GFGZ7GKLCULFHC333LQ3LBI62VKII3YL5O4C5CDGCT4AC
VPXUP5WZTVC3OVD73TNKPK43IAGFXGUGCEJT56JM4IT4APYQXUHAC
I33Z5QD6JHPO7W7G3EHGBIXQABW6ZOC2W4NJP6L5ENDPFRORUFNAC
O236B5LO6PHJ4TPZGYXDVSLB5EGXXRRLYYVWI46DPL5LEGXEIHZQC
VZRSH4U473FCZOP5EXURPXXN5J6F3ZLT435YY7A2JHLG2ZZB5KLQC
XF52N4U7HWXOF4PDSCR7LCUENLTSXLWEZGS2IJ6562KYI567Z2GAC
CXQW7UICWDJFL3M44O2XVH6JNCRDGRBMPMYR2LEGFJCANPG4YASAC
KAROCU3SAOGWWSFXGCLE5OW76VTDJR4HDIVTK62BIAESN5SOHVDAC
CD5FF75KTOBTMVMTMCKMR6F5DFKOF26I5K43ITNHGBI3ZAZHA4RAC
fileFormatVersion: 2
guid: adbc7a3b7d26f694bba40a280168e7be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using TagFighter.PawnResources;
using UnityEngine;
using UnityEngine.UI;
namespace TagFighter.UI
{
[RequireComponent(typeof(Image))]
public class PawnResourceViewer : MonoBehaviour, IPawnResourceViewer
{
Image fill;
protected void Awake() {
fill = GetComponent<Image>();
}
public void UpdateView(OnChangeArgs e) {
fill.fillAmount = (float)e.Current / e.Capacity;
}
}
}
fileFormatVersion: 2
guid: adbc7a3b7d26f694bba40a280168e7be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using TagFighter.Resources;
using UnityEngine;
using UnityEngine.UI;
namespace TagFighter.UI
{
[RequireComponent(typeof(Image))]
public class ImageFillResourceViewer : MonoBehaviour, IResourceViewer
{
Image fill;
protected void Awake() {
fill = GetComponent<Image>();
}
public void UpdateView(OnChangeArgs e) {
fill.fillAmount = (float)e.Current / e.Capacity;
}
}
}
fileFormatVersion: 2
guid: 94efccc62caea1a4580ab6f122e09ce2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using TagFighter.PawnResources;
using UnityEngine;
namespace TagFighter.UI
{
[RequireComponent(typeof(IPawnResourceViewer))]
public class PawnResourceWatcher : MonoBehaviour
{
IWatchableResource _watchedResource;
IPawnResourceViewer _resourceDisplay;
static readonly OnChangeArgs Default = new(0, 1, 0, 0);
public IWatchableResource WatchedResource {
get => _watchedResource;
set {
if (_watchedResource != null) {
_watchedResource.OnCapacityChanged -= OnCapacityChanged;
_watchedResource.OnCurrentChanged -= OnCurrentChanged;
_watchedResource.OnRegenerationAmountChanged -= OnRegenerationAmountChanged;
}
_watchedResource = value;
OnChangeArgs status = Default;
if (_watchedResource != null) {
_watchedResource.OnCapacityChanged += OnCapacityChanged;
_watchedResource.OnCurrentChanged += OnCurrentChanged;
_watchedResource.OnRegenerationAmountChanged += OnRegenerationAmountChanged;
status = _watchedResource.Status;
}
_resourceDisplay.UpdateView(status);
}
}
protected void Awake() {
_resourceDisplay = GetComponent<IPawnResourceViewer>();
}
protected virtual void OnCapacityChanged(object sender, OnChangeArgs e) {
_resourceDisplay.UpdateView(e);
}
protected virtual void OnCurrentChanged(object sender, OnChangeArgs e) {
_resourceDisplay.UpdateView(e);
}
protected virtual void OnRegenerationAmountChanged(object sender, OnChangeArgs e) {
_resourceDisplay.UpdateView(e);
}
protected void OnDestroy() {
_resourceDisplay = null;
}
}
}
fileFormatVersion: 2
guid: dd2006828ab220e4eafe7e265905282d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: bede5cbc2cf21a3499cd0b5e3a262d95
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using TagFighter.SpendableResources;
using UnityEngine;
namespace TagFighter.PawnResources
{
[Serializable]
public class PawnResource<T> : MonoBehaviour, IWatchableResource where T : ISpendableResource
{
[SerializeField] SpendableResource<T> _current;
[SerializeField] SpendableResource<T> _capacity;
readonly SpendableResource<T> _minimumCapacity = (SpendableResource<T>) 0;
[SerializeField] SpendableResource<T> regenerationAmount;
[Range(0.1f, 10f)] public float RegenerationRate;
public OnChangeArgs Status => (OnChangeArgs)this;
public SpendableResource<T> Capacity {
get => _capacity;
set {
if (Capacity == value) {
return;
}
_capacity = value;
OnCapacityChanged?.Invoke(this, (OnChangeArgs)this);
if (Current < Capacity) {
Current = Capacity;
}
}
}
public SpendableResource<T> Current {
get => _current;
set {
}
}
}
public SpendableResource<T> RegenerationAmount {
get => regenerationAmount;
set {
regenerationAmount = value;
}
}
public event EventHandler<OnChangeArgs> OnCurrentChanged;
public event EventHandler<OnChangeArgs> OnCapacityChanged;
public event EventHandler<OnChangeArgs> OnRegenerationAmountChanged;
public static explicit operator OnChangeArgs(PawnResource<T> resource) {
return new(
resource.RegenerationRate);
}
private IEnumerator Regenerate() {
while (true) {
yield return new WaitForSeconds(RegenerationRate);
Current += RegenerationAmount;
// print($"Regenerated {typeof(T).Name}, value = {Current}");
}
}
protected void Start() {
StartCoroutine(Regenerate());
}
}
}
(int)resource.Current,
(int)resource.Capacity,
(int)resource.RegenerationAmount,
OnRegenerationAmountChanged?.Invoke(this, (OnChangeArgs)this);
var valueToSet = (SpendableResource<T>) Math.Clamp((int)value, (int)_minimumCapacity, (int) Capacity);
if (_current != valueToSet) {
_current = valueToSet;
OnCurrentChanged?.Invoke(this, (OnChangeArgs)this);
fileFormatVersion: 2
guid: b0f1bdcc41f94a746a8a2478bf829888
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
namespace TagFighter.SpendableResources
{
[Serializable]
public struct SpendableResource<T> where T : ISpendableResource
{
[SerializeField] int _value;
private SpendableResource(int value) => _value = value;
public static explicit operator SpendableResource<T>(int value) => new(value);
public static explicit operator int(SpendableResource<T> resource) => resource._value;
public static bool operator ==(SpendableResource<T> a, SpendableResource<T> b) => a._value == b._value;
public static bool operator >(SpendableResource<T> a, SpendableResource<T> b) => a._value > b._value;
public static bool operator <(SpendableResource<T> a, SpendableResource<T> b) => a._value < b._value;
public static bool operator !=(SpendableResource<T> a, SpendableResource<T> b) => !(a == b);
public static bool operator >=(SpendableResource<T> a, SpendableResource<T> b) => !(a < b);
public static bool operator <=(SpendableResource<T> a, SpendableResource<T> b) => !(a > b);
public static SpendableResource<T> operator +(SpendableResource<T> a, SpendableResource<T> b) {
}
public static SpendableResource<T> operator -(SpendableResource<T> a, SpendableResource<T> b) {
}
public static float operator /(SpendableResource<T> a, SpendableResource<T> b) => a._value / (float)b._value;
public static SpendableResource<T> operator /(SpendableResource<T> a, int b) => a / (float)b;
public static SpendableResource<T> operator /(SpendableResource<T> a, float b) {
SpendableResource<T> returnPoints;
if (b == 0) {
returnPoints = (SpendableResource<T>)int.MaxValue;
}
else {
returnPoints = (SpendableResource<T>)(a._value / b);
}
return returnPoints;
}
public override bool Equals(object obj) {
return obj is SpendableResource<T> points &&
_value == points._value;
}
public override int GetHashCode() {
return HashCode.Combine(_value);
}
public override string ToString() => _value.ToString();
}
public interface ISpendableResource { }
public class Pain : ISpendableResource { }
public class Fatigue : ISpendableResource { }
public class Strain : ISpendableResource { }
public class RedTag : ISpendableResource { }
public class BlueTag : ISpendableResource { }
public class GreenTag : ISpendableResource { }
}
return (SpendableResource<T>)(a._value - b._value);
return (SpendableResource<T>)(a._value + b._value);
fileFormatVersion: 2
guid: b0f1bdcc41f94a746a8a2478bf829888
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
namespace TagFighter.Resources
{
[Serializable]
public struct Unit<T> where T : IUnit
{
[SerializeField] int _value;
private Unit(int value) => _value = value;
public static explicit operator Unit<T>(int value) => new(value);
public static explicit operator int(Unit<T> resource) => resource._value;
public static bool operator ==(Unit<T> a, Unit<T> b) => a._value == b._value;
public static bool operator >(Unit<T> a, Unit<T> b) => a._value > b._value;
public static bool operator <(Unit<T> a, Unit<T> b) => a._value < b._value;
public static bool operator !=(Unit<T> a, Unit<T> b) => !(a == b);
public static bool operator >=(Unit<T> a, Unit<T> b) => !(a < b);
public static bool operator <=(Unit<T> a, Unit<T> b) => !(a > b);
public static Unit<T> operator ++(Unit<T> a) {
return (Unit<T>)(++a._value);
}
public static Unit<T> operator --(Unit<T> a) {
return (Unit<T>)(--a._value);
}
public static Unit<T> operator +(Unit<T> a, Unit<T> b) {
return (Unit<T>)(a._value + b._value);
}
public static Unit<T> operator -(Unit<T> a, Unit<T> b) {
return (Unit<T>)(a._value - b._value);
}
public static float operator /(Unit<T> a, Unit<T> b) => a._value / (float)b._value;
public static Unit<T> operator /(Unit<T> a, int b) => a / (float)b;
public static Unit<T> operator /(Unit<T> a, float b) {
Unit<T> returnPoints;
if (b == 0) {
returnPoints = (Unit<T>)int.MaxValue;
}
else {
returnPoints = (Unit<T>)(a._value / b);
}
return returnPoints;
}
public override bool Equals(object obj) {
return obj is Unit<T> points &&
_value == points._value;
}
public override int GetHashCode() {
return HashCode.Combine(_value);
}
public override string ToString() => _value.ToString();
}
public interface IUnit { }
public class PainUnit : IUnit { }
public class FatigueUnit : IUnit { }
public class StrainUnit : IUnit { }
public class RedTagUnit : IUnit { }
public class BlueTagUnit : IUnit { }
public class GreenTagUnit : IUnit { }
}
fileFormatVersion: 2
guid: 94efccc62caea1a4580ab6f122e09ce2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using TagFighter.Resources;
using UnityEngine;
namespace TagFighter.UI
{
[RequireComponent(typeof(IResourceViewer))]
public class ResourceWatcher : MonoBehaviour
{
IWatchableResource _watchedResource;
IResourceViewer _resourceDisplay;
static readonly OnChangeArgs Default = new(0, 1, 0, 0);
public IWatchableResource WatchedResource {
get => _watchedResource;
set {
if (_watchedResource != null) {
_watchedResource.OnCapacityChanged -= OnCapacityChanged;
_watchedResource.OnCurrentChanged -= OnCurrentChanged;
_watchedResource.OnRegenerationAmountChanged -= OnRegenerationAmountChanged;
}
_watchedResource = value;
OnChangeArgs status = Default;
if (_watchedResource != null) {
_watchedResource.OnCapacityChanged += OnCapacityChanged;
_watchedResource.OnCurrentChanged += OnCurrentChanged;
_watchedResource.OnRegenerationAmountChanged += OnRegenerationAmountChanged;
status = _watchedResource.Status;
}
_resourceDisplay.UpdateView(status);
}
}
protected void Awake() {
_resourceDisplay = GetComponent<IResourceViewer>();
}
protected virtual void OnCapacityChanged(object sender, OnChangeArgs e) {
_resourceDisplay.UpdateView(e);
}
protected virtual void OnCurrentChanged(object sender, OnChangeArgs e) {
_resourceDisplay.UpdateView(e);
}
protected virtual void OnRegenerationAmountChanged(object sender, OnChangeArgs e) {
_resourceDisplay.UpdateView(e);
}
protected void OnDestroy() {
_resourceDisplay = null;
}
}
}
fileFormatVersion: 2
guid: bede5cbc2cf21a3499cd0b5e3a262d95
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using UnityEngine;
namespace TagFighter.Resources
{
[Serializable]
public class Resource<T> : MonoBehaviour, IWatchableResource where T : IUnit
{
[SerializeField] Unit<T> _current;
[SerializeField] Unit<T> _capacity;
readonly Unit<T> _minimumCapacity = (Unit<T>) 0;
[SerializeField] Unit<T> regenerationAmount;
[Range(0.1f, 10f)] public float RegenerationRate;
public OnChangeArgs Status => (OnChangeArgs)this;
public Unit<T> Capacity {
get => _capacity;
set {
if (Capacity == value) {
return;
}
_capacity = value;
OnCapacityChanged?.Invoke(this, (OnChangeArgs)this);
if (Current < Capacity) {
Current = Capacity;
}
}
}
public Unit<T> Current {
get => _current;
set {
var valueToSet = (Unit<T>) Math.Clamp((int)value, (int)_minimumCapacity, (int) Capacity);
if (_current != valueToSet) {
_current = valueToSet;
OnCurrentChanged?.Invoke(this, (OnChangeArgs)this);
}
}
}
public Unit<T> RegenerationAmount {
get => regenerationAmount;
set {
regenerationAmount = value;
OnRegenerationAmountChanged?.Invoke(this, (OnChangeArgs)this);
}
}
public event EventHandler<OnChangeArgs> OnCurrentChanged;
public event EventHandler<OnChangeArgs> OnCapacityChanged;
public event EventHandler<OnChangeArgs> OnRegenerationAmountChanged;
public static explicit operator OnChangeArgs(Resource<T> resource) {
return new(
(int)resource.Current,
(int)resource.Capacity,
(int)resource.RegenerationAmount,
resource.RegenerationRate);
}
private IEnumerator Regenerate() {
while (true) {
yield return new WaitForSeconds(RegenerationRate);
Current += RegenerationAmount;
// print($"Regenerated {typeof(T).Name}, value = {Current}");
}
}
protected void Start() {
StartCoroutine(Regenerate());
}
}
}
fileFormatVersion: 2
guid: dd2006828ab220e4eafe7e265905282d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using TagFighter.Resources;
namespace TagFighter.UI
{
public interface IResourceViewer
{
public void UpdateView(OnChangeArgs e);
}
}
transform.Find($"RedTag").GetComponent<PawnResourceWatcher>().WatchedResource = GetComponentInParent<RedTag>();
transform.Find($"GreenTag").GetComponent<PawnResourceWatcher>().WatchedResource = GetComponentInParent<GreenTag>();
transform.Find($"BlueTag").GetComponent<PawnResourceWatcher>().WatchedResource = GetComponentInParent<BlueTag>();
transform.Find($"RedTag").GetComponent<ResourceWatcher>().WatchedResource = GetComponentInParent<RedTag>();
transform.Find($"GreenTag").GetComponent<ResourceWatcher>().WatchedResource = GetComponentInParent<GreenTag>();
transform.Find($"BlueTag").GetComponent<ResourceWatcher>().WatchedResource = GetComponentInParent<BlueTag>();