initial commit

This commit is contained in:
Aggtaa
2026-01-11 13:48:49 +03:00
commit f846df9d8c
143 changed files with 21694 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Tilemaps;
[Serializable]
public class Inventory : IDataPersistence<InventoryData>
{
private int capacity = 0;
private Dictionary<string, int> items = new Dictionary<string, int>();
public Inventory(int capacity)
{
this.capacity = capacity;
}
public IReadOnlyDictionary<string, int> Items => items;
public int Capacity => capacity;
public int Load => items.Sum(kvp => kvp.Value);
public int Free => Capacity < 0 ? int.MaxValue : Capacity - Load;
public override string ToString()
{
string text = string.Join(Environment.NewLine, items);
text += Environment.NewLine + Environment.NewLine + $"Занято {Load}";
if (Capacity >= 0)
text += $", свободно {Capacity - Load}";
return text;
}
public int Add(string key, int value, bool allowPartialAdd = false)
{
if (!allowPartialAdd && (Capacity >= 0) && (Capacity < Load + value))
return 0;
value = Math.Min(value, Free);
if (items.ContainsKey(key))
items[key] += value;
else
items[key] = value;
return value;
}
public void LoadData(InventoryData data)
{
items = data.items;
capacity = data.capacity;
}
public void SaveData(InventoryData data)
{
data.items = new SerializableDictionary<string, int>(items);
data.capacity = capacity;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ce5eba69c9106f64baa1f264b567c861
@@ -0,0 +1,51 @@
using UnityEngine;
using UnityEngine.UIElements;
public class UIToolkitInfoPanel : MonoBehaviour
{
public Transform targetObject;
public Vector3 worldOffset = new Vector3(0, 1f, 0);
private UIDocument uiDocument;
private VisualElement infoPanel;
private Label infoLabel;
private Camera mainCamera;
void Start()
{
uiDocument = GetComponent<UIDocument>();
mainCamera = Camera.main;
if (uiDocument != null)
{
infoPanel = uiDocument.rootVisualElement.Q<VisualElement>("InfoPanel");
infoLabel = uiDocument.rootVisualElement.Q<Label>("InfoLabel");
}
}
void Update()
{
if (targetObject != null && infoPanel != null)
{
// Convert world position to screen space
Vector3 screenPos = mainCamera.WorldToScreenPoint(
targetObject.position + worldOffset
);
// Update panel position (UI Toolkit uses top-left origin)
infoPanel.style.left = screenPos.x;
infoPanel.style.top = Screen.height - screenPos.y;
// Update content
UpdateInfoContent();
}
}
void UpdateInfoContent()
{
if (infoLabel != null)
{
infoLabel.text = $"{targetObject.name}\nPosition: {targetObject.position}";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bf6bf11968b160c47b04fbb2d137051e