Skip to content

Commit aa62411

Browse files
committed
style: Improve item droppable code
1 parent 8f84ff3 commit aa62411

File tree

7 files changed

+13
-19
lines changed

7 files changed

+13
-19
lines changed

Assets/JCSUnity/Scripts/Effects/Item/JCS_Item.cs

Lines changed: 5 additions & 13 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

@@ -18,13 +19,13 @@ namespace JCSUnity
1819
[RequireComponent(typeof(Rigidbody))]
1920
public class JCS_Item : JCS_UnityObject
2021
{
21-
public delegate void PickedFunction(Collider other);
22-
2322
/* Variables */
2423

25-
public PickedFunction pickedCallback = DefaultPickCallback;
24+
// Execution after the item is picked.
25+
public Action<Collider> onPicked = null;
2626

2727
protected bool mCanPick = true;
28+
2829
protected BoxCollider mBoxCollider = null;
2930

3031
[Separator("Check Variables (JCS_Item)")]
@@ -188,15 +189,6 @@ public void Pick(Collider other)
188189
}
189190
}
190191

191-
/// <summary>
192-
/// Default pick up callback.
193-
/// </summary>
194-
/// <param name="other"></param>
195-
public static void DefaultPickCallback(Collider other)
196-
{
197-
// do anything after the character pick this item up.
198-
}
199-
200192
/// <summary>
201193
/// Do pick up item action.
202194
/// </summary>
@@ -214,7 +206,7 @@ private void DoPick(Collider other)
214206
sp.PlayOneShot(mPickSound);
215207

216208
// call item effect.
217-
pickedCallback.Invoke(other);
209+
onPicked?.Invoke(other);
218210

219211
/* Play Effect Sound */
220212
if (mPlayOneShotWhileNotPlayingForEffectSound)

Assets/JCSUnity/Scripts/Effects/Item/JCS_ItemDroppable.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

@@ -19,14 +20,14 @@ public class JCS_ItemDroppable : MonoBehaviour
1920
{
2021
/* Variables */
2122

22-
[System.Serializable]
23+
[Serializable]
2324
public struct ItemSet
2425
{
2526
[Tooltip("Possibilty droping this item, the higher the more possiblility.")]
2627
[Range(0.0f, 100.0f)]
2728
public float dropRate;
2829

29-
[Tooltip("Item to drop")]
30+
[Tooltip("Item to drop.")]
3031
public JCS_Item item;
3132
};
3233

Assets/_BossFight/Scripts/BF_GoldObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected override void Awake()
3333
// set the picking collider
3434
PickCollider = BF_GameManager.instance.COLLECT_GOLD_OBJECT;
3535

36-
pickedCallback = AfterPicked;
36+
onPicked = AfterPicked;
3737
}
3838

3939
/// <summary>

Assets/_BossFight/Scripts/BF_PickItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected override void Awake()
3939
// set the picking collider
4040
PickCollider = BF_GameManager.instance.COLLECT_GOLD_OBJECT;
4141

42-
pickedCallback = AfterPicked;
42+
onPicked = AfterPicked;
4343

4444
// try to get the optional variables.
4545
if (mEffectPickItem == null)

Assets/_RunningCrush/Scripts/RC_EffectItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected override void Awake()
3232
// disable auto detect
3333
mEffectObject.AutoEffect = false;
3434

35-
pickedCallback = AfterPicked;
35+
onPicked = AfterPicked;
3636
}
3737

3838
private void AfterPicked(Collider other)

Assets/_RunningCrush/Scripts/RC_GoldObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected override void Awake()
2727
// set to auto pick auto matically.
2828
mAutoPickColliderTouched = true;
2929

30-
pickedCallback = AfterPicked;
30+
onPicked = AfterPicked;
3131
}
3232

3333
private void AfterPicked(Collider other)

docs/ScriptReference/Effects/Item/JCS_Item.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Base class for all the item subclasses.
66

77
| Name | Description |
88
|:------------------------------------------|:-----------------------------------------------------------|
9+
| onPicked | Execution after the item is picked. |
910
| mMustBeActivePlayer | Must be an active player in order to pick this item up. |
1011
| mPickKey | Key to pick this item up. |
1112
| mPickByMouseDown | Pick up the item by mouse. |

0 commit comments

Comments
 (0)