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,81 @@
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using UnityEngine;
using VOID.Generic.Objects.Abstract;
using VOID.Generic.Objects.Door.Events;
using VOID.Generic.Objects.Unit;
namespace VOID.Generic.Objects.Door
{
[RequireComponent(typeof(Animator))]
public class DoorObject : AbstractObject
{
[Title("=== Door properties ===")]
public DoorObjectEvents doorEvents;
public DoorObjectState doorState;
public DoorObjectAnimator doorAnimator;
protected new void OnValidate()
{
base.OnValidate();
gameObject.GetComponent<Animator>().hideFlags = HideFlags.NotEditable;
}
protected override List<ObjectComponent> GetObjectComponents()
{
return base.GetObjectComponents()
.Union(new List<ObjectComponent>
{
doorEvents,
doorState,
doorAnimator
})
.ToList();
}
[Button]
public void Open(UnitObject unit = null)
{
if (doorState.isLocked) return;
doorEvents.onOpen.Invoke(new DoorEvent
{
door = this,
unit = unit
});
}
[Button]
public void Close(UnitObject unit = null)
{
doorEvents.onClose.Invoke(new DoorEvent
{
door = this,
unit = unit
});
}
[Button]
public void Lock(UnitObject unit = null)
{
if (doorState.isOpen) return;
doorEvents.onLock.Invoke(new DoorEvent
{
door = this,
unit = unit
});
}
[Button]
public void Unlock(UnitObject unit = null)
{
doorEvents.onUnlock.Invoke(new DoorEvent
{
door = this,
unit = unit
});
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 134e091633404623a85e54fea54b3651
timeCreated: 1707831925
@@ -0,0 +1,37 @@
using Sirenix.OdinInspector;
using UnityEditor.Animations;
using UnityEngine;
namespace VOID.Generic.Objects.Door
{
[System.Serializable]
public class DoorObjectAnimator : ObjectComponent<DoorObject>
{
#region Initialize
protected override void SelfInitialize()
{
_animator = parent.GetComponent<Animator>();
_animator.runtimeAnimatorController = Object.Instantiate(animatorController);
}
#endregion
private static readonly int TriggerOpen = Animator.StringToHash("TRIGGER_OPEN");
private static readonly int TriggerClose = Animator.StringToHash("TRIGGER_CLOSE");
private Animator _animator;
[SerializeField, Required] private AnimatorController animatorController;
public void PlayOpen()
{
_animator.SetTrigger(TriggerOpen);
}
public void PlayClose()
{
_animator.SetTrigger(TriggerClose);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 38f56c92901e4ff18f207fcdbb536a76
timeCreated: 1707845796
@@ -0,0 +1,17 @@
using System;
using Sirenix.OdinInspector;
using UnityEngine.Events;
using VOID.Generic.Objects.Door.Events;
namespace VOID.Generic.Objects.Door
{
[Serializable]
public class DoorObjectEvents : ObjectComponent<DoorObject>
{
[Title("Opening & Closing")]
public UnityEvent<DoorEvent> onOpen;
public UnityEvent<DoorEvent> onClose;
public UnityEvent<DoorEvent> onLock;
public UnityEvent<DoorEvent> onUnlock;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 647f2a1fd449473fa329598a924293c2
timeCreated: 1707834284
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.AI;
using VOID.Generic.Navigation;
using VOID.Generic.Objects.Door.Events;
using VOID.Generic.Objects.Door.State;
namespace VOID.Generic.Objects.Door
{
[Serializable]
public class DoorObjectState : ObjectComponent<DoorObject>
{
#region Initialize
protected override void SelfInitialize()
{
_doorObstacles = parent.GetComponents<NavMeshObstacle>().ToList();
parent.GetComponentInChildren<DoorOpenerTrigger>().door = parent;
}
protected override void EventInitialize()
{
parent.doorEvents.onOpen.AddListener(OnOpen);
parent.doorEvents.onClose.AddListener(OnClose);
parent.doorEvents.onLock.AddListener(OnLock);
parent.doorEvents.onUnlock.AddListener(OnUnlock);
}
protected override void Initialize()
{
if (isOpen)
{
parent.Unlock();
parent.Open();
return;
}
if (isLocked)
{
parent.Close();
parent.Lock();
return;
}
parent.Close();
parent.Unlock();
}
#endregion
private List<NavMeshObstacle> _doorObstacles;
[DisableInPlayMode] public bool isOpen;
[DisableInPlayMode] public bool isLocked;
private void OnOpen(DoorEvent doorEvent)
{
isOpen = true;
parent.doorAnimator.PlayOpen();
}
private void OnClose(DoorEvent doorEvent)
{
isOpen = false;
parent.doorAnimator.PlayClose();
}
private void OnLock(DoorEvent doorEvent)
{
isLocked = true;
_doorObstacles.ForEach(obstacle => obstacle.enabled = true);
NavigationManager.current.UpdateNavMesh(new Bounds(parent.transform.position, Vector3.one * parent.basicData.radius));
}
private void OnUnlock(DoorEvent doorEvent)
{
isLocked = false;
_doorObstacles.ForEach(obstacle => obstacle.enabled = false);
NavigationManager.current.UpdateNavMesh(new Bounds(parent.transform.position, Vector3.one * parent.basicData.radius));
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b3f06f11936447ab873d886285686e5f
timeCreated: 1707831925
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1bf4fd5ef34247ffb5c5ec67428bb145
timeCreated: 1707834322
@@ -0,0 +1,11 @@
using VOID.Generic.Objects.Abstract.Events;
using VOID.Generic.Objects.Unit;
namespace VOID.Generic.Objects.Door.Events
{
public class DoorEvent : AbstractEvent
{
public DoorObject door;
public UnitObject unit;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4fbbff99398b4b66a564e241909a66fc
timeCreated: 1707835249
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3885ec636a8640d0bac953c4a2e80f4a
timeCreated: 1707919778
@@ -0,0 +1,34 @@
using UnityEngine;
using VOID.Generic.Objects.Abstract;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Triggers;
namespace VOID.Generic.Objects.Door.State
{
public class DoorOpenerTrigger : MonoBehaviour, IDynamicTrigger
{
#region ParentGetterSetter
private DoorObject _door;
public DoorObject door
{
get => _door;
set
{
if (!_door) _door = value;
else Debug.LogWarning("Trying to set parent object " + _door.name + " again.");
}
}
#endregion
public void OnObjectEnter(AbstractObject obj)
{
if (obj is UnitObject && !door.doorState.isOpen) door.Open();
}
public void OnObjectExit(AbstractObject obj)
{
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: abf38a00ee3f4f50bcd018cd92d5034c
timeCreated: 1707919809