From 5a994cc3f35dc029920e599ed7ce3c0fc2c86464 Mon Sep 17 00:00:00 2001 From: stilnat Date: Thu, 24 Oct 2024 02:09:06 +0200 Subject: [PATCH] add sit as interaction procedural --- .../Entities/Humanoids/Human/UberHuman.prefab | 107 +++++++--------- .../SS3D/Interactions/InteractionType.cs | 1 + .../ProceduralAnimationController.cs | 14 ++- Assets/Scripts/SS3D/Systems/Animations/Sit.cs | 114 +++++------------- .../SS3D/Systems/Animations/SitInteraction.cs | 91 ++++++++++++++ .../Systems/Animations/SitInteraction.cs.meta | 11 ++ .../SS3D/Systems/Furniture/Sittable.cs | 13 +- 7 files changed, 196 insertions(+), 155 deletions(-) create mode 100644 Assets/Scripts/SS3D/Systems/Animations/SitInteraction.cs create mode 100644 Assets/Scripts/SS3D/Systems/Animations/SitInteraction.cs.meta diff --git a/Assets/Content/WorldObjects/Entities/Humanoids/Human/UberHuman.prefab b/Assets/Content/WorldObjects/Entities/Humanoids/Human/UberHuman.prefab index ae6001774..eb878e6db 100644 --- a/Assets/Content/WorldObjects/Entities/Humanoids/Human/UberHuman.prefab +++ b/Assets/Content/WorldObjects/Entities/Humanoids/Human/UberHuman.prefab @@ -149,7 +149,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 24 + _componentIndexCache: 22 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -1040,7 +1040,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 21 + _componentIndexCache: 19 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -1390,7 +1390,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 57 + _componentIndexCache: 55 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -1728,7 +1728,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 40 + _componentIndexCache: 38 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 0 @@ -2841,7 +2841,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 41 + _componentIndexCache: 39 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -3194,7 +3194,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e60c09e136263a44eb7996c9a5dc742a, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 25 + _componentIndexCache: 23 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _handHoldTargetLocker: {fileID: 5441267867618792388} @@ -3230,7 +3230,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 26 + _componentIndexCache: 24 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -3769,7 +3769,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 34 + _componentIndexCache: 32 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -3851,7 +3851,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 32 + _componentIndexCache: 30 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -4028,7 +4028,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 43 + _componentIndexCache: 41 _addedNetworkObject: {fileID: 7892022672265885063, guid: 4a9d34a6cf84ef045a740513d8ae30b1, type: 3} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -4346,7 +4346,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 33 + _componentIndexCache: 31 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -4532,7 +4532,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 23 + _componentIndexCache: 21 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -4781,7 +4781,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 44 + _componentIndexCache: 42 _addedNetworkObject: {fileID: 7892022672265885063, guid: 4a9d34a6cf84ef045a740513d8ae30b1, type: 3} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -5237,7 +5237,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 47 + _componentIndexCache: 45 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -5282,7 +5282,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 555a9241a5054d04cbb220278204f9b7, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 48 + _componentIndexCache: 46 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} --- !u!1 &3549033138117458215 @@ -5531,7 +5531,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 56 + _componentIndexCache: 54 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -6162,7 +6162,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 50 + _componentIndexCache: 48 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -6332,7 +6332,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 49 + _componentIndexCache: 47 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -6961,7 +6961,6 @@ GameObject: - component: {fileID: 2744598832793855224} - component: {fileID: 814667727278639600} - component: {fileID: 3265741626988572248} - - component: {fileID: 6345364980800757135} - component: {fileID: 5257508295790914349} - component: {fileID: 909431137198346835} - component: {fileID: 8621494274385040166} @@ -7090,11 +7089,9 @@ MonoBehaviour: - {fileID: 2744598832793855224} - {fileID: 814667727278639600} - {fileID: 3265741626988572248} - - {fileID: 6345364980800757135} - {fileID: 5257508295790914349} - {fileID: 909431137198346835} - {fileID: 8621494274385040166} - - {fileID: 0} - {fileID: 2768583506857238720} - {fileID: 7601720951202063522} - {fileID: 8615535220686661918} @@ -7587,23 +7584,6 @@ MonoBehaviour: _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _intent: 0 ---- !u!114 &6345364980800757135 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4089496606853742746} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 8c567fc47e27cb948ade338fde3d1b2f, type: 3} - m_Name: - m_EditorClassIdentifier: - _componentIndexCache: 13 - _addedNetworkObject: {fileID: 241836927429143711} - _networkObjectCache: {fileID: 241836927429143711} - _animatorController: {fileID: 4083960901991266909} - _movement: {fileID: 313020066527916364} --- !u!114 &5257508295790914349 MonoBehaviour: m_ObjectHideFlags: 0 @@ -7616,7 +7596,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3c75d17834848bb4f83ee6e730a65519, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 14 + _componentIndexCache: 13 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _openState: 0 @@ -7634,7 +7614,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3c75d17834848bb4f83ee6e730a65519, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 15 + _componentIndexCache: 14 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _openState: 0 @@ -7652,7 +7632,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f4ff32dc0709afc4990941dc6637c6f9, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 16 + _componentIndexCache: 15 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _aimTarget: {fileID: 2856800849451305125} @@ -7674,7 +7654,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c820c500b2966a940907fe7f9855c107, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 18 + _componentIndexCache: 16 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _armatureRoot: {fileID: 3362543718434004155} @@ -7695,7 +7675,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 524774ef343211042b18bd7442ba4ee5, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 19 + _componentIndexCache: 17 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _ragdoll: {fileID: 2768583506857238720} @@ -7712,7 +7692,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7caa3b96ae405e74d9512d65caf2385f, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 20 + _componentIndexCache: 18 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} k__BackingField: {fileID: 5358384094254398678} @@ -7720,6 +7700,7 @@ MonoBehaviour: k__BackingField: {fileID: 2851688491558728783} k__BackingField: {fileID: 7568747683536695618} k__BackingField: {fileID: 4083960901991266909} + k__BackingField: {fileID: 313020066527916364} k__BackingField: {fileID: 3222345056416986628} --- !u!1 &4092542307493577921 GameObject: @@ -8137,7 +8118,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 36 + _componentIndexCache: 34 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -8296,7 +8277,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 22 + _componentIndexCache: 20 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -8407,7 +8388,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 42 + _componentIndexCache: 40 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -9141,7 +9122,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 54 + _componentIndexCache: 52 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -9472,7 +9453,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 35 + _componentIndexCache: 33 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -9844,7 +9825,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 55 + _componentIndexCache: 53 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -10859,7 +10840,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 37 + _componentIndexCache: 35 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -11033,7 +11014,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 53 + _componentIndexCache: 51 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -11204,7 +11185,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 45 + _componentIndexCache: 43 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -11249,7 +11230,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 555a9241a5054d04cbb220278204f9b7, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 46 + _componentIndexCache: 44 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} --- !u!1 &7409137361464878030 @@ -11860,7 +11841,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 39 + _componentIndexCache: 37 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -12235,7 +12216,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 31 + _componentIndexCache: 29 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -12435,7 +12416,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 29 + _componentIndexCache: 27 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -13120,7 +13101,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e60c09e136263a44eb7996c9a5dc742a, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 27 + _componentIndexCache: 25 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _handHoldTargetLocker: {fileID: 2712046360455809814} @@ -13156,7 +13137,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 28 + _componentIndexCache: 26 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -13459,7 +13440,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 52 + _componentIndexCache: 50 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -13840,7 +13821,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 51 + _componentIndexCache: 49 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 @@ -14215,7 +14196,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 25696236470760b41b375e9b6939444c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 38 + _componentIndexCache: 36 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _automaticContainerSetUp: 1 @@ -14647,7 +14628,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3} m_Name: m_EditorClassIdentifier: - _componentIndexCache: 30 + _componentIndexCache: 28 _addedNetworkObject: {fileID: 241836927429143711} _networkObjectCache: {fileID: 241836927429143711} _componentConfiguration: 0 diff --git a/Assets/Scripts/SS3D/Interactions/InteractionType.cs b/Assets/Scripts/SS3D/Interactions/InteractionType.cs index 9d9240f15..296b993f1 100644 --- a/Assets/Scripts/SS3D/Interactions/InteractionType.cs +++ b/Assets/Scripts/SS3D/Interactions/InteractionType.cs @@ -14,5 +14,6 @@ public enum InteractionType Pickup, Place, Grab, + Sit, } } diff --git a/Assets/Scripts/SS3D/Systems/Animations/ProceduralAnimationController.cs b/Assets/Scripts/SS3D/Systems/Animations/ProceduralAnimationController.cs index 1f10b796a..abfe3cd37 100644 --- a/Assets/Scripts/SS3D/Systems/Animations/ProceduralAnimationController.cs +++ b/Assets/Scripts/SS3D/Systems/Animations/ProceduralAnimationController.cs @@ -23,16 +23,19 @@ public class ProceduralAnimationController : NetworkActor public HoldController HoldController { get; private set; } [field: SerializeField] - public MultiAimConstraint LookAtConstraint {get; private set; } + public MultiAimConstraint LookAtConstraint { get; private set; } [field: SerializeField] - public PositionController PositionController {get; private set; } + public PositionController PositionController { get; private set; } [field: SerializeField] - public HumanoidAnimatorController AnimatorController {get; private set; } + public HumanoidAnimatorController AnimatorController { get; private set; } [field: SerializeField] - public Hands Hands {get; private set; } + public HumanoidLivingController MovementController { get; private set; } + + [field: SerializeField] + public Hands Hands { get; private set; } // We can't have more than one procedural animation running at the same time per hand private List> _animations = new(); @@ -65,6 +68,9 @@ public void ObserversPlayAnimation(InteractionType interactionType, Hand mainHan case InteractionType.Grab: proceduralAnimation = new GrabAnimation(); break; + case InteractionType.Sit: + proceduralAnimation = new Sit(); + break; default: return; diff --git a/Assets/Scripts/SS3D/Systems/Animations/Sit.cs b/Assets/Scripts/SS3D/Systems/Animations/Sit.cs index 7d77fc0f3..95d8dd5ab 100644 --- a/Assets/Scripts/SS3D/Systems/Animations/Sit.cs +++ b/Assets/Scripts/SS3D/Systems/Animations/Sit.cs @@ -1,123 +1,63 @@ +using DG.Tweening; using FishNet.Object; +using SS3D.Interactions; using SS3D.Systems.Entities.Humanoid; using SS3D.Systems.Furniture; +using SS3D.Systems.Interactions; +using SS3D.Systems.Inventory.Containers; using SS3D.Utils; +using System; using System.Collections; using UnityEngine; using UnityEngine.Serialization; namespace SS3D.Systems.Animations { - public class Sit : NetworkBehaviour + public class Sit : IProceduralAnimation { + public event Action OnCompletion; - [SerializeField] - private HumanoidAnimatorController _animatorController; + private ProceduralAnimationController _controller; - [SerializeField] - private HumanoidController _movement; + private Sequence _sitSequence; - public override void OnStartClient() - { - base.OnStartClient(); - if (!GetComponent().IsOwner) - { - enabled = false; - } - } - - protected void Update() - { - if (!Input.GetKeyDown(KeyCode.J)) - { - return; - } - - if (GetComponent().Position == PositionType.Standing && CanSit(out Sittable sit)) - { - RcpSit(sit); - } - else if (GetComponent().Position == PositionType.Sitting) - { - RcpStopSitting(); - } - } - - [ServerRpc] - private void RcpSit(Sittable sit) - { - ObserversSit(sit); - } - - [ObserversRpc] - private void ObserversSit(Sittable sit) - { - StartCoroutine(AnimateSit(sit.transform)); + public void ServerPerform(InteractionType interactionType, Hand mainHand, Hand secondaryHand, NetworkBehaviour target, Vector3 targetPosition, ProceduralAnimationController proceduralAnimationController, float time, float delay) + { + } - [ServerRpc] - private void RcpStopSitting() + public void ClientPlay(InteractionType interactionType, Hand mainHand, Hand secondaryHand, NetworkBehaviour target, Vector3 targetPosition, ProceduralAnimationController proceduralAnimationController, float time, float delay) { - ObserversStopSitting(); + _controller = proceduralAnimationController; + AnimateSit(target.transform); } - [ServerRpc] - private void ObserversStopSitting() + public void Cancel() { - StopSitting(); - } - - private bool CanSit(out Sittable sit) - { - // Cast a ray from the mouse position into the scene - Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); - - // Check if the ray hits any collider - if (Physics.Raycast(ray, out RaycastHit hit)) - { - // Check if the collider belongs to a GameObject - GameObject obj = hit.collider.gameObject; - - if (obj.TryGetComponent(out Sittable sit2) && GoodDistanceFromRootToSit(sit2.transform)) - { - sit = sit2; - - return true; - } - } - sit = null; - - return false; } - private IEnumerator AnimateSit(Transform sitOrientation) + private void AnimateSit(Transform sit) { - _movement.enabled = false; - - _animatorController.Sit(true); + _controller.MovementController.enabled = false; - Vector3 initialRotation = transform.eulerAngles; + _controller.AnimatorController.Sit(true); - Vector3 initialPosition = transform.position; + _sitSequence = DOTween.Sequence(); - StartCoroutine(CoroutineHelper.ModifyVector3OverTime(x => transform.eulerAngles = x, initialRotation, sitOrientation.eulerAngles, 0.5f)); + _sitSequence.Join(_controller.transform.DOMove(sit.position, 0.5f)); + _sitSequence.Join(_controller.transform.DORotate(sit.rotation.eulerAngles, 0.5f)); - yield return CoroutineHelper.ModifyVector3OverTime(x => transform.position = x, initialPosition, sitOrientation.position, 0.5f); + _controller.PositionController.Position = PositionType.Sitting; - GetComponent().Position = PositionType.Sitting; + _sitSequence.OnComplete(() => OnCompletion?.Invoke(this)); } private void StopSitting() { - _movement.enabled = true; - _animatorController.Sit(false); - GetComponent().Position = PositionType.Standing; - } - - private bool GoodDistanceFromRootToSit(Transform sit) - { - return Vector3.Distance(transform.position, sit.position) < 0.8f; + _controller.MovementController.enabled = true; + _controller.AnimatorController.Sit(false); + _controller.PositionController.Position = PositionType.Standing; } } } diff --git a/Assets/Scripts/SS3D/Systems/Animations/SitInteraction.cs b/Assets/Scripts/SS3D/Systems/Animations/SitInteraction.cs new file mode 100644 index 000000000..a8c7fe98d --- /dev/null +++ b/Assets/Scripts/SS3D/Systems/Animations/SitInteraction.cs @@ -0,0 +1,91 @@ +using SS3D.Data.Generated; +using SS3D.Interactions; +using SS3D.Interactions.Extensions; +using SS3D.Systems.Entities; +using SS3D.Systems.Furniture; +using SS3D.Systems.Interactions; +using SS3D.Systems.Inventory.Containers; +using UnityEngine; + +namespace SS3D.Systems.Animations +{ + public class SitInteraction : Interaction + { + + public float TimeToSit{ get; private set; } + + /// + /// Only raycast the default layer for seeing if we are vision blocked + /// + private LayerMask _defaultMask = LayerMask.GetMask("Default"); + + public override InteractionType InteractionType => InteractionType.Sit; + + public SitInteraction(float timeToSit) + { + TimeToSit = timeToSit; + } + + public override string GetName(InteractionEvent interactionEvent) + { + return "Sit"; + } + + public override string GetGenericName() => "Sit"; + + public override Sprite GetIcon(InteractionEvent interactionEvent) + { + return Icon ? Icon : InteractionIcons.Discard; + } + + public override bool CanInteract(InteractionEvent interactionEvent) + { + if (!interactionEvent.Target.GetGameObject().TryGetComponent(out Sittable sit)) + { + return false; + } + + if (!GoodDistanceFromRootToSit(sit.transform, interactionEvent.Source.GameObject.transform)) + { + return false; + } + + return true; + } + + private bool GoodDistanceFromRootToSit(Transform sit, Transform playerRoot) + { + return Vector3.Distance(playerRoot.position, sit.position) < 2f; + } + + public override bool Start(InteractionEvent interactionEvent, InteractionReference reference) + { + Hand hand = interactionEvent.Source.GetRootSource() as Hand; + + if (interactionEvent.Target is not Sittable sit) + { + return false; + } + + hand.GetComponentInParent().PlayAnimation(InteractionType.Sit, hand, sit, interactionEvent.Point, TimeToSit); + + return false; + } + + public override void Cancel(InteractionEvent interactionEvent, InteractionReference reference) + { + Debug.Log("attempting to cancel animation"); + + // We don't want to cancel the interaction if the item is already dropped + /*if (_hasDroppedItem) + { + return; + } */ + + if (interactionEvent.Source.GetRootSource() is Hand hand && hand.ItemInHand != null) + { + hand.GetComponentInParent().CancelAnimation(hand); + } + } + } +} diff --git a/Assets/Scripts/SS3D/Systems/Animations/SitInteraction.cs.meta b/Assets/Scripts/SS3D/Systems/Animations/SitInteraction.cs.meta new file mode 100644 index 000000000..baaa4db52 --- /dev/null +++ b/Assets/Scripts/SS3D/Systems/Animations/SitInteraction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: daca1ddbca7a0b8438bd690f7962727b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/SS3D/Systems/Furniture/Sittable.cs b/Assets/Scripts/SS3D/Systems/Furniture/Sittable.cs index f36d3ec6a..569011c2a 100644 --- a/Assets/Scripts/SS3D/Systems/Furniture/Sittable.cs +++ b/Assets/Scripts/SS3D/Systems/Furniture/Sittable.cs @@ -1,11 +1,22 @@ using FishNet.Object; +using SS3D.Core.Behaviours; +using SS3D.Interactions; +using SS3D.Interactions.Extensions; +using SS3D.Interactions.Interfaces; +using System; using UnityEngine; using UnityEngine.Serialization; namespace SS3D.Systems.Furniture { - public class Sittable : NetworkBehaviour + public class Sittable : NetworkActor, IInteractionTarget { + public IInteraction[] CreateTargetInteractions(InteractionEvent interactionEvent) + { + return Array.Empty(); + } + + public bool TryGetInteractionPoint(IInteractionSource source, out Vector3 point) => this.GetInteractionPoint(source, out point); } }