Skip to content

Commit 532ba8c

Browse files
committed
优化InteruptBuff相关逻辑
1 parent f6cdbf1 commit 532ba8c

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

Assets/NoSLoofah_BuffSystem/BuffSystem/Base/BuffHandler/BuffHandler.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,24 @@ private void AddBuff(IBuff buff, GameObject caster)
9292
}
9393
}
9494
/// <summary>
95-
/// 移除一个Buff,移除后执行OnBuffDestroy
95+
/// 移除一个Buff,移除后执行OnBuffRemove
9696
/// </summary>
9797
/// <param name="buff">要移除的Buff</param>
9898
private void RemoveBuff(IBuff buff)
9999
{
100-
InteruptBuff(buff);
101-
forOnBuffDestroy += ((Buff)buff).OnBuffDestroy;
100+
Buff bf = (Buff)buff;
101+
bf.SetEffective(false);
102102
}
103103
/// <summary>
104-
/// 移除一个Buff,移除后不执行OnBuffDestroy
104+
/// 移除一个Buff,移除后不执行OnBuffRemove
105105
/// </summary>
106106
/// <param name="buff">要移除的Buff</param>
107107
private void InteruptBuff(IBuff buff)
108108
{
109109
Buff bf = (Buff)buff;
110110
bf.SetEffective(false);
111+
buffs.Remove(bf);
112+
forOnBuffDestroy += ((Buff)buff).OnBuffDestroy;
111113
}
112114
#endregion
113115
public void AddBuff(int buffId, GameObject caster)
@@ -151,7 +153,7 @@ public void InteruptBuff(int buffId, bool removeAll = true)
151153
InteruptBuff(bf);
152154
}
153155
}
154-
InteruptBuff(b);
156+
else InteruptBuff(b);
155157
}
156158

157159
private bool updated = false;
@@ -170,6 +172,7 @@ private void LateUpdate()
170172
{
171173
updated = false;
172174
Buff bf;
175+
bool buffRemoved = false;
173176
for (int i = buffs.Count - 1; i >= 0; i--)
174177
{
175178
bf = buffs[i];
@@ -178,11 +181,12 @@ private void LateUpdate()
178181
if (!bf.IsEffective)
179182
{
180183
bf.OnBuffRemove();
181-
onRemoveBuff?.Invoke();
184+
buffRemoved = true;
182185
buffs.Remove(bf);
183186
forOnBuffDestroy += bf.OnBuffDestroy;
184187
}
185188
}
189+
if (buffRemoved) onRemoveBuff?.Invoke();
186190
}
187191
}
188192
}

Assets/NoSLoofah_BuffSystem/BuffSystem/Base/BuffHandler/IBuffHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface IBuffHandler
2121
/// <param name="removeAll">如果对象同时存在多个同id的buff,是否将所有一并移除</param>
2222
public void RemoveBuff(int buffId, bool removeAll = true);
2323
/// <summary>
24-
/// 移除Buff(不执行OnBuffDestroy
24+
/// 移除Buff(不执行OnBuffRemove
2525
/// </summary>
2626
/// <param name="buffId">要移除的Buff id</param>
2727
/// <param name="removeAll">如果对象同时存在多个同id的buff,是否将所有一并移除</param>

Assets/NoSLoofah_BuffSystem/Example/Scripts/CustomBuff/Buff_Fragile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ public override void OnBuffDestroy()
1414
}
1515

1616
public override void OnBuffModifyLayer(int change)
17-
{
17+
{
1818
targetEntity.ModifyDamageMultiplier(hurtIncreaseRate * change);
1919
}
2020

2121
public override void OnBuffRemove()
2222
{
23-
23+
Debug.Log("OnRemove");
2424
}
2525

2626
public override void OnBuffStart()
2727
{
28-
targetEntity = Target.GetComponent<Entity1>();
28+
targetEntity = Target.GetComponent<Entity1>();
2929
}
3030

3131
public override void Reset()

Assets/NoSLoofah_BuffSystem/Example/Scripts/UI/BuffButton.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public void InteruptBuff()
2525
{
2626
int i;
2727
if (!int.TryParse(inputField.text, out i)) return;
28-
buffHandler.RemoveBuff(i);
28+
buffHandler.InteruptBuff(i);
2929
}
3030
}

0 commit comments

Comments
 (0)