Second commit
This commit is contained in:
commit
36840f3ad4
999 files changed
+61364
No files matched your search
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.D.Cleaning.CleanTools;
|
||||
using R3;
|
||||
using Reflex.Attributes;
|
||||
using Unity.Burst;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.D.Player
|
||||
{
|
||||
public class PlayerEquipment : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Texture2D tryapkaBrushTexture;
|
||||
public CleanTool CurrentTool { get; private set; }
|
||||
private Dictionary<CleanToolType, CleanTool> _cleanTools = new();
|
||||
public ReactiveProperty<CleanToolType> CurrentToolType { get; } = new();
|
||||
|
||||
private IDisposable _dirtinessDisposable;
|
||||
|
||||
[Inject]
|
||||
private void Construct(List<CleanTool> cleanTools)
|
||||
{
|
||||
foreach (var cleanTool in cleanTools) _cleanTools.Add(cleanTool.ToolType, cleanTool);
|
||||
|
||||
var firstTool = _cleanTools.First();
|
||||
CurrentToolType.Value = firstTool.Key;
|
||||
CurrentTool = firstTool.Value;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
//CurrentTool = new Tryapka(0.0001f, 0.005f, tryapkaBrushTexture);
|
||||
//
|
||||
// DisposableBuilder builder = new DisposableBuilder();
|
||||
// // Я безумец, здесь подписаться на все сразу
|
||||
// builder.Add(CurrentTool.CurrentDirtiness.Subscribe(x => CurrentToolDirtiness.Value =
|
||||
// new ToolDirtinessData
|
||||
// {
|
||||
// Dirtiness = x,
|
||||
// ToolType = CleanToolType.Tryapka
|
||||
// }
|
||||
// ));
|
||||
//
|
||||
// _dirtinessDisposable = builder.Build();
|
||||
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_dirtinessDisposable?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public struct ToolDirtinessData : IEquatable<ToolDirtinessData>
|
||||
{
|
||||
public float Dirtiness;
|
||||
public CleanToolType ToolType;
|
||||
|
||||
public bool Equals(ToolDirtinessData other)
|
||||
{
|
||||
return Mathf.Approximately(Dirtiness, other.Dirtiness) && ToolType == other.ToolType;
|
||||
}
|
||||
|
||||
[BurstDiscard]
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is ToolDirtinessData other && Equals(other);
|
||||
}
|
||||
|
||||
[BurstDiscard]
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Dirtiness, ToolType);
|
||||
}
|
||||
|
||||
public static bool operator ==(ToolDirtinessData left, ToolDirtinessData right) => left.Equals(right);
|
||||
public static bool operator !=(ToolDirtinessData left, ToolDirtinessData right) => !left.Equals(right);
|
||||
}
|
||||
|
||||
public struct ToolDirtyData : IEquatable<ToolDirtyData>
|
||||
{
|
||||
public CleanToolType ToolType;
|
||||
|
||||
public bool Equals(ToolDirtyData other)
|
||||
{
|
||||
return ToolType == other.ToolType;
|
||||
}
|
||||
|
||||
[BurstDiscard]
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is ToolDirtyData other && Equals(other);
|
||||
}
|
||||
|
||||
[BurstDiscard]
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ToolType.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(ToolDirtyData left, ToolDirtyData right) => left.Equals(right);
|
||||
public static bool operator !=(ToolDirtyData left, ToolDirtyData right) => !left.Equals(right);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user