Added Furnance and smelting
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49b83c56f1d5e6d46b448c92e658fbe9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(NetworkItem))]
|
||||
public sealed class FurnaceMetalSource : MonoBehaviour
|
||||
{
|
||||
[SerializeField, Min(0.01f)] private float metalAmount = 25f;
|
||||
|
||||
private bool isConsumed;
|
||||
|
||||
public float MetalAmount => metalAmount;
|
||||
public bool IsConsumed => isConsumed;
|
||||
|
||||
public bool TryMarkConsumed()
|
||||
{
|
||||
if (isConsumed)
|
||||
return false;
|
||||
|
||||
isConsumed = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9dd3ea21361871345b5a9d21839c6da1
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "ItemCatalog", menuName = "FORT-BO/Items/Item Catalog")]
|
||||
public sealed class ItemCatalog : ScriptableObject
|
||||
{
|
||||
[SerializeField] private List<ItemDefinition> items = new();
|
||||
|
||||
private readonly Dictionary<string, ItemDefinition> itemsById =
|
||||
new(StringComparer.Ordinal);
|
||||
|
||||
public IReadOnlyList<ItemDefinition> Items => items;
|
||||
|
||||
private void OnEnable() => RebuildIndex();
|
||||
private void OnValidate() => RebuildIndex();
|
||||
|
||||
public bool TryGetItem(string itemId, out ItemDefinition definition)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(itemId))
|
||||
{
|
||||
definition = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return itemsById.TryGetValue(itemId.Trim().ToLowerInvariant(), out definition);
|
||||
}
|
||||
|
||||
private void RebuildIndex()
|
||||
{
|
||||
itemsById.Clear();
|
||||
|
||||
foreach (ItemDefinition definition in items)
|
||||
{
|
||||
if (definition == null || string.IsNullOrWhiteSpace(definition.ItemId))
|
||||
continue;
|
||||
|
||||
if (!itemsById.TryAdd(definition.ItemId, definition))
|
||||
Debug.LogError($"Duplicate item id '{definition.ItemId}' in {name}.", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0928368adb57acb4987bb8fabda3a927
|
||||
@@ -0,0 +1,31 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
public enum ItemCategory
|
||||
{
|
||||
Scrap,
|
||||
SmeltedMaterial,
|
||||
RocketPart,
|
||||
Tool,
|
||||
Consumable
|
||||
}
|
||||
|
||||
[CreateAssetMenu(fileName = "ItemDefinition", menuName = "FORT-BO/Items/Item Definition")]
|
||||
public sealed class ItemDefinition : ScriptableObject
|
||||
{
|
||||
[SerializeField] private string itemId;
|
||||
[SerializeField] private string displayName;
|
||||
[SerializeField] private ItemCategory category;
|
||||
[SerializeField] private NetworkObject worldPrefab;
|
||||
|
||||
public string ItemId => itemId;
|
||||
public string DisplayName => string.IsNullOrWhiteSpace(displayName) ? name : displayName;
|
||||
public ItemCategory Category => category;
|
||||
public NetworkObject WorldPrefab => worldPrefab;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
itemId = itemId?.Trim().ToLowerInvariant();
|
||||
displayName = displayName?.Trim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0c79cebdb4201743be8612545ee180e
|
||||
@@ -0,0 +1,14 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(NetworkObject))]
|
||||
public sealed class NetworkItem : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private ItemDefinition definition;
|
||||
|
||||
public ItemDefinition Definition => definition;
|
||||
public string ItemId => definition != null ? definition.ItemId : string.Empty;
|
||||
public string DisplayName => definition != null ? definition.DisplayName : name;
|
||||
public ItemCategory Category => definition != null ? definition.Category : default;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 323282b7a87fc4344bd33250e88822e8
|
||||
Reference in New Issue
Block a user