init
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2fbc304c5594cabb12a0acf46d2a65b
|
||||
timeCreated: 1731858740
|
||||
@@ -0,0 +1,16 @@
|
||||
using VOID.Generic.Dict;
|
||||
using VOID.Generic.Objects.Abstract.Events;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
namespace VOID.Generic.Objects.Wearable.Events
|
||||
{
|
||||
public class EquipEvent : AbstractEvent
|
||||
{
|
||||
public bool prevented = false;
|
||||
|
||||
public WearableObject wearable;
|
||||
public UnitObject unit;
|
||||
public int slotIndex;
|
||||
public EquipmentSlotType slotType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca18a2eb79784873a2d3ec91e0039c0e
|
||||
timeCreated: 1672745226
|
||||
@@ -0,0 +1,13 @@
|
||||
using VOID.Generic.Objects.Abstract.Events;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
namespace VOID.Generic.Objects.Wearable.Events
|
||||
{
|
||||
public class UnEquipEvent : AbstractEvent
|
||||
{
|
||||
public bool prevented = false;
|
||||
|
||||
public WearableObject wearable;
|
||||
public UnitObject unit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8140167085e42d8a0de7e07e04e1902
|
||||
timeCreated: 1672745241
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Sirenix.OdinInspector;
|
||||
using VOID.Generic.Objects.Item;
|
||||
|
||||
namespace VOID.Generic.Objects.Wearable
|
||||
{
|
||||
public abstract class WearableObject : ItemObject
|
||||
{
|
||||
[Title("=== WearableObject properties ===")]
|
||||
public WearableObjectData wearableData;
|
||||
public WearableObjectEvents wearableEvents;
|
||||
public WearableObjectState wearableState;
|
||||
|
||||
protected override List<ObjectComponent> GetObjectComponents()
|
||||
{
|
||||
return base.GetObjectComponents()
|
||||
.Union(new List<ObjectComponent>
|
||||
{
|
||||
wearableData,
|
||||
wearableEvents,
|
||||
wearableState
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7186ede973a44313b465b6b2ecddb353
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 8859e69b12a7faa41b864ccf36e88a91, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Requirement;
|
||||
using VOID.Generic.Status.Effect;
|
||||
|
||||
namespace VOID.Generic.Objects.Wearable
|
||||
{
|
||||
[Serializable]
|
||||
public class WearableObjectData : ObjectComponent<WearableObject>
|
||||
{
|
||||
#region Initialize
|
||||
|
||||
protected override void SelfInitialize()
|
||||
{
|
||||
parent.itemData.stackable = false;
|
||||
parent.itemData.stackSize = 1;
|
||||
parent.itemData.stackSizeMax = 1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Title("Equip Effects")]
|
||||
[SerializeReference] public List<BasicEffect> effects = new();
|
||||
|
||||
[Title("Equip Requirements")]
|
||||
[SerializeReference]
|
||||
public List<IUnitRequirement> requirements = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27f88a9d00d54dc098919d5b0dc2a74f
|
||||
timeCreated: 1670866035
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using VOID.Generic.Objects.Item.Events;
|
||||
using VOID.Generic.Objects.Wearable.Events;
|
||||
|
||||
namespace VOID.Generic.Objects.Wearable
|
||||
{
|
||||
[System.Serializable]
|
||||
public class WearableObjectEvents : ObjectComponent<WearableObject>
|
||||
{
|
||||
[Header("Equipped & UnEquipped")]
|
||||
public UnityEvent<EquipEvent> onEquippedBefore;
|
||||
public UnityEvent<EquipEvent> onEquippedAfter;
|
||||
public UnityEvent<UnEquipEvent> onUnEquippedBefore;
|
||||
public UnityEvent<UnEquipEvent> onUnEquippedAfter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfd636c156b84f368488a6d709ae534e
|
||||
timeCreated: 1670864346
|
||||
@@ -0,0 +1,100 @@
|
||||
using System.Linq;
|
||||
using InfinityPBR.ModularCharacterHelper;
|
||||
using Sirenix.Utilities;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Objects.Item.Events;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
using VOID.Generic.Objects.Wearable;
|
||||
using VOID.Generic.Objects.Wearable.Events;
|
||||
using VOID.ScriptableObjects;
|
||||
|
||||
namespace VOID.Generic.Objects.Item
|
||||
{
|
||||
[System.Serializable]
|
||||
public class WearableObjectState : ObjectComponent<WearableObject>
|
||||
{
|
||||
#region Initialize
|
||||
|
||||
protected override void EventInitialize()
|
||||
{
|
||||
parent.itemEvents.onDroppedAfter.AddListener(OnDropped);
|
||||
parent.wearableEvents.onEquippedAfter.AddListener(OnEquip);
|
||||
parent.wearableEvents.onUnEquippedAfter.AddListener(OnUnEquip);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public UnitObject wearerUnit { get; private set; }
|
||||
public BasicStatus equipStatus { get; private set; }
|
||||
|
||||
private GameObject _equipModelGameObject;
|
||||
|
||||
private void OnDropped(DropEvent dropEvent)
|
||||
{
|
||||
EndEquipStatus();
|
||||
wearerUnit = null;
|
||||
}
|
||||
|
||||
private void OnEquip(EquipEvent equipEvent)
|
||||
{
|
||||
wearerUnit = equipEvent.unit;
|
||||
ApplyEquipStatus();
|
||||
ShowEquipModel();
|
||||
}
|
||||
|
||||
private void OnUnEquip(UnEquipEvent unEquipEvent)
|
||||
{
|
||||
EndEquipStatus();
|
||||
HideEquipModel();
|
||||
wearerUnit = null;
|
||||
}
|
||||
|
||||
private void ApplyEquipStatus()
|
||||
{
|
||||
if (parent.wearableData.effects.Count <= 0) return;
|
||||
|
||||
equipStatus = ScriptableObject.CreateInstance<BasicStatus>();
|
||||
equipStatus.name = $"EquipStatus: {wearerUnit.gameObject.name}";
|
||||
equipStatus.effects = parent.wearableData.effects;
|
||||
equipStatus.permanent = true;
|
||||
equipStatus.hidden = true;
|
||||
|
||||
wearerUnit.statusManager.AddStatus(equipStatus, wearerUnit, false);
|
||||
}
|
||||
|
||||
private void EndEquipStatus()
|
||||
{
|
||||
if (!equipStatus) return;
|
||||
|
||||
equipStatus.Cancel();
|
||||
equipStatus = null;
|
||||
}
|
||||
|
||||
private void ShowEquipModel()
|
||||
{
|
||||
var modularCharacter = wearerUnit.unitState.modularCharacter;
|
||||
if (!modularCharacter) return;
|
||||
|
||||
// GameObject container for all parts
|
||||
_equipModelGameObject = new GameObject($"{parent.name} - equip model");
|
||||
_equipModelGameObject.transform.parent = wearerUnit.transform;
|
||||
|
||||
// Find all matching parts that can be attached to unit's rig
|
||||
parent
|
||||
.GetComponentsInChildren<ModularPart>(true)
|
||||
.Where(modularPart => modularPart.avatar == modularCharacter.avatar)
|
||||
.Select(modularPart => Object.Instantiate(modularPart.gameObject).GetComponent<ModularPart>())
|
||||
.ForEach(modularPart =>
|
||||
{
|
||||
modularPart.gameObject.transform.parent = _equipModelGameObject.transform;
|
||||
modularCharacter.AttachPart(modularPart);
|
||||
});
|
||||
}
|
||||
|
||||
private void HideEquipModel()
|
||||
{
|
||||
if (_equipModelGameObject) Object.Destroy(_equipModelGameObject);
|
||||
_equipModelGameObject = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45deeea83b834a1bb99f49af704141e7
|
||||
timeCreated: 1672751435
|
||||
Reference in New Issue
Block a user