This commit is contained in:
2026-04-25 23:37:10 +02:00
commit 19d6bd934a
476 changed files with 9198 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 246c7f468cf64a629c371b64c2e920e8
timeCreated: 1773428848
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 846e226f291f4671be66417e772c98c5
timeCreated: 1773428855
@@ -0,0 +1,21 @@
{
"name": "RPGCore.BackpackEquipment.Editor",
"rootNamespace": "RPGCore.BackpackEquipment.Editor",
"references": [
"RPGCore",
"RPGCore.Editor",
"RPGCore.BackpackEquipment",
"RPGCoreCommon.Helpers"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2576611464924f6f802336cafddc5977
timeCreated: 1773428869
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8515b9a070ec44b58d2b7cbd621055e0
timeCreated: 1773428859
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5c5dabd4515f45fb96c7f15903844f14
timeCreated: 1774103711
@@ -0,0 +1,46 @@
using RPGCore.BackpackEquipment.Events;
using RPGCore.BackpackEquipment.ObjectModules.Content.Events;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.ObjectModules.ActionObjectModule;
namespace RPGCore.BackpackEquipment.Actions
{
public class UseUsableAction : BaseActionParallel
{
private readonly UsableObject _usable;
public UseUsableAction(UsableObject usable)
{
_usable = usable;
}
public override void CanDoIt()
{
}
protected override void OnDoIt()
{
var useEvent = new UseUsableEvent
{
unit = unit,
usable = _usable,
};
unit.events.InvokeBefore(useEvent);
_usable.events.InvokeBefore(useEvent);
Check(!useEvent.isPrevented, ActionWasPreventedMessage);
BeforePerform();
AfterPerform();
unit.events.InvokeAfter(useEvent);
_usable.events.InvokeAfter(useEvent);
EndIt();
}
protected override void OnEndIt() { }
protected override void OnCancelIt() { }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cb1ae2d4cdf64919807fcb9f305c8112
timeCreated: 1764968523
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 613dac7e64bf4e00843b96715575183c
timeCreated: 1774104256
@@ -0,0 +1,20 @@
using System;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
using UnityEngine;
namespace RPGCore.BackpackEquipment.Data
{
[Serializable]
public sealed class ItemObjectData : BaseData<ItemObject>
{
[Header("Current state")]
public BaseObject carriedBy { get; set; }
[Header("Stacking")]
[field: SerializeField] public bool stackable { get; private set; } = false;
[field: SerializeField] [Min(1)] public int stackSize { get; set; } = 1;
[field: SerializeField] [Min(1)] public int stackSizeMax { get; private set; } = 1;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7f4c99a92ec24e4188e68b383aafa544
timeCreated: 1774024999
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4e5cdbb2c066404bb108b2b65d7b5532
timeCreated: 1774103708
@@ -0,0 +1,12 @@
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.Events
{
public class UseUsableEvent : BasePreventableEvent<UnitObject>
{
public UnitObject unit;
public UsableObject usable;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c0cda7055098456787bdfe5e373e8c79
timeCreated: 1764943310
@@ -0,0 +1,10 @@
using RPGCoreCommon.Settings;
namespace RPGCore.BackpackEquipment.TheVVaS.RPGCore.BackpackEquipment.Runtime
{
[CustomSettings("RPG Core/Inventory")]
public class InventorySettings : CustomSettingsSO
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 23152dde11934dc888fb1a826a8d9603
timeCreated: 1774116804
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 133e3213c71840b7affa92b9c12e1359
timeCreated: 1773430576
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4d921d95879d44f0bd88e5c7f05450b1
timeCreated: 1773479260
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5173c23cdfbb43fd80e5bb85342554b1
timeCreated: 1774105224
@@ -0,0 +1,38 @@
using RPGCore.BackpackEquipment.ObjectModules.Content.Events;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.ObjectModules.ActionObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.Content.Actions
{
public class DropAction : BaseAction
{
private readonly ItemObject _item;
public DropAction(ItemObject item)
{
_item = item;
}
public override void CanDoIt()
{
}
protected override void OnDoIt()
{
var dropEvent = new DropEvent { unit = unit, item = _item };
unit.events.InvokeBefore(dropEvent);
Check(!dropEvent.isPrevented, string.Format(ActionWasPreventedMessage, nameof(DropAction)));
unit.events.InvokeAfter(dropEvent);
unit.GetComponent<ContentModule>().Remove(_item);
}
protected override void OnEndIt()
{
}
protected override void OnCancelIt()
{
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 15a26990a9c14410b2131f6d8286ad18
timeCreated: 1774104885
@@ -0,0 +1,45 @@
using RPGCore.BackpackEquipment.ObjectModules.Content.Events;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.ObjectModules.ActionObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.Content.Actions
{
public class TakeAction : BaseAction
{
private readonly IContentOwner _contentOwner;
private readonly ItemObject _item;
private readonly int _index;
public TakeAction(IContentOwner contentOwner, ItemObject item, int index = -1)
{
_contentOwner = contentOwner;
_item = item;
_index = index;
}
public override void CanDoIt()
{
_contentOwner.CanAdd(_item, _index);
}
protected override void OnDoIt()
{
var takeEvent = new TakeEvent { unit = unit, item = _item };
unit.events.InvokeBefore(takeEvent);
Check(!takeEvent.isPrevented, string.Format(ActionWasPreventedMessage, nameof(TakeAction)));
unit.events.InvokeAfter(takeEvent);
var content = unit.GetComponent<ContentModule>();
content.Add(_item);
content.TransferTo(_contentOwner, _item, _index);
}
protected override void OnEndIt()
{
}
protected override void OnCancelIt()
{
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e2df668c012544ff893888d9f5bcce9a
timeCreated: 1774104779
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using RPGCore.BackpackEquipment.Data;
using RPGCore.BackpackEquipment.ObjectModules.Content.Events;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule.Events;
using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.Content
{
[Serializable]
[RequireComponent(typeof(BaseObject))]
public sealed class ContentModule : ObjectModule<BaseObject>
{
// TODO: tutaj jakiś domyślny owner?
private Dictionary<ItemObject, IContentOwner> _items = new();
public bool Add(ItemObject item)
{
if (item.data.Get<ItemObjectData>().carriedBy) return false;
if (_items.ContainsKey(item)) return false;
_items.TryAdd(item, null);
item.data.Get<ItemObjectData>().carriedBy = parent;
parent.events.Invoke(new ContentAddEvent{obj = parent, item = item});
item.events.Register<RemoveEvent>(OnItemRemove);
return true;
}
public bool Remove(ItemObject item)
{
if (!_items.ContainsKey(item)) return false;
_items[item]?.Remove_Internal(item);
_items.Remove(item);
item.data.Get<ItemObjectData>().carriedBy = null;
parent.events.Invoke(new ContentAddEvent{obj = parent, item = item});
item.events.Unregister<RemoveEvent>(OnItemRemove);
return true;
}
public bool TransferTo(IContentOwner newOwner, ItemObject item, int index = -1)
{
if (parent.data.Get<ItemObjectData>().carriedBy != parent) return false;
if (!newOwner.CanAdd(item, index)) return false;
_items.TryAdd(item, null);
_items[item]?.Remove_Internal(item);
_items[item] = newOwner;
newOwner.Add_Internal(item, index);
return true;
}
private void OnItemRemove(RemoveEvent removeEvent)
{
Remove(removeEvent.obj as ItemObject);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 79108abbb1214cdca99dde30ae550ceb
timeCreated: 1773479273
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3913c554eb1a4addbb26fffdcd349490
timeCreated: 1773603441
@@ -0,0 +1,12 @@
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.Content.Events
{
public class ContentAddEvent : BaseEvent<BaseObject>
{
public BaseObject obj;
public ItemObject item;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 99499df3a233439c87e15c7aff0c5f7e
timeCreated: 1773603493
@@ -0,0 +1,12 @@
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.Content.Events
{
public class ContentRemoveEvent : BaseEvent<BaseObject>
{
public BaseObject obj;
public ItemObject item;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9475ae89a4184189aadc77e6efc7f86b
timeCreated: 1773603523
@@ -0,0 +1,12 @@
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.Content.Events
{
public class DropEvent : BasePreventableEvent<UnitObject>
{
public UnitObject unit;
public ItemObject item;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6d837632056f4104b980ea605bedf43a
timeCreated: 1774105017
@@ -0,0 +1,12 @@
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.Content.Events
{
public class TakeEvent : BasePreventableEvent<UnitObject>
{
public UnitObject unit;
public ItemObject item;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 59ccda71e50b47c1aa77c87b649fcbc6
timeCreated: 1774104995
@@ -0,0 +1,18 @@
using RPGCore.BackpackEquipment.Objects;
namespace RPGCore.BackpackEquipment.ObjectModules.Content
{
public interface IContentOwner
{
internal bool Add_Internal(ItemObject item, int index = -1)
{
return CanAdd(item, index) && Add(item, index);
}
internal bool Remove_Internal(ItemObject item) => Remove(item);
public bool CanAdd(ItemObject item, int index);
protected bool Add(ItemObject item, int index);
protected bool Remove(ItemObject item);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 78febecbf5d31be469d6b9d3c816fd4d
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dd19ece4ebc44910a39c811850fd4193
timeCreated: 1773430585
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 44fa14edd1ea4bca85d9f05ac40e40ea
timeCreated: 1774105228
@@ -0,0 +1,13 @@
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitBackpack.Events
{
public class BackpackAddEvent : BaseEvent<UnitObject>
{
public UnitObject unit;
public ItemObject item;
public int index;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c6f6cc77ea14440495a47ca94593c621
timeCreated: 1774105312
@@ -0,0 +1,13 @@
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitBackpack.Events
{
public class BackpackRemoveEvent : BaseEvent<UnitObject>
{
public UnitObject unit;
public ItemObject item;
public int index;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71449b2a17364a648815c450a72a7b8a
timeCreated: 1774105327
@@ -0,0 +1,12 @@
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitBackpack.Events
{
public class BackpackResizeEvent : BaseEvent<UnitObject>
{
public UnitObject unit;
public int beforeSlotCount;
public int afterSlotCount;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 78e21ee03af24c16b2227c490a8baf32
timeCreated: 1774205953
@@ -0,0 +1,10 @@
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitBackpack.Events
{
public class BackpackSortEvent : BaseEvent<UnitObject>
{
public UnitObject unit;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a837a368926d42888b1a661e56cab0df
timeCreated: 1774129920
@@ -0,0 +1,17 @@
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitBackpack.Events
{
public class BackpackSwapEvent : BaseEvent<UnitObject>
{
public UnitObject unit;
public int firstSlotIndex;
public ItemObject firstItem;
public int secondSlotIndex;
public ItemObject secondItem;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4343d10da640435abbc163a2d255ddf2
timeCreated: 1774206592
@@ -0,0 +1,154 @@
using System;
using System.Linq;
using RPGCore.BackpackEquipment.ObjectModules.Content;
using RPGCore.BackpackEquipment.ObjectModules.UnitBackpack.Events;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core;
using RPGCore.Core.Objects;
using RPGCoreCommon.Helpers.PropertyAttributeDrawers;
using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitBackpack
{
[RequireComponent(typeof(UnitObject))]
[RequireComponent(typeof(ContentModule))]
[DisallowMultipleComponent]
public sealed class UnitBackpackModule : ObjectModule<UnitObject>, IContentOwner
{
// TODO: implementacja stackowania tutaj
[SerializeField] private ItemObject[] _serializedItems;
[SerializeField] public bool isLimited = true;
[SerializeField] public int itemsLimit = 5;
[SerializeField] public int itemsPerChunk = 5;
[SerializeField] public int minimumChunks = 3;
[SerializeField] public int additionalChunks = 1;
private ItemObject[] _items;
public ItemObject[] items => _items.ToArray();
private void Awake()
{
_items = _serializedItems.ToArray();
Resize();
}
private void Start()
{
InitializeItems();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void InitializeItems()
{
// TODO: inicjalizacja serializowanych itemkow + ich eventy
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public bool CanAdd(ItemObject item, int index)
{
return !isLimited || _items.Any(i => i == null);
}
bool IContentOwner.Add(ItemObject item, int index)
{
if (index < 0) index = Array.IndexOf(_items, false);
if (index < 0) return false;
if (isLimited && index >= itemsLimit) return false;
_items[index] = item;
Resize();
parent.events.Invoke(new BackpackAddEvent { unit = parent, item = item, index = index });
return true;
}
bool IContentOwner.Remove(ItemObject item)
{
var index = Array.IndexOf(_items, item);
if (index < 0) return false;
_items[index] = null;
Resize();
parent.events.Invoke(new BackpackRemoveEvent { unit = parent, item = item, index = index });
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void Swap(int firstItemIndex, int secondItemIndex)
{
var wantedSize = Math.Max(firstItemIndex, secondItemIndex) + 1;
if (isLimited && wantedSize > itemsLimit) return;
Resize(wantedSize);
(items[firstItemIndex], items[secondItemIndex]) = (items[secondItemIndex], items[firstItemIndex]);
parent.events.Invoke(new BackpackSwapEvent
{
unit = parent,
firstSlotIndex = firstItemIndex,
firstItem = items[firstItemIndex],
secondSlotIndex = secondItemIndex,
secondItem = items[secondItemIndex],
});
}
private void Resize(int wantedSize = 0)
{
if (isLimited)
{
// TODO: obsłużyć itemki w miejscach, które zaraz zostaną "ucięte" (przy zmniejszaniu slotów) - TYLKO w limitowanym plecaku
if (_items.Length != itemsLimit)
{
Array.Resize(ref _items, itemsLimit);
}
return;
}
var limitBefore = items.Length;
var lastItemIndex = Array.FindLastIndex(items, item => item);
var limitMinimum = Mathf.Max(wantedSize, lastItemIndex, minimumChunks * itemsPerChunk);
var limitAfter = Mathf.CeilToInt((float)limitMinimum / itemsPerChunk + additionalChunks) * itemsPerChunk;
// Size not changed, do nothing
if (limitBefore == limitAfter) return;
// Resize backpack's arrays
Array.Resize(ref _items, limitAfter);
parent.events.Invoke(new BackpackResizeEvent
{
unit = parent,
beforeSlotCount = limitBefore,
afterSlotCount = limitAfter
});
}
public void Sort(Func<ItemObject, IComparable> valueGetter, bool sortDescending = false)
{
Array.Sort(items, (item1, item2) =>
{
// NULLS always to the end
if (!item1 && !item2) return 0;
if (!item1) return 1;
if (!item2) return -1;
// Existing items sort by given value getter with given sort direction
var result = valueGetter(item1).CompareTo(valueGetter(item2));
if (sortDescending) result *= - 1;
return result;
});
parent.events.Invoke(new BackpackSortEvent { unit = parent });
Resize();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e066d3b400674903a1d052f489460cbc
timeCreated: 1773430662
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9a81f86e2a5e4f37b06c93aa994bd84e
timeCreated: 1773430610
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8bf7e79f48a548eb84e276eee5e5e625
timeCreated: 1774105234
@@ -0,0 +1,29 @@
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects;
using RPGCore.ObjectModules.ActionObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Actions
{
public class EquipAction : BaseAction
{
private readonly WearableObject _wearable;
private readonly int _index;
public EquipAction(WearableObject wearable, int index = -1)
{
_wearable = wearable;
_index = index;
}
public override void CanDoIt()
{
}
protected override void OnDoIt()
{
}
protected override void OnEndIt() { }
protected override void OnCancelIt() { }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e7e7ce4fbec54ebfbe05f9cecae4a871
timeCreated: 1774105374
@@ -0,0 +1,27 @@
using RPGCore.ObjectModules.ActionObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Actions
{
public class UnEquipAction : BaseAction
{
public override void CanDoIt()
{
throw new System.NotImplementedException();
}
protected override void OnDoIt()
{
throw new System.NotImplementedException();
}
protected override void OnEndIt()
{
throw new System.NotImplementedException();
}
protected override void OnCancelIt()
{
throw new System.NotImplementedException();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 48179d58af5844cb9ea6d3df49a151cb
timeCreated: 1774105416
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8935ac7ea78145d2bade1ab807dcf5ac
timeCreated: 1776013837
@@ -0,0 +1,19 @@
using System;
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
using RPGCoreCommon.Helpers.PropertyAttributeDrawers;
using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Data
{
[Serializable]
public sealed class WearableObjectData : BaseData<WearableObject>
{
[Header("Current state")]
[field: SerializeField, ReadOnly] public UnitObject equippedBy { get; set; }
[Header("WEARABLE")]
[field: SerializeField] public WearableTypeSO type { get; private set; }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5225f7b9b3fd4b15874ed6af5a887703
timeCreated: 1775931397
@@ -0,0 +1,10 @@
using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment
{
[CreateAssetMenu(menuName = "RPG Core/Equipment/Schema")]
public class EquipmentSchemaSO : ScriptableObject
{
public EquipmentSchemaSlot[] slots;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1b6db097519240cdb57eb1a235eb6d00
timeCreated: 1774117121
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment
{
[Serializable]
public class EquipmentSchemaSlot
{
public string name;
public Texture2D icon;
public List<WearableTypeSO> validTypes;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3c100a156e9e403888cab30f01b22b2e
timeCreated: 1774117160
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5a9185f4f6844784b7432d9353365f7f
timeCreated: 1774105234
@@ -0,0 +1,14 @@
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events
{
public class EquipEvent : BaseEvent<UnitObject>
{
public UnitObject unit;
public WearableObject wearable;
public int index;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9c3da958a57e4b019de195f87cc032d7
timeCreated: 1774105477
@@ -0,0 +1,14 @@
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events
{
public class UnEquipEvent : BaseEvent<UnitObject>
{
public UnitObject unit;
public WearableObject wearable;
public int index;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b9b6c7062a844cb6bf556d76e7351410
timeCreated: 1774105488
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4f78116570fd4167a06bb18e9f0d585b
timeCreated: 1776013778
@@ -0,0 +1,13 @@
using System;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core;
using RPGCoreCommon.DynamicValues;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects
{
public class WearableObject : ItemObject
{
[DynamicValueProvider]
private ObjectModule<WearableObject> UsableModuleProvider(Type moduleType) => GetComponent(moduleType) as ObjectModule<WearableObject>;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c2ef6b5eaa38431bacb28adb8bb2739c
timeCreated: 1773430452
@@ -0,0 +1,78 @@
using System;
using System.Linq;
using RPGCore.BackpackEquipment.ObjectModules.Content;
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Data;
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events;
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core;
using RPGCore.Core.Objects;
using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment
{
[RequireComponent(typeof(UnitObject))]
[RequireComponent(typeof(ContentModule))]
[DisallowMultipleComponent]
public class UnitEquipmentModule : ObjectModule<UnitObject>, IContentOwner
{
[SerializeField] private EquipmentSchemaSO _schema;
[SerializeField] private WearableObject[] _serializedItems;
private WearableObject[] _items;
private void Awake()
{
_items = new WearableObject[_schema.slots.Length];
}
private void Start()
{
InitializeItems();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void InitializeItems()
{
// TODO: inicjalizacja serializowanych itemkow + ich eventy
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public bool CanAdd(ItemObject item, int index)
{
if (item is not WearableObject wearable) return false;
var slot = _schema.slots[index];
if (slot == null) return false;
if (!slot.validTypes.Contains(wearable.data.Get<WearableObjectData>().type)) return false;
return true;
}
bool IContentOwner.Add(ItemObject item, int index)
{
var wearable = (WearableObject)item;
parent.events.Invoke(new EquipEvent { unit = parent, wearable = wearable, index = index });
_items[index] = wearable;
return true;
}
bool IContentOwner.Remove(ItemObject item)
{
var wearable = (WearableObject)item;
var index = Array.IndexOf(_items, wearable);
parent.events.Invoke(new UnEquipEvent { unit = parent, wearable = wearable, index = index });
_items[index] = null;
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2daf6192d70b4fc798983932b68c28ea
timeCreated: 1773430702
@@ -0,0 +1,12 @@
using RPGCoreCommon.Helpers.CustomTypes;
using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment
{
[CreateAssetMenu(menuName = "RPG Core/Equipment/Wearable Type")]
public class WearableTypeSO : ScriptableObject
{
public new string name;
public Texture2D icon;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2c0e3d78b2374dfbb1b254cb9a9cef19
timeCreated: 1774116782
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 91c35ff45009487e8d5949bdd8a0e821
timeCreated: 1773430417
@@ -0,0 +1,13 @@
using System;
using RPGCore.Core;
using RPGCore.Core.Objects;
using RPGCoreCommon.DynamicValues;
namespace RPGCore.BackpackEquipment.Objects
{
public class ItemObject : BaseObject
{
[DynamicValueProvider]
private ObjectModule<ItemObject> ItemModuleProvider(Type moduleType) => GetComponent(moduleType) as ObjectModule<ItemObject>;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3a78a8ed91814b05aa7a0a34135d8edf
timeCreated: 1761863724
@@ -0,0 +1,12 @@
using System;
using RPGCore.Core;
using RPGCoreCommon.DynamicValues;
namespace RPGCore.BackpackEquipment.Objects
{
public class UsableObject : ItemObject
{
[DynamicValueProvider]
private ObjectModule<UsableObject> UsableModuleProvider(Type moduleType) => GetComponent(moduleType) as ObjectModule<UsableObject>;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 517748b5c1324d10b16e239bbbc7ba3e
timeCreated: 1761863772
@@ -0,0 +1,20 @@
{
"name": "RPGCore.BackpackEquipment",
"rootNamespace": "RPGCore.BackpackEquipment",
"references": [
"RPGCore",
"RPGCore.StatusEffect",
"RPGCoreCommon.Settings",
"RPGCoreCommon.Helpers",
"RPGCoreCommon.DynamicValues"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a627f0df001c4795964985a7b361ac64
timeCreated: 1773428871
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bfd9def14cab4592814c2cf160e6f8f2
timeCreated: 1772991224
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d2be1640179628a40821b132d8487517
timeCreated: 1772973840
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9b47a45649f44855b50d7efd8637fd23
timeCreated: 1768928367
@@ -0,0 +1,59 @@
using RPGCore.Movement.ObjectModules.UnitMovement;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace RPGCore.Movement.Editor.Drawers
{
[CustomPropertyDrawer(typeof(UnitMovementModule))]
public class UnitMovementModuleDrawer : PropertyDrawer
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var root = new VisualElement();
if (Application.isPlaying) root.Add(CreateDebugBox(property));
root.Add(new PropertyField(property));
return root;
}
private HelpBox CreateDebugBox(SerializedProperty property)
{
var debugBox = new HelpBox();
debugBox.style.flexDirection = FlexDirection.Column;
debugBox.style.alignItems = Align.Stretch;
debugBox.SetEnabled(false);
debugBox.Add(new Label("RUNTIME DEBUG:"));
var groundSteepnessField = new FloatField(nameof(UnitMovementModule.groundSteepness));
debugBox.Add(groundSteepnessField);
var isOnGroundField = new Toggle(nameof(UnitMovementModule.isOnGround));
debugBox.Add(isOnGroundField);
var rotateYawField = new FloatField(nameof(UnitMovementModule.rotateYaw));
debugBox.Add(rotateYawField);
var moveVectorField = new Vector3Field(nameof(UnitMovementModule.accelerationVector));
debugBox.Add(moveVectorField);
var linearVelocityField = new Vector3Field(nameof(Rigidbody.linearVelocity));
debugBox.Add(linearVelocityField);
var linearVelocityMagnitudeField = new FloatField(nameof(Rigidbody.linearVelocity.magnitude));
debugBox.Add(linearVelocityMagnitudeField);
debugBox.schedule.Execute(() =>
{
var module = property.boxedValue as UnitMovementModule;
groundSteepnessField.value = module.groundSteepness;
isOnGroundField.value = module.isOnGround;
rotateYawField.value = module.rotateYaw;
moveVectorField.value = module.accelerationVector;
linearVelocityField.value = module.parent.rigidbody.linearVelocity;
linearVelocityMagnitudeField.value = module.parent.rigidbody.linearVelocity.magnitude;
}).Every(100);
return debugBox;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3acb507069ca47ceb32fc3b5be9da459
timeCreated: 1768928385
@@ -0,0 +1,21 @@
{
"name": "RPGCore.Movement.Editor",
"rootNamespace": "RPGCore.Movement.Editor",
"references": [
"RPGCore",
"RPGCore.Editor",
"RPGCore.Movement",
"RPGCoreCommon.Helpers"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 162316575de365d43817366fcbce56bf
timeCreated: 1772973849
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7279c3bc406a2804bb2e7023c56f56cb
timeCreated: 1772973844
@@ -0,0 +1,13 @@
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule;
using RPGCoreCommon.Settings;
using UnityEngine;
namespace RPGCore.Movement
{
[CustomSettings("RPG Core/Movement")]
public class MovementSettings : CustomSettingsSO
{
[Header("Statuses Definitions")]
public StatusDefinitionSO runStatusDefinitionSO;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ed5576b120bd480796129f99e38965a5
timeCreated: 1772991814
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7c3413a6703346cfb369fc7a8959562f
timeCreated: 1772991398
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7dba86a6b4be4134866887f89495c479
timeCreated: 1767463510
@@ -0,0 +1,102 @@
using System;
using RPGCore.Movement.ObjectModules.UnitMovement;
using RPGCore.Movement.ObjectModules.UnitMovement.Events;
using RPGCore.Core;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
using RPGCoreCommon.Helpers;
using UnityEngine;
namespace RPGCore.Movement.ObjectModules.UnitAnimator
{
[Serializable]
[RequireComponent(typeof(UnitObject))]
[RequireComponent(typeof(UnitMovementModule))]
public class UnitAnimatorModule : ObjectModule<UnitObject>
{
// CONSTANT (defined in animator)
private static readonly int BaseLayer = 0;
private static readonly int VelocityMagnitude = Animator.StringToHash("VELOCITY_MAGNITUDE");
private static readonly int DirectionX = Animator.StringToHash("DIRECTION_X");
private static readonly int DirectionZ = Animator.StringToHash("DIRECTION_Z");
private static readonly int MoveAnimSpeed = Animator.StringToHash("MOVE_ANIM_SPEED");
private static readonly int JumpTrigger = Animator.StringToHash("JUMP_TRIGGER");
private static readonly int IsOnGround = Animator.StringToHash("IS_ON_GROUND");
// SERIALIZED
[SerializeField] private Animator _animator;
[Header("Movement animation speed - used for animation speed scaling")]
[SerializeField] private float _sprintSpeed = 6f;
[SerializeField] private float _runSpeed = 3f;
[Header("Animation spine helper")]
[SerializeField] private bool _spineHelper;
[SerializeField] private Transform _hips;
[SerializeField] private Transform _spine;
[SerializeField] private Quaternion _spineRotation;
private void OnValidate()
{
if (!_animator)
{
_animator = parent.GetComponentInChildren<Animator>();
UnityEditor.EditorUtility.SetDirty(parent.gameObject);
}
if (_animator)
{
_hips = _animator.GetBoneTransform(HumanBodyBones.Hips);
_spine = _animator.GetBoneTransform(HumanBodyBones.Spine);
_spineRotation = _spine.localRotation;
}
}
private void Awake()
{
parent.events.Register<JumpEvent>(_ => _animator.SetTrigger(JumpTrigger));
parent.events.Register<LandEvent>(_ => _animator.SetBool(IsOnGround, true));
parent.events.Register<FallEvent>(_ => _animator.SetBool(IsOnGround, false));
}
private void Start()
{
_animator.SetBool(IsOnGround, parent.GetComponent<UnitMovementModule>().isOnGround);
}
private void LateUpdate()
{
if (_spineHelper) _spine.rotation = _hips.rotation * _spineRotation;
}
private void FixedUpdate()
{
HandleMoveAnimation();
}
private void HandleMoveAnimation()
{
var unitMovement = parent.GetComponent<UnitMovementModule>();
if (!unitMovement.isMoving)
{
_animator.SetFloat(VelocityMagnitude, 0f);
_animator.SetFloat(DirectionX, 0f);
_animator.SetFloat(DirectionZ, 0f);
_animator.SetFloat(MoveAnimSpeed, 1f);
return;
}
// TODO: tutaj powinno jakoś fajnie brać prędkość TYLKO od ruchu, a nie całego velocity
var relVelocity = parent.transform.InverseTransformDirection(parent.rigidbody.linearVelocity.SetY(0));
var moveAnimSpeed = relVelocity.magnitude < _runSpeed ? relVelocity.magnitude / _runSpeed
: relVelocity.magnitude > _sprintSpeed ? relVelocity.magnitude / _sprintSpeed
: 1f;
var moveRelativeDirection = relVelocity.normalized;
_animator.SetFloat(VelocityMagnitude, relVelocity.magnitude);
_animator.SetFloat(DirectionX, moveRelativeDirection.x);
_animator.SetFloat(DirectionZ, moveRelativeDirection.z);
_animator.SetFloat(MoveAnimSpeed, moveAnimSpeed);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2196f6792fb64519a9c02abec4cad026
timeCreated: 1767463517
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6a57c1cd622649c0ab87034a023c1ae6
timeCreated: 1766851215
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 46cdb0a558204291b86aab452972e23e
timeCreated: 1766851215
@@ -0,0 +1,68 @@
using System;
using System.Collections;
using RPGCore.Movement.ObjectModules.UnitMovement.Events;
using RPGCore.ObjectModules.ActionObjectModule;
using RPGCore.ObjectModules.EventObjectModule;
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule;
using RPGCoreCommon.Settings;
using UnityEngine;
namespace RPGCore.Movement.ObjectModules.UnitMovement.Actions
{
public class DirectionMoveAction : BaseActionParallel
{
private readonly Func<Vector3> _directionGetter;
private StatusDefinitionSO _runStatusDefinitionSO;
private StatusModule _unitStatus;
private UnitMovementModule _unitMovement;
public DirectionMoveAction(Func<Vector3> directionGetter)
{
_directionGetter = directionGetter;
}
public override void CanDoIt()
{
Check(
unit.GetComponent<StatusModule>().IsControllable(),
UnitIsBusyMessage);
}
protected override void OnDoIt()
{
_runStatusDefinitionSO = SettingsManager.Get<MovementSettings>().runStatusDefinitionSO;
_unitStatus = unit.GetComponent<StatusModule>();
_unitMovement = unit.GetComponent<UnitMovementModule>();
var moveStartEvent = new MoveStartEvent{ unit = unit };
unit.events.InvokeBefore(moveStartEvent);
Check(!moveStartEvent.isPrevented, ActionWasPreventedMessage);
unit.events.InvokeAfter(moveStartEvent);
unit.StartCoroutine(MoveCoroutine());
}
private IEnumerator MoveCoroutine()
{
while (state == ActionState.Running)
{
_unitMovement.moveInput = _directionGetter();
yield return new WaitForFixedUpdate();
}
}
protected override void OnEndIt()
{
_unitMovement.moveInput = Vector2.zero;
_unitStatus.Remove(_runStatusDefinitionSO);
unit.events.Invoke(new MoveEndEvent{ unit = unit });
}
protected override void OnCancelIt()
{
OnEndIt();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e1c38778027246d1afc2fa822bc9826b
timeCreated: 1766851215

Some files were not shown because too many files have changed in this diff Show More