Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed Delegates into Event #31

Open
wants to merge 2 commits into
base: Converting-Delegate-into-Event-Action-Setup
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"files.exclude":
{
"**/.DS_Store":true,
"**/.git":true,
"**/.gitmodules":true,
"**/*.booproj":true,
"**/*.pidb":true,
"**/*.suo":true,
"**/*.user":true,
"**/*.userprefs":true,
"**/*.unityproj":true,
"**/*.dll":true,
"**/*.exe":true,
"**/*.pdf":true,
"**/*.mid":true,
"**/*.midi":true,
"**/*.wav":true,
"**/*.gif":true,
"**/*.ico":true,
"**/*.jpg":true,
"**/*.jpeg":true,
"**/*.png":true,
"**/*.psd":true,
"**/*.tga":true,
"**/*.tif":true,
"**/*.tiff":true,
"**/*.3ds":true,
"**/*.3DS":true,
"**/*.fbx":true,
"**/*.FBX":true,
"**/*.lxo":true,
"**/*.LXO":true,
"**/*.ma":true,
"**/*.MA":true,
"**/*.obj":true,
"**/*.OBJ":true,
"**/*.asset":true,
"**/*.cubemap":true,
"**/*.flare":true,
"**/*.mat":true,
"**/*.meta":true,
"**/*.prefab":true,
"**/*.unity":true,
"build/":true,
"Build/":true,
"Library/":true,
"library/":true,
"obj/":true,
"Obj/":true,
"ProjectSettings/":true,
"temp/":true,
"Temp/":true
},
"dotnet.preferCSharpExtension": true
}
13 changes: 8 additions & 5 deletions Assets/Scripts/Interactables/LightSwitchView.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using static LightSwitchView;
Expand All @@ -6,16 +7,18 @@ public class LightSwitchView : MonoBehaviour, IInteractable
{
[SerializeField] private List<Light> lightsources = new List<Light>();
private SwitchState currentState;
public delegate void LightSwitchDelegate();
public static LightSwitchDelegate lightToggled;
//public delegate void LightSwitchDelegate();
//public static event LightSwitchDelegate lightToggled;

private void OnEnable() => lightToggled += onLightSwitch;
public static event Action lightToggledAction;

private void OnDisable() => lightToggled -= onLightSwitch;
private void OnEnable() => lightToggledAction += onLightSwitch;

private void OnDisable() => lightToggledAction -= onLightSwitch;

private void Start() => currentState = SwitchState.Off;

public void Interact() => lightToggled?.Invoke();
public void Interact() => lightToggledAction?.Invoke();

private void toggleLights()
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri

this.playerScriptableObject = playerScriptableObject;
this.playerScriptableObject.KeysEquipped = 0;
LightSwitchView.lightToggled += onLightSwitch;
LightSwitchView.lightToggledAction += onLightSwitch;
playerState = PlayerState.InDark;
}

~PlayerController()
{
LightSwitchView.lightToggled -= onLightSwitch;
LightSwitchView.lightToggledAction -= onLightSwitch;
}
public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted);

Expand Down