Skip to content

Commit 3438a00

Browse files
committed
feat: Replace empty function with generic callback
1 parent 98bc003 commit 3438a00

28 files changed

+118
-94
lines changed

Assets/JCSUnity/Editor/JCSUnity_EditortUtil.cs

Lines changed: 7 additions & 6 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 © 2021 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEditor;
1011
using UnityEngine;
1112

@@ -27,7 +28,7 @@ public static string FormKey(string name)
2728
return JCSUnity_EditorWindow.NAME + "." + name;
2829
}
2930

30-
public static void CreateGroup(EmptyFunction func, bool flexibleSpace = false)
31+
public static void CreateGroup(Action func, bool flexibleSpace = false)
3132
{
3233
BeginHorizontal(() =>
3334
{
@@ -39,29 +40,29 @@ public static void CreateGroup(EmptyFunction func, bool flexibleSpace = false)
3940
flexibleSpace);
4041
}
4142

42-
public static void BeginHorizontal(EmptyFunction func, bool flexibleSpace = false)
43+
public static void BeginHorizontal(Action func, bool flexibleSpace = false)
4344
{
4445
GUILayout.BeginHorizontal();
4546
if (flexibleSpace) GUILayout.FlexibleSpace();
4647
func.Invoke();
4748
GUILayout.EndHorizontal();
4849
}
4950

50-
public static void BeginVertical(EmptyFunction func)
51+
public static void BeginVertical(Action func)
5152
{
5253
GUILayout.BeginVertical("box");
5354
func.Invoke();
5455
GUILayout.EndVertical();
5556
}
5657

57-
public static void Indent(EmptyFunction func)
58+
public static void Indent(Action func)
5859
{
5960
EditorGUI.indentLevel++;
6061
func.Invoke();
6162
EditorGUI.indentLevel--;
6263
}
6364

64-
public static bool Foldout(bool foldout, string content, EmptyFunction func, string texName = "")
65+
public static bool Foldout(bool foldout, string content, Action func, string texName = "")
6566
{
6667
Texture tex = FindTexture(texName);
6768

@@ -89,7 +90,7 @@ public static Texture FindTexture(string texName)
8990
/// </summary>
9091
public static GameObject Instantiate(string path)
9192
{
92-
var asset = AssetDatabase.LoadAssetAtPath(path, typeof(Object)) as GameObject;
93+
var asset = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object)) as GameObject;
9394
var currentPrefab = GameObject.Instantiate(asset);
9495
return currentPrefab;
9596
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2016 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using MyBox;
1112

@@ -35,7 +36,7 @@ public class JCS_2DCursorShootAction : MonoBehaviour , JCS_IAction
3536
/// Call back during shooting a bullet.
3637
/// </summary>
3738
/// <param name="func"> function to set. </param>
38-
public void SetShootCallback(EmptyFunction func)
39+
public void SetShootCallback(Action func)
3940
{
4041
this.mShootAction.SetShootCallback(func);
4142
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2016 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using MyBox;
1112

@@ -86,7 +87,7 @@ public class JCS_2DSequenceShootActionNoDetection : MonoBehaviour, JCS_IAction
8687
/// Call back during shooting a bullet.
8788
/// </summary>
8889
/// <param name="func"> function to set. </param>
89-
public void SetShootCallback(EmptyFunction func)
90+
public void SetShootCallback(Action func)
9091
{
9192
this.mShootAction.SetShootCallback(func);
9293
}

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

Lines changed: 3 additions & 2 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 (c) 2016 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using MyBox;
1112

@@ -97,7 +98,7 @@ public class JCS_SequenceShootAction : MonoBehaviour, JCS_IAction
9798
public bool InSequenceEffect { get { return this.mInSequenceEffect; } set { this.mInSequenceEffect = value; } }
9899
public bool SequenceStay { get { return this.mSequenceStay; } set { this.mSequenceStay = value; } }
99100
public JCS_TimeType DeltaTimeType { get { return this.mTimeType; } set { this.mTimeType = value; } }
100-
public void SetShootCallback(EmptyFunction func) { this.mShootAction.SetShootCallback(func); }
101+
public void SetShootCallback(Action func) { this.mShootAction.SetShootCallback(func); }
101102
public JCS_AbilityFormat AbilityFormat { get { return this.mAbilityFormat; } set { this.mAbilityFormat = value; } }
102103
public float TimeBeforeShoot { get { return this.mTimeBeforeShoot; } set { this.mTimeBeforeShoot = value; } }
103104
public float TimeDelayAfterShoot { get { return this.mTimeDelayAfterShoot; } set { this.mTimeDelayAfterShoot = value; } }
@@ -432,7 +433,7 @@ public int[] PreCalculateSequenceDamage(int minDamage, int maxDamage, int hit, i
432433

433434
for (int index = 0; index < hit; ++index)
434435
{
435-
int dm = Random.Range(minDamage, maxDamage);
436+
int dm = UnityEngine.Random.Range(minDamage, maxDamage);
436437

437438
// 受到的傷害 = 傷害 - 防禦力
438439
damages[index] = dm - defenseValue;

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

Lines changed: 4 additions & 3 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 (c) 2016 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using MyBox;
1112

@@ -77,7 +78,7 @@ public class JCS_ShootAction : MonoBehaviour, JCS_IAction
7778
private JCS_KeyActionType mKeyAct = JCS_KeyActionType.KEY;
7879

7980
// call back after we do shoot action.
80-
private EmptyFunction mShootCallback = DefualtShootCallback;
81+
private Action mShootCallback = DefualtShootCallback;
8182

8283
// Check we able to shoot or not
8384
private CheckAbleToShoot mCheckAbleToShoot = DefualtCheckFunction;
@@ -233,8 +234,8 @@ public enum TrackType
233234
/// Call back during shooting a bullet.
234235
/// </summary>
235236
/// <param name="func"> function to set. </param>
236-
public void SetShootCallback(EmptyFunction func) { this.mShootCallback = func; }
237-
public EmptyFunction GetShootCallback() { return this.mShootCallback; }
237+
public void SetShootCallback(Action func) { this.mShootCallback = func; }
238+
public Action GetShootCallback() { return this.mShootCallback; }
238239

239240
/// <summary>
240241
/// Function check before shooting the bullet.

Assets/JCSUnity/Scripts/Actions/3D/JCS_3DDistanceTileAction.cs

Lines changed: 3 additions & 2 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 (c) 2017 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using MyBox;
1112

@@ -20,8 +21,8 @@ public class JCS_3DDistanceTileAction : MonoBehaviour
2021
{
2122
/* Variables */
2223

23-
public EmptyFunction beforeResetCallback = null;
24-
public EmptyFunction afterResetCallback = null;
24+
public Action beforeResetCallback = null;
25+
public Action afterResetCallback = null;
2526

2627
private Vector3 mOriginPos = Vector3.zero;
2728

Assets/JCSUnity/Scripts/Actions/JCS_AdjustTimeTrigger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2017 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using UnityEngine.Events;
1112
using MyBox;
@@ -20,7 +21,7 @@ public class JCS_AdjustTimeTrigger : MonoBehaviour
2021
/* Variables */
2122

2223
// action to trigger if the time is reached.
23-
public EmptyFunction onAction = null;
24+
public Action onAction = null;
2425

2526
[Separator("Check Variables (JCS_AdjustTimeTrigger)")]
2627

Assets/JCSUnity/Scripts/Animation/2D/JCS_2DAnimation.cs

Lines changed: 3 additions & 2 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 (c) 2017 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using MyBox;
1112

@@ -19,8 +20,8 @@ public class JCS_2DAnimation : JCS_UnityObject
1920
/* Variables */
2021

2122
// call back when done playing the animation.
22-
public EmptyFunction donePlayingAnimCallback = null;
23-
public EmptyFunction playFrameCallback = null;
23+
public Action donePlayingAnimCallback = null;
24+
public Action playFrameCallback = null;
2425

2526
// animator using this animation?
2627
private JCS_2DAnimator mAnimator = null;

Assets/JCSUnity/Scripts/Effects/JCS_FadeObject.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2016 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using MyBox;
1112

1213
namespace JCSUnity
1314
{
14-
public delegate void Fading(float alpha);
15-
1615
/// <summary>
1716
/// Fade object to a particular alpha channel.
1817
/// </summary>
1918
public class JCS_FadeObject : JCS_UnityObject
2019
{
2120
/* Variables */
2221

23-
public EmptyFunction onFadeOut = null;
24-
public EmptyFunction onFadeIn = null;
22+
public Action onFadeOut = null;
23+
public Action onFadeIn = null;
2524

26-
public Fading onFading = null;
25+
public Action<float> onFading = null;
2726

2827
private JCS_FadeType mFadeType = JCS_FadeType.FADE_IN; // defaul as visible
2928

@@ -223,8 +222,7 @@ private void DoFade()
223222
mEffect = false;
224223

225224
// do fade out callback
226-
if (onFadeOut != null)
227-
onFadeOut.Invoke();
225+
onFadeOut?.Invoke();
228226

229227
return;
230228
}
@@ -241,8 +239,7 @@ private void DoFade()
241239
mEffect = false;
242240

243241
// do fade in callback
244-
if (onFadeIn != null)
245-
onFadeIn.Invoke();
242+
onFadeIn?.Invoke();
246243

247244
return;
248245
}
@@ -256,8 +253,7 @@ private void DoFade()
256253
screenColor.a = mAlpha;
257254
this.LocalColor = screenColor;
258255

259-
if (onFading != null)
260-
onFading.Invoke(mAlpha);
256+
onFading?.Invoke(mAlpha);
261257
}
262258
}
263259
}

Assets/JCSUnity/Scripts/Effects/Tweener/JCS_ColorTweener.cs

Lines changed: 6 additions & 5 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 (c) 2017 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using UnityEngine.Events;
1112
using MyBox;
@@ -24,7 +25,7 @@ public class JCS_ColorTweener : JCS_UnityObject
2425
private TweenDelegate mEasingBlue = null;
2526
private TweenDelegate mEasingAlpha = null;
2627

27-
private EmptyFunction mColorCallback = null;
28+
private Action mColorCallback = null;
2829

2930
/**
3031
* time to calculate the progress.
@@ -221,7 +222,7 @@ public JCS_TweenType EaseTypeA
221222
public bool IgnoreG { get { return this.mIgnoreG; } set { this.mIgnoreG = value; } }
222223
public bool IgnoreB { get { return this.mIgnoreB; } set { this.mIgnoreB = value; } }
223224
public bool IgnoreA { get { return this.mIgnoreA; } set { this.mIgnoreA = value; } }
224-
public void SetCallback(EmptyFunction func)
225+
public void SetCallback(Action func)
225226
{
226227
this.mColorCallback = func;
227228
}
@@ -286,7 +287,7 @@ public void ResetTweener()
286287
/// Tween to the color.
287288
/// </summary>
288289
/// <param name="inToColor"> target color </param>
289-
public void DoTween(Color inToColor, EmptyFunction func = null)
290+
public void DoTween(Color inToColor, Action func = null)
290291
{
291292
DoTween(
292293
inToColor,
@@ -311,7 +312,7 @@ public void DoTween(
311312
JCS_TweenType inTweenTypeG,
312313
JCS_TweenType inTweenTypeB,
313314
JCS_TweenType inTweenTypeA,
314-
EmptyFunction func = null)
315+
Action func = null)
315316
{
316317
DoTween(
317318
this.LocalColor,
@@ -351,7 +352,7 @@ public void DoTween(
351352
float inDurationG,
352353
float inDurationB,
353354
float inDurationA,
354-
EmptyFunction func = null)
355+
Action func = null)
355356
{
356357
this.mFromColor = inFromColor;
357358
this.mTargetColor = inToColor;

0 commit comments

Comments
 (0)