Skip to content

Commit

Permalink
big cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Dec 8, 2024
1 parent bff6d8f commit 1946466
Show file tree
Hide file tree
Showing 30 changed files with 153 additions and 242 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ resharper_unity_inefficient_property_access_highlighting = hint
resharper_unity_load_scene_disabled_scene_name_highlighting = error
resharper_unity_load_scene_unexisting_scene_highlighting = error
resharper_unity_performance_critical_code_camera_main_highlighting = error
resharper_unity_performance_critical_code_invocation_highlighting = warning
resharper_unity_performance_critical_code_invocation_highlighting = hint
resharper_unity_performance_critical_code_null_comparison_highlighting = warning
resharper_unity_prefer_non_alloc_api_highlighting = error
resharper_unity_redundant_attribute_on_target_highlighting = error
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/SS3D/Hacks/RagdollWhenPressingButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override void OnStartClient()

private void HandleKnockdown(InputAction.CallbackContext context)
{
if (_positionController.Position != PositionType.Ragdoll)
if (_positionController.PositionType != PositionType.Ragdoll)
{
RpcKnockDown();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using DG.Tweening;
using FishNet.Object;
using SS3D.Systems.Interactions;
using JetBrains.Annotations;
using SS3D.Systems.Inventory.Containers;
using SS3D.Utils;
using System;
Expand Down Expand Up @@ -39,7 +38,7 @@ protected AbstractProceduralAnimation(float interactionTime, ProceduralAnimation
/// </summary>
protected void TryRotateTowardTargetPosition(Transform rootTransform, float rotateTime, Vector3 position)
{
if (Controller.PositionController.Position != PositionType.Sitting)
if (Controller.PositionController.PositionType != PositionType.Sitting)
{
InteractionSequence.Join(Controller.transform.DORotate(
QuaternionExtension.SameHeightPlaneLookRotation(position - rootTransform.position, Vector3.up).eulerAngles, rotateTime));
Expand All @@ -50,7 +49,7 @@ protected void TryRotateTowardTargetPosition(Transform rootTransform, float rota
/// Create a rotation of the IK target to make sure the hand reach in a natural way the item.
/// The rotation is such that it's Y axis is aligned with the line crossing through the character shoulder and IK target.
/// </summary>
protected void OrientTargetForHandRotation(Hand hand)
protected void OrientTargetForHandRotation([NotNull] Hand hand)
{
Vector3 armTargetDirection = hand.Hold.HandIkTarget.position - hand.Hold.UpperArm.position;

Expand All @@ -64,11 +63,11 @@ protected void OrientTargetForHandRotation(Hand hand)
/// <summary>
/// Adapt the position of the player interacting to make the animation look more natural, such as crouching when the interaction is too low.
/// </summary>
protected void AdaptPosition(PositionController positionController, Hand mainHand, Vector3 targetPosition)
protected void AdaptPosition(PositionController positionController, [NotNull] Hand mainHand, Vector3 targetPosition)
{
if (mainHand.HandBone.transform.position.y - targetPosition.y > 0.3)
{
_positionHasChanged = positionController.Position != PositionType.Crouching;
_positionHasChanged = positionController.PositionType != PositionType.Crouching;
positionController.TryCrouch();
}
}
Expand Down
4 changes: 1 addition & 3 deletions Assets/Scripts/SS3D/Systems/Animations/DraggableFurniture.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using SS3D.Interactions.Extensions;
using SS3D.Interactions.Interfaces;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// For furnitures that can be dragged
/// </summary>
public class DraggableFurniture : Draggable
public sealed class DraggableFurniture : Draggable
{
public override bool TryGetInteractionPoint(IInteractionSource source, out Vector3 point) => this.GetInteractionPoint(source, out point);

Expand Down
13 changes: 6 additions & 7 deletions Assets/Scripts/SS3D/Systems/Animations/GrabAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using SS3D.Systems.Inventory.Containers;
using System;
using UnityEngine;
using Object = UnityEngine.Object;

namespace SS3D.Systems.Animations
{
Expand All @@ -16,7 +17,7 @@ public class GrabAnimation : AbstractProceduralAnimation

private LayerMask _grabbableLayer;

private readonly float _jointBreakForce = 25000f;
private const float JointBreakForce = 500f;

private readonly float _itemReachDuration;

Expand Down Expand Up @@ -55,7 +56,7 @@ private void ReleaseGrab()

if (_fixedJoint is not null)
{
MonoBehaviour.Destroy(_fixedJoint);
Object.Destroy(_fixedJoint);
}

Sequence stopSequence = DOTween.Sequence();
Expand Down Expand Up @@ -98,10 +99,8 @@ private void GrabReach()
InteractionSequence.Join(DOTween.To(() => Controller.LookAtConstraint.weight, x => Controller.LookAtConstraint.weight = x, 1f, _itemReachDuration));

// At the same time change pickup constraint weight of the main hand from 0 to 1
InteractionSequence.Join(DOTween.To(() => _mainHand.Hold.PickupIkConstraint.weight, x => _mainHand.Hold.PickupIkConstraint.weight = x, 1f, _itemReachDuration).OnComplete(() =>
{
HandleGrabbing();
}));
InteractionSequence.Join(DOTween.To(() => _mainHand.Hold.PickupIkConstraint.weight, x => _mainHand.Hold.PickupIkConstraint.weight = x, 1f, _itemReachDuration)
.OnComplete(HandleGrabbing));

// Stop looking
InteractionSequence.Append(DOTween.To(() => Controller.LookAtConstraint.weight, x => Controller.LookAtConstraint.weight = x, 0f, _itemReachDuration));
Expand Down Expand Up @@ -135,7 +134,7 @@ private void HandleGrabbing()

_fixedJoint = Controller.GameObject.AddComponent<FixedJoint>();
_fixedJoint.connectedBody = grabbedRb;
_fixedJoint.breakForce = _jointBreakForce;
_fixedJoint.breakForce = JointBreakForce;
}
}
}
52 changes: 23 additions & 29 deletions Assets/Scripts/SS3D/Systems/Animations/HoldController.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
using DG.Tweening;
using FishNet.Object;
using FishNet.Object.Synchronizing;
using FishNet.Serializing;
using JetBrains.Annotations;
using SS3D.Core.Behaviours;
using SS3D.Interactions;
using SS3D.Systems.Entities.Humanoid;
using SS3D.Systems.Inventory.Containers;
using SS3D.Systems.Inventory.Items;
using SS3D.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Serialization;

namespace SS3D.Systems.Animations
{

/// <summary>
/// Handle the state of holding items and hand positions
/// </summary>
Expand All @@ -28,7 +25,7 @@ public class HoldController : NetworkActor
/// </summary>
private struct HandItem
{
public AbstractHoldable Holdable;
public readonly AbstractHoldable Holdable;
public Hand Hand;

public HandItem(Hand hand, AbstractHoldable holdable)
Expand Down Expand Up @@ -117,6 +114,7 @@ private sealed record HoldData(HandHoldType HandHoldType, Transform HoldTarget,




public override void OnStartServer()
{
base.OnStartServer();
Expand Down Expand Up @@ -153,6 +151,7 @@ protected override void OnAwake()
_holdData.Add(new(HandHoldType.ThrowSmallItem, _smallItemRightThrow, HandType.RightHand));
}


public void BringToHand(Hand hand, AbstractHoldable holdable, float duration)
{
StartCoroutine(CoroutineBringToHand(hand, holdable, duration));
Expand All @@ -163,9 +162,7 @@ public void BringToHand(Hand hand, AbstractHoldable holdable, float duration)
/// </summary>
/// <param name="hand"> The main hand holding the item</param>
/// <param name="item"> The item held</param>
/// <param name="withTwoHands"> If the item should be held with two hands </param>
/// <param name="duration"> The time in second to go from the current item position to its updated position</param>
/// <param name="toThrow"> True the item should be in a ready to throw position</param>
public void UpdateItemPositionConstraintAndRotation(
[NotNull] Hand hand, [NotNull] AbstractHoldable item, float duration)
{
Expand All @@ -185,10 +182,10 @@ public void UpdateItemPositionConstraintAndRotation(


// Do the same with interpolating rotation.
hand.Hold.ItemPositionConstraint.data.constrainedObject.DOLocalRotate(hold.localRotation.eulerAngles, duration); ;
hand.Hold.ItemPositionConstraint.data.constrainedObject.DOLocalRotate(hold.localRotation.eulerAngles, duration);
}

private IEnumerator CoroutineBringToHand(Hand hand, AbstractHoldable holdable, float duration)
private IEnumerator CoroutineBringToHand([NotNull] Hand hand, [NotNull] AbstractHoldable holdable, float duration)
{
Vector3 start = holdable.GameObject.transform.position;

Expand Down Expand Up @@ -251,19 +248,17 @@ private IEnumerator CoroutineBringToHand(Hand hand, AbstractHoldable holdable, f
/// </summary>
private void SyncItemsInHandsChanged(SyncListOperation op, int index, HandItem oldItem, HandItem newItem, bool asServer)
{
if (asServer)
{
return;
}
if (asServer) { return; }

if (op == SyncListOperation.Add || op == SyncListOperation.Insert || op == SyncListOperation.Set)
switch (op)
{
AddItem(newItem.Hand, newItem.Holdable);
}
case SyncListOperation.Add or SyncListOperation.Insert or SyncListOperation.Set:
AddItem(newItem.Hand, newItem.Holdable);
break;

if (op == SyncListOperation.RemoveAt)
{
RemoveItem(oldItem.Hand);
case SyncListOperation.RemoveAt:
RemoveItem(oldItem.Hand);
break;
}
}

Expand All @@ -279,7 +274,7 @@ private void RemoveItem(Hand hand)
}

[Client]
private void AddItem(Hand hand, AbstractHoldable holdable)
private void AddItem([NotNull] Hand hand, [NotNull] AbstractHoldable holdable)
{
BringToHand(hand, holdable, 0f);
UpdateItemPositionConstraintAndRotation(hand, holdable, 0f);
Expand All @@ -291,19 +286,19 @@ private void AddItem(Hand hand, AbstractHoldable holdable)
}

[Server]
private void HandleHandContentChanged(Hand hand, Item olditem, Item newitem, ContainerChangeType type)
private void HandleHandContentChanged(Hand hand, Item oldItem, Item newItem, ContainerChangeType type)
{
int handIndex = _itemsInHands.FindIndex(x => x.Hand = hand);

if (type == ContainerChangeType.Add)
{
if (handIndex == -1)
{
_itemsInHands.Add(new(hand, newitem.Holdable));
_itemsInHands.Add(new(hand, newItem.Holdable));
}
else
{
_itemsInHands[handIndex] = new(hand, newitem.Holdable);
_itemsInHands[handIndex] = new(hand, newItem.Holdable);
}
}

Expand Down Expand Up @@ -375,14 +370,13 @@ private Vector3 OffsetFromHoldTypeAndHand(HandHoldType handHoldType, HandType se
}

[Server]
private void HandleRagdoll(bool isRagdolled)
private void HandleRagdoll(bool isRagdoll)
{
if (isRagdolled)
if (!isRagdoll) { return; }

foreach (Hand hand in GetComponentsInChildren<Hand>())
{
foreach (Hand hand in GetComponentsInChildren<Hand>())
{
hand.DropHeldItem();
}
hand.DropHeldItem();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using FishNet.Object;
using SS3D.Systems.Interactions;
using SS3D.Systems.Inventory.Containers;
using System;
using UnityEngine;
using UnityEngine.Animations.Rigging;

namespace SS3D.Systems.Animations
{
Expand Down
7 changes: 0 additions & 7 deletions Assets/Scripts/SS3D/Systems/Animations/InteractAnimations.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using DG.Tweening;
using FishNet.Object;
using SS3D.Systems.Crafting;
using SS3D.Systems.Entities.Humanoid;
using SS3D.Systems.Interactions;
using SS3D.Systems.Inventory.Containers;
using SS3D.Utils;
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Animations.Rigging;

namespace SS3D.Systems.Animations
{
Expand All @@ -29,8 +25,6 @@ public class InteractAnimations : AbstractProceduralAnimation

private readonly Vector3 _targetPosition;

private readonly Transform _toolParent;

public InteractAnimations(ProceduralAnimationController proceduralAnimationController, float time, Hand mainHand, NetworkBehaviour target, InteractionType interactionType, Vector3 targetPosition)
: base(time, proceduralAnimationController)
{
Expand All @@ -39,7 +33,6 @@ public InteractAnimations(ProceduralAnimationController proceduralAnimationContr
_mainHand = mainHand;
_interact = interactionType;
_targetPosition = targetPosition;
_toolParent = _tool.GameObject.transform.parent;
SetupInteract(mainHand, _tool);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DG.Tweening;
using FishNet.Object;
using SS3D.Systems.Interactions;
using SS3D.Systems.Inventory.Containers;
using System;
Expand Down
22 changes: 10 additions & 12 deletions Assets/Scripts/SS3D/Systems/Animations/ItemHitPoint.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using JetBrains.Annotations;
using NaughtyAttributes;
using System.Collections.Generic;
using UnityEngine;

namespace SS3D.Systems.Animations
Expand Down Expand Up @@ -36,17 +36,15 @@ public class ItemHitPoint : MonoBehaviour
/// </summary>
public Vector3 UpHit => _upHit;

private DropdownList<Vector3> GetDirectionValues()
[NotNull]
private DropdownList<Vector3> GetDirectionValues() => new()
{
return new DropdownList<Vector3>()
{
{ "Right", Vector3.right },
{ "Left", Vector3.left },
{ "Up", Vector3.up },
{ "Down", Vector3.down },
{ "Forward", Vector3.forward },
{ "Back", Vector3.back },
};
}
{ "Right", Vector3.right },
{ "Left", Vector3.left },
{ "Up", Vector3.up },
{ "Down", Vector3.down },
{ "Forward", Vector3.forward },
{ "Back", Vector3.back },
};
}
}
6 changes: 1 addition & 5 deletions Assets/Scripts/SS3D/Systems/Animations/PickUpAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace SS3D.Systems.Animations
{
public class PickUpAnimation : AbstractProceduralAnimation
public sealed class PickUpAnimation : AbstractProceduralAnimation
{
public override event Action<IProceduralAnimation> OnCompletion;

Expand All @@ -18,8 +18,6 @@ public class PickUpAnimation : AbstractProceduralAnimation

private readonly AbstractHoldable _holdable;

public bool IsPicking { get; private set; }

public PickUpAnimation(ProceduralAnimationController proceduralAnimationController, float time, Hand mainHand, Hand secondaryHand, AbstractHoldable item)
: base(time, proceduralAnimationController)
{
Expand Down Expand Up @@ -137,11 +135,9 @@ private void PickupReach(bool withTwoHands)
InteractionSequence.Join(DOTween.To(() => _secondaryHand.Hold.PickupIkConstraint.weight, x => _secondaryHand.Hold.PickupIkConstraint.weight = x, 0f, _itemReachDuration));
}

InteractionSequence.OnStart(() => IsPicking = true);
InteractionSequence.OnComplete(() =>
{
OnCompletion?.Invoke(this);
IsPicking = false;
});
}
}
Expand Down
Loading

0 comments on commit 1946466

Please sign in to comment.