This commit is contained in:
2026-07-09 21:33:33 +02:00
commit 84a2a365f3
2364 changed files with 950134 additions and 0 deletions
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d23037a424044e309cd5d9d8888f073d
timeCreated: 1670860447
@@ -0,0 +1,13 @@
using VOID.Generic.Objects.Abstract.Events;
using VOID.Generic.Objects.Unit;
namespace VOID.Generic.Objects.Item.Events
{
public class DropEvent : AbstractEvent
{
public bool prevented = false;
public ItemObject item;
public UnitObject unit;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e203310941f54d02b47cef3f9e8c20d4
timeCreated: 1670866592
@@ -0,0 +1,14 @@
using UnityEngine;
using VOID.Generic.Objects.Abstract.Events;
using VOID.Generic.Objects.Unit;
namespace VOID.Generic.Objects.Item.Events
{
public class MoveItemEvent : AbstractEvent
{
public ItemObject item;
public UnitObject unit;
public Vector3 fromPosition;
public Vector3 toPosition;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a453865967934a0a89b000580d5ac9c4
timeCreated: 1694902221
@@ -0,0 +1,13 @@
using VOID.Generic.Objects.Abstract.Events;
using VOID.Generic.Objects.Unit;
namespace VOID.Generic.Objects.Item.Events
{
public class PickEvent : AbstractEvent
{
public bool prevented = false;
public ItemObject item;
public UnitObject unit;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6fb2036978d04f1791b5c913cdca486e
timeCreated: 1670862299
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using UnityEngine;
using VOID.Generic.Objects.Abstract;
namespace VOID.Generic.Objects.Item
{
public class ItemObject : AbstractObject
{
[Title("=== ItemObject properties ===")]
public ItemObjectData itemData;
public ItemObjectEvents itemEvents;
public ItemObjectState itemState;
protected override List<ObjectComponent> GetObjectComponents()
{
return base.GetObjectComponents()
.Union(new List<ObjectComponent>
{
itemData,
itemEvents,
itemState
})
.ToList();
}
/// <summary>
/// Moves current item to given position
/// </summary>
/// <returns>TRUE if item can be moved</returns>
public bool Move(Vector3 moveTo)
{
// TODO: póki co przenoszenie za pomocą "teleportacji", kiedyś dorobić ładny ruch przedmiotu do tego miejsca
Debug.LogWarning("TODO: Action MoveItem: item teleported");
transform.position = moveTo;
transform.rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y, 0);
return true;
}
public bool CanStackWith(ItemObject otherItem) => CanStackWith(otherItem, out _);
public bool CanStackWith(ItemObject otherItem, out bool thisItemWillBeRemoved)
{
thisItemWillBeRemoved = false;
if (this == otherItem) return false;
if (!otherItem) return false;
if (itemData.uniqueId != otherItem.itemData.uniqueId) return false;
if (!itemData.stackable) return false;
if (!otherItem.itemData.stackable) return false;
if (itemData.stackSize + otherItem.itemData.stackSize > itemData.stackSizeMax) thisItemWillBeRemoved = true;
return true;
}
public void StackWith(ItemObject otherItem) => StackWith(otherItem, out _);
public void StackWith(ItemObject otherItem, out bool thisItemWillBeRemoved)
{
if (this == otherItem)
throw new Exception("Trying to stack with itself!");
if (!otherItem)
throw new Exception("Other item doesn't exist!");
if (itemData.uniqueId != otherItem.itemData.uniqueId)
throw new Exception("Trying to stack with item having different unique id!");
if (!itemData.stackable)
throw new Exception("This item is not stackable!");
if (!otherItem.itemData.stackable)
throw new Exception("other item is not stackable!");
var sum = itemData.stackSize + otherItem.itemData.stackSize;
var overflow = sum - itemData.stackSizeMax;
if (overflow > 0)
{
thisItemWillBeRemoved = false;
otherItem.itemData.stackSize = itemData.stackSizeMax;
itemData.stackSize = overflow;
}
else
{
thisItemWillBeRemoved = true;
otherItem.itemData.stackSize = sum;
Remove();
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6e9588e995e3fb43964239ffbbd8d13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: ae27aa9e9c30de644ba5cf18b511d34a, type: 3}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using System;
using Sirenix.OdinInspector;
using VOID.ScriptableObjects;
namespace VOID.Generic.Objects.Item
{
[Serializable]
[TypeInfoBox("Most values can be changed only in main prefab!")]
public class ItemObjectData : ObjectComponent<ItemObject>
{
[Title("Uniqueness")]
[EnableIn(PrefabKind.Regular)] public string uniqueId = Guid.NewGuid().ToString();
[Title("Display in UI")]
public string finalName => parent.basicData.name + (stackable ? $" ({stackSize})" : "");
public float finalWeight => stackable ? stackSize * weight : weight;
public int finalValue => stackable ? stackSize * value : value;
[Title("Possible actions")]
[EnableIn(PrefabKind.Regular)] public bool canBePicked = true;
[EnableIn(PrefabKind.Regular)] public bool canBeMoved = true;
[Title("Item base stats")]
[EnableIn(PrefabKind.Regular)] public ItemQuality quality;
[EnableIn(PrefabKind.Regular), MinValue(0)] public float weight = 1;
[EnableIn(PrefabKind.Regular), MinValue(0)] public int value = 0;
[Title("Stacking")]
[InfoBox("Stackable only available if both items have identical uniqueId.")]
[EnableIn(PrefabKind.Regular)] public bool stackable = false;
[ShowIf("stackable"), MinValue(1), MaxValue(nameof(stackSizeMax))] public int stackSize = 1;
[EnableIn(PrefabKind.Regular), ShowIf("stackable"), MinValue(1)] public int stackSizeMax = 1;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d460d4d8409dc784c8328d2bcd40ee8f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,25 @@
using Sirenix.OdinInspector;
using UnityEngine.Events;
using VOID.Generic.Objects.Container.Events;
using VOID.Generic.Objects.Item.Events;
namespace VOID.Generic.Objects.Item
{
[System.Serializable]
public class ItemObjectEvents : ObjectComponent<ItemObject>
{
[Title("Picked & Dropped")]
public UnityEvent<PickEvent> onPickedBefore;
public UnityEvent<PickEvent> onPickedAfter;
public UnityEvent<DropEvent> onDroppedBefore;
public UnityEvent<DropEvent> onDroppedAfter;
[Title("Moved")]
public UnityEvent<MoveItemEvent> onMovedBefore;
public UnityEvent<MoveItemEvent> onMovedAfter;
[Title("Moved")]
public UnityEvent<ContainerMoveInEvent> onMovedIntoContainer;
public UnityEvent<ContainerMoveOutEvent> onMovedOutOfContainer;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3fe8dd9faea24cd4a3594d5fdbe19271
timeCreated: 1675719187
@@ -0,0 +1,50 @@
using VOID.Generic.Objects.Container;
using VOID.Generic.Objects.Container.Events;
using VOID.Generic.Objects.Item.Events;
using VOID.Generic.Objects.Unit;
namespace VOID.Generic.Objects.Item
{
[System.Serializable]
public class ItemObjectState : ObjectComponent<ItemObject>
{
#region Initialize
protected override void EventInitialize()
{
parent.itemEvents.onPickedAfter.AddListener(OnPicked);
parent.itemEvents.onDroppedAfter.AddListener(OnDropped);
parent.itemEvents.onMovedIntoContainer.AddListener(OnMovedIntoContainer);
parent.itemEvents.onMovedOutOfContainer.AddListener(OnMovedOutOfContainer);
}
#endregion
public UnitObject carriedBy { get; private set; }
public ContainerObject inContainer { get; private set; }
private void OnPicked(PickEvent pickEvent)
{
carriedBy = pickEvent.unit;
parent.gameObject.SetActive(!carriedBy && !inContainer);
}
private void OnDropped(DropEvent dropEvent)
{
carriedBy = null;
parent.gameObject.SetActive(!carriedBy && !inContainer);
}
private void OnMovedIntoContainer(ContainerMoveInEvent containerMoveInEvent)
{
inContainer = containerMoveInEvent.container;
parent.gameObject.SetActive(!carriedBy && !inContainer);
}
private void OnMovedOutOfContainer(ContainerMoveOutEvent containerMoveOutEvent)
{
inContainer = null;
parent.gameObject.SetActive(!carriedBy && !inContainer);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 32f519a36c384889ac77709d5ae6ffaf
timeCreated: 1672664906