Skip to content

Commit

Permalink
make toggle interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Oct 18, 2024
1 parent c8d0061 commit 00cfae0
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions Assets/Scripts/SS3D/Systems/Audio/Boombox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SS3D.Core;
using SS3D.Core.Behaviours;
using SS3D.Interactions.Extensions;
using SS3D.Systems.Interactions;
using System.Electricity;
using UnityEngine.Serialization;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SS3D.Data.Generated;
using SS3D.Interactions;
using SS3D.Systems.Audio;
using SS3D.Systems.Interactions;
using SS3D.Systems.Tile.Connections;
using UnityEngine;
using AudioType = SS3D.Systems.Audio.AudioType;
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/SS3D/Systems/Electricity/SmesBattery.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FishNet.Object;
using SS3D.Core;
using SS3D.Interactions;
using SS3D.Systems.Interactions;
using UnityEngine;
using UnityEngine.Serialization;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using FishNet.Object.Synchronizing;
using SS3D.Core.Behaviours;
using SS3D.Interactions;
using SS3D.Interactions.Interfaces;
using System;
using System.Collections.Generic;
using UnityEngine;


namespace SS3D.Interactions
namespace SS3D.Systems.Interactions
{
/// <summary>
/// Small script to make a game object toggleable. All it does is send an OnToggle event when its state changes.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using SS3D.Interactions.Extensions;
using SS3D.Interactions;
using SS3D.Interactions.Extensions;
using SS3D.Systems.Animations;
using SS3D.Systems.Inventory.Containers;
using System;
using UnityEngine;

namespace SS3D.Interactions
namespace SS3D.Systems.Interactions
{
/// <summary>
/// Utility class for toggle interactions
/// </summary>
public class ToggleInteraction : Interaction
public class ToggleInteraction : DelayedInteraction
{
/// <summary>
/// The icon when state is true
Expand Down Expand Up @@ -37,11 +40,15 @@ public class ToggleInteraction : Interaction
/// </summary>
public bool RangeCheck { get; set; } = true;

public ToggleInteraction()
{
Delay = 0.2f;
}

public override string GetGenericName()
{
return "Toggle";
}


public override string GetName(InteractionEvent interactionEvent)
{
Expand Down Expand Up @@ -73,6 +80,31 @@ public override bool CanInteract(InteractionEvent interactionEvent)
}

public override bool Start(InteractionEvent interactionEvent, InteractionReference reference)
{
base.Start(interactionEvent, reference);
Hand hand = interactionEvent.Source as Hand;

Vector3 point = interactionEvent.Point;

if (interactionEvent.Target.TryGetInteractionPoint(interactionEvent.Source, out Vector3 customPoint))
{
point = customPoint;
}

if (hand != null)
{
interactionEvent.Source.GameObject.GetComponentInParent<InteractWithHandAnimation>().ServerInteract(hand, point, Delay);
}

return true;
}

public override void Cancel(InteractionEvent interactionEvent, InteractionReference reference)
{

}

protected override void StartDelayed(InteractionEvent interactionEvent, InteractionReference reference)
{
if (interactionEvent.Target is IToggleable toggle1)
{
Expand All @@ -83,7 +115,6 @@ public override bool Start(InteractionEvent interactionEvent, InteractionReferen
toggle.Toggle();
}

return false;
}
}
}

0 comments on commit 00cfae0

Please sign in to comment.