Skip to content

Commit 7dab70b

Browse files
committed
refactor: Replace delegate to action or func
1 parent aa62411 commit 7dab70b

File tree

10 files changed

+24
-42
lines changed

10 files changed

+24
-42
lines changed

Assets/JCSUnity/Scripts/Actions/2D/Shooting/JCS_2DCursorShootAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void SetShootCallback(Action func)
4545
/// Function to check if able to do this action.
4646
/// </summary>
4747
/// <param name="func"></param>
48-
public void SetCheckAbleToShootFunction(CheckAbleToShoot func)
48+
public void SetCheckAbleToShootFunction(Func<bool> func)
4949
{
5050
this.mShootAction.SetCheckAbleToShootFunction(func);
5151
}

Assets/JCSUnity/Scripts/Actions/2D/Shooting/JCS_2DSequenceShootActionNoDetection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void SetShootCallback(Action func)
9292
this.mShootAction.SetShootCallback(func);
9393
}
9494

95-
public void SetCheckAbleToShootFunction(CheckAbleToShoot func)
95+
public void SetCheckAbleToShootFunction(Func<bool> func)
9696
{
9797
this.mShootAction.SetCheckAbleToShootFunction(func);
9898
}

Assets/JCSUnity/Scripts/Actions/2D/Shooting/JCS_ShootAction.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
namespace JCSUnity
1414
{
15-
// If the function return
16-
// -> true, shoot the bullet.
17-
// -> false not able to shoot the bullet.
18-
public delegate bool CheckAbleToShoot();
19-
2015
/// <summary>
2116
/// Action that shoot bullets.
2217
/// </summary>
@@ -81,7 +76,7 @@ public class JCS_ShootAction : MonoBehaviour, JCS_IAction
8176
private Action mShootCallback = DefualtShootCallback;
8277

8378
// Check we able to shoot or not
84-
private CheckAbleToShoot mCheckAbleToShoot = DefualtCheckFunction;
79+
private Func<bool> mCheckAbleToShoot = DefualtCheckFunction;
8580

8681
[Header("- Action")]
8782

@@ -244,8 +239,8 @@ public enum TrackType
244239
/// in order to check the shoot action.
245240
/// </summary>
246241
/// <param name="func"> functin to check able to do the shoot action. </param>
247-
public void SetCheckAbleToShootFunction(CheckAbleToShoot func) { this.mCheckAbleToShoot = func; }
248-
public CheckAbleToShoot GetCheckAbleToShootFunction() { return this.mCheckAbleToShoot; }
242+
public void SetCheckAbleToShootFunction(Func<bool> func) { this.mCheckAbleToShoot = func; }
243+
public Func<bool> GetCheckAbleToShootFunction() { return this.mCheckAbleToShoot; }
249244

250245
/* Functions */
251246

Assets/JCSUnity/Scripts/Input/JCS_ButtonSelection.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ namespace JCSUnity
2121
/// </summary>
2222
public class JCS_ButtonSelection : MonoBehaviour
2323
{
24-
public delegate void SelectionActiveEvent(bool act);
25-
2624
/* Variables */
2725

2826
public Action selectionEnable = SelectionEnable;
2927
public Action selectionDisable = SelectionDisable;
30-
public SelectionActiveEvent selectionActive = SelectionActive;
28+
public Action<bool> selectionActive = SelectionActive;
3129

3230
private JCS_ButtonSelectionGroup mButtonSelectionGroup = null;
3331

Assets/JCSUnity/Scripts/Input/JCS_Input.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ public enum JCS_MouseButton
7979
MIDDLE = 2
8080
};
8181

82-
public delegate void JoystickPlugged(); // Callback when joystick is plugged.
83-
public delegate void JoystickUnPlugged(); // Callback when joystick is unplugged.
84-
8582
/// <summary>
8683
/// Unity's Input class re-wrapper.
8784
/// </summary>

Assets/JCSUnity/Scripts/Interactive/2D/Camera/JCS_2DSlideScreenCamera.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
using UnityEngine;
1010
using MyBox;
11+
using System;
1112

1213
namespace JCSUnity
1314
{
@@ -18,16 +19,13 @@ namespace JCSUnity
1819
/// </summary>
1920
public class JCS_2DSlideScreenCamera : MonoBehaviour
2021
{
21-
public delegate void AfterSceneSwitchedCallback(Vector2 page);
22-
public delegate void AfterSwipeCallback(Vector2 page);
23-
2422
/* Variables */
2523

2624
// Function call after the scene changed
27-
public AfterSceneSwitchedCallback afterSceneSwitched = null;
25+
public Action<Vector2> afterSceneSwitched = null;
2826

2927
// Function call after the user has swiped
30-
public AfterSwipeCallback afterSwiped = null;
28+
public Action<Vector2> afterSwiped = null;
3129

3230
#if UNITY_EDITOR
3331
[Separator("Helper Variables (JCS_2DSlideScreenCamera)")]

Assets/JCSUnity/Scripts/Loader/JCS_AudioLoader.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright © 2018 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using System.IO;
1011
using System.Collections;
1112
using UnityEngine;
@@ -18,12 +19,6 @@ namespace JCSUnity
1819
/// </summary>
1920
public static class JCS_AudioLoader
2021
{
21-
/// <summary>
22-
/// Callback after the audio is loaded.
23-
/// </summary>
24-
/// <param name="tex"> The loaded audio. </param>
25-
public delegate void AudioLoaded(AudioClip clip);
26-
2722
/// <summary>
2823
/// Load the audio from path/url in runtime.
2924
/// </summary>
@@ -36,7 +31,7 @@ public static IEnumerator LoadAudio(
3631
string path,
3732
string filename,
3833
AudioType type = AudioType.OGGVORBIS,
39-
AudioLoaded callback = null)
34+
Action<AudioClip> callback = null)
4035
{
4136
string url = Path.Join(path, filename);
4237
return LoadAudio(url, type, callback);
@@ -52,7 +47,7 @@ public static IEnumerator LoadAudio(
5247
public static IEnumerator LoadAudio(
5348
string url,
5449
AudioType type = AudioType.OGGVORBIS,
55-
AudioLoaded callback = null)
50+
Action<AudioClip> callback = null)
5651
{
5752
#if UNITY_2018_1_OR_NEWER
5853
UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(url, type);

Assets/JCSUnity/Scripts/Network/JCS_ServerRequestProcessor.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2017 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using System.Collections.Generic;
11+
using UnityEditor.PackageManager;
1012
using UnityEngine;
1113

1214
namespace JCSUnity
@@ -17,13 +19,11 @@ namespace JCSUnity
1719
public class JCS_ServerRequestProcessor
1820
: JCS_Settings<JCS_ServerRequestProcessor>
1921
{
20-
public delegate void ServerRequest(JCS_BinaryReader br, JCS_Client client);
21-
2222
/* Variables */
2323

24-
private List<ServerRequest> mServerRequest = new List<ServerRequest>();
25-
private List<JCS_Client> mClient = new List<JCS_Client>();
26-
private List<JCS_BinaryReader> mBinaryReader = new List<JCS_BinaryReader>();
24+
private List<Action<JCS_BinaryReader, JCS_Client>> mServerRequest = new();
25+
private List<JCS_Client> mClient = new();
26+
private List<JCS_BinaryReader> mBinaryReader = new();
2727

2828
/* Setter & Getter */
2929

@@ -42,7 +42,7 @@ private void Update()
4242
/// <summary>
4343
/// Register request from server.
4444
/// </summary>
45-
public void RegisterRequest(ServerRequest request, JCS_BinaryReader br, JCS_Client client)
45+
public void RegisterRequest(Action<JCS_BinaryReader, JCS_Client> request, JCS_BinaryReader br, JCS_Client client)
4646
{
4747
mServerRequest.Add(request);
4848
mBinaryReader.Add(br);
@@ -52,7 +52,7 @@ public void RegisterRequest(ServerRequest request, JCS_BinaryReader br, JCS_Clie
5252
/// <summary>
5353
/// Deregister the request from server.
5454
/// </summary>
55-
public void DeresgisterRequest(ServerRequest request, JCS_BinaryReader br, JCS_Client client)
55+
public void DeresgisterRequest(Action<JCS_BinaryReader, JCS_Client> request, JCS_BinaryReader br, JCS_Client client)
5656
{
5757
mServerRequest.Remove(request);
5858
mBinaryReader.Remove(br);

Assets/JCSUnity/Scripts/Util/JCS_UIUtil.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
#define TMP_PRO
1313

14+
using System;
1415
using UnityEngine;
1516
using UnityEngine.UI;
1617
using UnityEngine.EventSystems;
@@ -21,9 +22,6 @@
2122

2223
namespace JCSUnity
2324
{
24-
public delegate void EventTriggerEvent(PointerEventData data);
25-
public delegate void EventTriggerEventButtonSelection(PointerEventData data, JCS_ButtonSelection selection);
26-
2725
/// <summary>
2826
/// User interface related utilities functions.
2927
/// </summary>
@@ -61,7 +59,7 @@ public static bool IsUnityDefinedUI(Component comp)
6159
/// <param name="te"></param>
6260
/// <param name="type"></param>
6361
/// <param name="func"></param>
64-
public static void AddEventTriggerEvent(EventTrigger te, EventTriggerType type, EventTriggerEvent func)
62+
public static void AddEventTriggerEvent(EventTrigger te, EventTriggerType type, Action<PointerEventData> func)
6563
{
6664
EventTrigger.Entry entry = new EventTrigger.Entry();
6765
entry.eventID = type;
@@ -75,7 +73,7 @@ public static void AddEventTriggerEvent(EventTrigger te, EventTriggerType type,
7573
/// <param name="te"></param>
7674
/// <param name="type"></param>
7775
/// <param name="func"></param>
78-
public static void AddEventTriggerEvent(EventTrigger te, EventTriggerType type, EventTriggerEventButtonSelection func, JCS_ButtonSelection selection)
76+
public static void AddEventTriggerEvent(EventTrigger te, EventTriggerType type, Action<PointerEventData, JCS_ButtonSelection> func, JCS_ButtonSelection selection)
7977
{
8078
EventTrigger.Entry entry = new EventTrigger.Entry();
8179
entry.eventID = type;

Assets/_BossFight/Scripts/BF_Player.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public class BF_Player : JCS_2DSideScrollerPlayer
2424

2525
private JCS_SequenceShootAction mSequenceShootAction = null;
2626

27-
[SerializeField] [Range(0, 100)]
27+
[SerializeField]
28+
[Range(0, 100)]
2829
private float mManaCastPerShoot = 1;
2930

3031
/* Setter & Getter */

0 commit comments

Comments
 (0)