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,25 @@
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using VOID.Generic.Objects.Wearable;
namespace VOID.Generic.Objects.Weapon
{
public class WeaponObject : WearableObject
{
[Title("=== WeaponObject properties ===")]
public WeaponObjectData weaponData;
public WeaponObjectState weaponState;
protected override List<ObjectComponent> GetObjectComponents()
{
return base.GetObjectComponents()
.Union(new List<ObjectComponent>
{
weaponData,
weaponState
})
.ToList();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2859cf9bd4bb4f2cbf6898d5fdc76a6f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: d3d84d6d3806ede46ace5362eb0bdf8e, type: 3}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,54 @@
using Sirenix.OdinInspector;
using UnityEngine;
using VOID.Generic.Dict;
using VOID.ScriptableObjects.Abilities;
namespace VOID.Generic.Objects.Weapon
{
[System.Serializable]
public class WeaponObjectData : ObjectComponent<WeaponObject>
{
#region Initialize
protected override void SelfInitialize()
{
if (handPoint)
{
// Calculate and cache - unit will hold weapon by this position and rotation - Transform defined in prefab
handRotationOffset = Quaternion.Inverse(handPoint.transform.localRotation);
handPositionOffset = handRotationOffset * handPoint.transform.localPosition * - 1;
}
if (secondHandPoint)
{
// Calculate and cache - mainly for two-handed weapons - it IK point for second hand
secondHandPositionOffset = handRotationOffset * secondHandPoint.transform.localPosition * - 1;
secondHandPositionOffset = handPositionOffset - secondHandPositionOffset;
}
}
#endregion
[Title("Visuals")]
[Required, ChildGameObjectsOnly] public GameObject model;
[Title("IK targets")]
[Required, ChildGameObjectsOnly] public GameObject handPoint;
public Quaternion handRotationOffset { get; private set; }
public Vector3 handPositionOffset { get; private set; }
[ChildGameObjectsOnly, ShowIf(nameof(weaponCarryType), WeaponCarryType.TwoHand)] public GameObject secondHandPoint;
public Vector3 secondHandPositionOffset { get; private set; }
[Title("Weapon attributes")]
public WeaponType weaponType;
public WeaponCarryType weaponCarryType;
public DamageType damageType;
[MinValue(0)] public int damageMin;
[MinValue(nameof(damageMin))] public int damageMax;
[MinValue(0)] public float criticalDamageChange;
[MinValue(1)] public float criticalDamageMultiplier;
[Title("Default Attack Ability")]
[Required] public BasicAttackAbility attackAbility;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b8d7601471b646cebc983202a109c43b
timeCreated: 1670867640
@@ -0,0 +1,58 @@
using System;
using UnityEngine;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Wearable.Events;
using Object = UnityEngine.Object;
namespace VOID.Generic.Objects.Weapon
{
[Serializable]
public class WeaponObjectState : ObjectComponent<WeaponObject>
{
#region Initialize
protected override void EventInitialize()
{
parent.wearableEvents.onEquippedAfter.AddListener(ShowEquipModel);
parent.wearableEvents.onUnEquippedAfter.AddListener(HideEquipModel);
}
#endregion
public GameObject equippedModel { get; private set; }
public GameObject equippedModelHandIK { get; private set; }
private void ShowEquipModel(EquipEvent equipEvent)
{
// Point (aka bone) where weapon's model will be attached
var equipPoint = equipEvent.slotType switch
{
EquipmentSlotType.MainHand when parent.weaponData.weaponType is WeaponType.Bow => equipEvent.unit.unitData.leftHandPosition,
EquipmentSlotType.MainHand => equipEvent.unit.unitData.rightHandPosition,
EquipmentSlotType.OffHand => equipEvent.unit.unitData.leftHandPosition,
_ => throw new Exception("Equipping weapon in slot other than 'MainHand' or 'OffHand'!")
};
// Instance of weapon's ONLY model
equippedModel = Object.Instantiate(parent.weaponData.model, equipPoint, false);
equippedModel.name = "_model";
equippedModel.transform.localRotation = parent.weaponData.handRotationOffset;
equippedModel.transform.localPosition = parent.weaponData.handPositionOffset;
// Instance of point for other hand IK
equippedModelHandIK = new GameObject();
equippedModelHandIK.name = "_ik_target";
equippedModelHandIK.transform.parent = equipPoint.transform;
equippedModelHandIK.transform.localRotation = parent.weaponData.handRotationOffset;
equippedModelHandIK.transform.localPosition = parent.weaponData.secondHandPositionOffset;
}
private void HideEquipModel(UnEquipEvent unEquipEvent)
{
Object.Destroy(equippedModel);
equippedModel = null;
Object.Destroy(equippedModelHandIK);
equippedModelHandIK = null;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0c1f81e3df1c4db4bb3b71e04ae19d98
timeCreated: 1737144869