Skip to content

Commit f69a517

Browse files
committed
first commit
0 parents  commit f69a517

File tree

598 files changed

+47843
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

598 files changed

+47843
-0
lines changed

Assets/BuffSystem.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/BuffSystem/Base.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/BuffSystem/Base/BuffBase.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
using NoSLoofah.BuffSystem.Dependence;
2+
using UnityEngine;
3+
using Newtonsoft.Json;
4+
using System;
5+
namespace NoSLoofah.BuffSystem
6+
{
7+
[SerializeField]
8+
//重复添加同一种Buff时的行为
9+
public enum BuffMutilAddType
10+
{
11+
resetTime, //重置Buff时间
12+
multipleLayer, //增加Buff层数
13+
multipleLayerAndResetTime, //增加Buff层数且重置Buff时间
14+
multipleCount //同种Buff同时存在多个,互不影响
15+
}
16+
/// <summary>
17+
/// 所有Buff类的基类
18+
/// </summary>
19+
[System.Serializable]
20+
public abstract class Buff : ScriptableObject, IBuff, IComparable<Buff>
21+
{
22+
/// <summary>
23+
/// 创建一个新的Buff对象
24+
/// </summary>
25+
/// <param name="buffName">具体的Buff子类名</param>
26+
/// <param name="id">Buff对象的ID</param>
27+
/// <returns>Buff对象</returns>
28+
public static Buff CreateInstance(string buffName, int id)
29+
{
30+
var b = (Buff)ScriptableObject.CreateInstance(buffName);
31+
b.id = id;
32+
return b;
33+
}
34+
/// <summary>
35+
/// 克隆当前的Buff
36+
/// </summary>
37+
/// <returns>克隆的Buff</returns>
38+
public Buff Clone()
39+
{
40+
return GameObject.Instantiate(this);
41+
}
42+
43+
44+
45+
[JsonIgnore] public BuffHandler Target { get; private set; }
46+
[JsonIgnore] public GameObject Caster { get; private set; }
47+
[JsonIgnore] public int Layer { get; private set; }
48+
49+
[ReplaceLabel("图标")][SerializeField] private Sprite icon;
50+
[ReplaceLabel("名称(必填)")][SerializeField] private string buffName;
51+
//层级
52+
[ReplaceLabel("重复添加方式")][SerializeField] private BuffMutilAddType mutilAddType;
53+
[ReplaceLabel("计时结束时层-1/层全清空")][SerializeField] private bool removeOneLayerOnTimeUp;
54+
55+
[ReplaceLabel("Tag")][SerializeField] private BuffTag buffTag;
56+
[SerializeField][HideInInspector] private int id;
57+
private int tmpLayer = 0;
58+
private bool layerModified = false;
59+
public bool RemoveOneLayerOnTimeUp => removeOneLayerOnTimeUp;
60+
public BuffMutilAddType MutilAddType => mutilAddType;
61+
public BuffTag BuffTag => buffTag;
62+
public string BuffName => buffName;
63+
public Sprite Icon => icon;
64+
public int ID => id;
65+
#region 管理器接手的生命周期函数
66+
public virtual void OnBuffAwake()
67+
{
68+
timer = duration;
69+
isEffective = true;
70+
Layer = 1;
71+
72+
}
73+
public abstract void OnBuffDestroy();
74+
public abstract void OnBuffRemove();
75+
public abstract void OnBuffStart();
76+
public abstract void OnBuffModifyLayer(int change);
77+
public abstract void Reset();
78+
#region 定时器效果
79+
//buff时间
80+
private float timer;
81+
[ReplaceLabel("是永久的")][SerializeField] private bool isPermanent;
82+
[ReplaceLabel("Buff持续时间")][SerializeField] private float duration;
83+
private bool isEffective;
84+
[JsonIgnore] public bool IsEffective => isEffective;
85+
[JsonIgnore] public bool RunTickTimer => runTickTimer;
86+
87+
//定时效果
88+
private float tickTimer;
89+
private float tickInterval;
90+
private bool runTickTimer = false; //时候开始了周期性计时
91+
92+
//Buff剩余时间
93+
public float RemainingTime => timer;
94+
//Buff总时长
95+
public float Duration => duration;
96+
public float TickRemainingTime => tickTimer;
97+
98+
public bool IsPermanent => isPermanent;
99+
100+
public void ResetTimer()
101+
{
102+
timer = duration;
103+
}
104+
public void SetEffective(bool ef)
105+
{
106+
isEffective = ef;
107+
}
108+
protected abstract void OnBuffTickEffect();
109+
public void StartBuffTickEffect(float interval)
110+
{
111+
runTickTimer = true;
112+
tickTimer = interval;
113+
this.tickInterval = interval;
114+
}
115+
public void StopBuffTickEffect()
116+
{
117+
runTickTimer = false;
118+
}
119+
public void OnBuffUpdate()
120+
{
121+
if (!IsEffective) return;
122+
if (!isPermanent) timer -= Time.deltaTime;
123+
if (!isPermanent && timer <= 0)
124+
{
125+
if (removeOneLayerOnTimeUp)
126+
{
127+
timer = duration;
128+
ModifyLayer(-1);
129+
}
130+
else if (mutilAddType == BuffMutilAddType.multipleLayer || mutilAddType == BuffMutilAddType.multipleLayerAndResetTime)
131+
{
132+
ModifyLayer(-Layer);
133+
isEffective = false;
134+
}
135+
}
136+
RealModifyLayer();
137+
if (!runTickTimer) return;
138+
tickTimer -= Time.deltaTime;
139+
if (tickTimer <= 0)
140+
{
141+
tickTimer = tickInterval;
142+
OnBuffTickEffect();
143+
}
144+
}
145+
#endregion
146+
#endregion
147+
public void Initialize(IBuffHandler target, GameObject caster)
148+
{
149+
this.Target = (BuffHandler)target;
150+
this.Caster = caster;
151+
}
152+
private void RealModifyLayer()
153+
{
154+
Layer += tmpLayer;
155+
if (layerModified) OnBuffModifyLayer(tmpLayer);
156+
if (Layer <= 0) isEffective = false;
157+
tmpLayer = 0;
158+
layerModified = false;
159+
}
160+
public void ModifyLayer(int i)
161+
{
162+
if (mutilAddType != BuffMutilAddType.multipleLayer && mutilAddType != BuffMutilAddType.multipleLayerAndResetTime)
163+
throw new System.Exception("试图修改非层级Buff的层数");
164+
tmpLayer += i;
165+
layerModified = true;
166+
}
167+
#region 重写
168+
public override string ToString()
169+
{
170+
171+
return string.Concat(ID, ". ", buffName, ":", timer, "/", duration, "\tEffective: ", IsEffective);
172+
}
173+
public override int GetHashCode()
174+
{
175+
return HashCode.Combine(ID, base.GetHashCode());
176+
}
177+
public override bool Equals(object other)
178+
{
179+
if (!(other is Buff)) return false;
180+
return ID == ((Buff)other).ID;
181+
}
182+
183+
public int CompareTo(Buff other)
184+
{
185+
return ID.CompareTo(other.ID);
186+
}
187+
188+
public bool IsEmpty()
189+
{
190+
return string.IsNullOrEmpty(buffName);
191+
}
192+
193+
194+
#endregion
195+
}
196+
}

