NG_/Assets/Scripts/Data/Entity/MaterialData.cs

31 lines
1004 B
C#
Raw Normal View History

2024-12-13 19:40:05 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 耗材数据结构
[System.Serializable]
public class MaterialData:IEquatable<MaterialData>
{
public string name; // 耗材名称
public string type; // 耗材类型
public int stock; // 实时库存
public int warningValue; // 预警值
// 实现IEquatable接口的Equals方法以及重写GetHashCode方法以及ToString方法
public bool Equals(MaterialData other)
{
if (other is null) return false;
if (ReferenceEquals(this, other)) return true;
return name == other.name && type == other.type && stock == other.stock && warningValue == other.warningValue;
}
public override int GetHashCode()
{
return HashCode.Combine(name, type, stock, warningValue);
}
public override string ToString()
{
return $"耗材名称: {name}, 耗材类型: {type}, 实时库存: {stock}, 预警值: {warningValue}";
}
}