Assets/BuffSystem/Base/BuffBase/Buff.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using UnityEngine;
2+
namespace NoSLoofah.BuffSystem
3+
{
4+
/// <summary>
5+
/// Buff的接口,定义了生命周期函数
6+
/// </summary>
7+
[UnityEngine.SerializeField]
8+
public interface IBuff
9+
{
10+
/// <summary>
11+
/// Buff启用时,生效前(即便该Buff不可作用于对象也会先执行)
12+
/// </summary>
13+
public void OnBuffAwake();
14+
/// <summary>
15+
/// Buff开始生效时
16+
/// </summary>
17+
public void OnBuffStart();
18+
/// <summary>
19+
/// Buff移除时(用于移除效果)
20+
/// </summary>
21+
public void OnBuffRemove();
22+
/// <summary>
23+
/// Buff销毁时(用于执行移除时效果)
24+
/// </summary>
25+
public void OnBuffDestroy();
26+
/// <summary>
27+
/// 更新周期性效果计时
28+
/// </summary>
29+
public void OnBuffUpdate();
30+
/// <summary>
31+
/// Buff层数变化时
32+
/// </summary>
33+
/// <param name="change"></param>
34+
public void OnBuffModifyLayer(int change);
35+
/// <summary>
36+
/// 开始周期性效果
37+
/// 如果已经开启过(无论是否在之后停止了),则重置计时器并重新开始
38+
/// </summary>
39+
/// <param name="interval">周期时间</param>
40+
public void StartBuffTickEffect(float interval);
41+
/// <summary>
42+
/// 停止周期性效果
43+
/// </summary>
44+
public void StopBuffTickEffect();
45+
/// <summary>
46+
/// 重置Buff以复用
47+
/// </summary>
48+
public void Reset();
49+
/// <summary>
50+
/// 重置总体时间
51+
/// </summary>
52+
public void ResetTimer();
53+
/// <summary>
54+
/// 初始化
55+
/// </summary>
56+
/// <param name="target">Buff目标</param>
57+
/// <param name="caster">Buff来源</param>
58+
public void Initialize(IBuffHandler target, GameObject caster);
59+
/// <summary>
60+
/// 让Buff层级+=i
61+
/// </summary>
62+
/// <param name="i">改变的层数,可以为负</param>
63+
public void ModifyLayer(int i);
64+
/// <summary>
65+
/// 设置Buff是否生效。
66+
/// 不生效时,Buff的所有计时器也会暂停
67+
/// </summary>
68+
/// <param name="ef"></param>
69+
public void SetEffective(bool ef);
70+
71+
/// <summary>
72+
/// 如果Buff名为空,就会视为不可使用的空Buff
73+
/// </summary>
74+
public bool IsEmpty();
75+
}
76+
}

Assets/BuffSystem/Base/BuffBase/IBuff.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
namespace NoSLoofah.BuffSystem
5+
{
6+
/// <summary>
7+
/// 用来占位的Buff类,即编辑器中的[NONE]
8+
/// 无视即可
9+
/// </summary>
10+
public class PlaceholderBuff : Buff
11+
{
12+
13+
public override void OnBuffDestroy()
14+
{
15+
16+
}
17+
18+
public override void OnBuffModifyLayer(int change)
19+
{
20+
21+
}
22+
23+
public override void OnBuffRemove()
24+
{
25+
26+
}
27+
28+
public override void OnBuffStart()
29+
{
30+
31+
}
32+
33+
public override void Reset()
34+
{
35+
36+
}
37+
38+
protected override void OnBuffTickEffect()
39+
{
40+
41+
}
42+
}
43+
}

Assets/BuffSystem/Base/BuffBase/PlaceholderBuff.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/BuffSystem/Base/BuffHandler.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)