Skip to content

Commit

Permalink
修复Numeric组件的一些问题
Browse files Browse the repository at this point in the history
  • Loading branch information
egametang committed Feb 25, 2022
1 parent cd81079 commit f22df5b
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 2,062 deletions.
4 changes: 4 additions & 0 deletions Unity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/Unity.Mono.csproj
/Unity.ThirdParty.csproj
/Unity.sln
/Unity.sln.DotSettings.user
2 changes: 1 addition & 1 deletion Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static Unit Create(Scene currentScene, UnitInfo unitInfo)
NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
for (int i = 0; i < unitInfo.Ks.Count; ++i)
{
numericComponent.Set((NumericType)unitInfo.Ks[i], unitInfo.Vs[i]);
numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i]);
}

unit.AddComponent<MoveComponent>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class NumericChangeEvent_NotifyWatcher: AEvent<EventType.NumbericChange>
{
protected override async ETTask Run(EventType.NumbericChange args)
{
NumericWatcherComponent.Instance.Run(args.NumericType, args.Parent.Id, args.New);
NumericWatcherComponent.Instance.Run(args);
await ETTask.CompletedTask;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[NumericWatcher(NumericType.Hp)]
public class NumericWatcher_Hp_ShowUI : INumericWatcher
{
public void Run(long id, long value)
public void Run(EventType.NumbericChange args)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion Unity/Codes/Model/Module/Numeric/INumericWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public interface INumericWatcher
{
void Run(long id, long value);
void Run(EventType.NumbericChange args);
}
}
35 changes: 10 additions & 25 deletions Unity/Codes/Model/Module/Numeric/NumericComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace EventType
public struct NumbericChange
{
public Entity Parent;
public NumericType NumericType;
public int NumericType;
public long Old;
public long New;
}
Expand All @@ -34,26 +34,11 @@ public void Awake()
// 这里初始化base值
}

public float GetAsFloat(NumericType numericType)
{
return (float)GetByKey((int)numericType) / 10000;
}

public float GetAsFloat(int numericType)
{
return (float)GetByKey(numericType) / 10000;
}

public int GetAsInt(NumericType numericType)
{
return (int)GetByKey((int)numericType);
}

public long GetAsLong(NumericType numericType)
{
return GetByKey((int)numericType);
}

public int GetAsInt(int numericType)
{
return (int)GetByKey(numericType);
Expand All @@ -64,36 +49,36 @@ public long GetAsLong(int numericType)
return GetByKey(numericType);
}

public void Set(NumericType nt, float value)
public void Set(int nt, float value)
{
this[nt] = (int) (value * 10000);
}

public void Set(NumericType nt, int value)
public void Set(int nt, int value)
{
this[nt] = value;
}

public void Set(NumericType nt, long value)
public void Set(int nt, long value)
{
this[nt] = value;
}

public long this[NumericType numericType]
public long this[int numericType]
{
get
{
return this.GetByKey((int) numericType);
return this.GetByKey(numericType);
}
set
{
long v = this.GetByKey((int) numericType);
long v = this.GetByKey(numericType);
if (v == value)
{
return;
}

NumericDic[(int)numericType] = value;
NumericDic[numericType] = value;

Update(numericType);
}
Expand All @@ -106,7 +91,7 @@ private long GetByKey(int key)
return value;
}

public void Update(NumericType numericType)
public void Update(int numericType)
{
if (numericType < NumericType.Max)
{
Expand All @@ -127,7 +112,7 @@ public void Update(NumericType numericType)
Game.EventSystem.Publish(new EventType.NumbericChange()
{
Parent = this.Parent,
NumericType = (NumericType) final,
NumericType = final,
Old = old,
New = result
});
Expand Down
51 changes: 26 additions & 25 deletions Unity/Codes/Model/Module/Numeric/NumericType.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
namespace ET
{
public enum NumericType
// 这个可弄个配置表生成
public static class NumericType
{
Max = 10000,
public const int Max = 10000;

Speed = 1000,
SpeedBase = Speed * 10 + 1,
SpeedAdd = Speed * 10 + 2,
SpeedPct = Speed * 10 + 3,
SpeedFinalAdd = Speed * 10 + 4,
SpeedFinalPct = Speed * 10 + 5,

Hp = 1001,
HpBase = Hp * 10 + 1,
public const int Speed = 1000;
public const int SpeedBase = Speed * 10 + 1;
public const int SpeedAdd = Speed * 10 + 2;
public const int SpeedPct = Speed * 10 + 3;
public const int SpeedFinalAdd = Speed * 10 + 4;
public const int SpeedFinalPct = Speed * 10 + 5;

MaxHp = 1002,
MaxHpBase = MaxHp * 10 + 1,
MaxHpAdd = MaxHp * 10 + 2,
MaxHpPct = MaxHp * 10 + 3,
MaxHpFinalAdd = MaxHp * 10 + 4,
MaxHpFinalPct = MaxHp * 10 + 5,

AOI = 1003,
AOIBase = AOI * 10 + 1,
AOIAdd = AOI * 10 + 2,
AOIPct = AOI * 10 + 3,
AOIFinalAdd = AOI * 10 + 4,
AOIFinalPct = AOI * 10 + 5,
}
public const int Hp = 1001;
public const int HpBase = Hp * 10 + 1;

public const int MaxHp = 1002;
public const int MaxHpBase = MaxHp * 10 + 1;
public const int MaxHpAdd = MaxHp * 10 + 2;
public const int MaxHpPct = MaxHp * 10 + 3;
public const int MaxHpFinalAdd = MaxHp * 10 + 4;
public const int MaxHpFinalPct = MaxHp * 10 + 5;

public const int AOI = 1003;
public const int AOIBase = AOI * 10 + 1;
public const int AOIAdd = AOI * 10 + 2;
public const int AOIPct = AOI * 10 + 3;
public const int AOIFinalAdd = AOI * 10 + 4;
public const int AOIFinalPct = AOI * 10 + 5;
}
}
4 changes: 2 additions & 2 deletions Unity/Codes/Model/Module/Numeric/NumericWatcherAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
public class NumericWatcherAttribute : BaseAttribute
{
public NumericType NumericType { get; }
public int NumericType { get; }

public NumericWatcherAttribute(NumericType type)
public NumericWatcherAttribute(int type)
{
this.NumericType = type;
}
Expand Down
10 changes: 5 additions & 5 deletions Unity/Codes/Model/Module/Numeric/NumericWatcherComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class NumericWatcherComponent : Entity, IAwake, ILoad
{
public static NumericWatcherComponent Instance { get; set; }

private Dictionary<NumericType, List<INumericWatcher>> allWatchers;
private Dictionary<int, List<INumericWatcher>> allWatchers;

public void Awake()
{
Expand All @@ -38,7 +38,7 @@ public void Awake()

public void Load()
{
this.allWatchers = new Dictionary<NumericType, List<INumericWatcher>>();
this.allWatchers = new Dictionary<int, List<INumericWatcher>>();

HashSet<Type> types = Game.EventSystem.GetTypes(typeof(NumericWatcherAttribute));
foreach (Type type in types)
Expand All @@ -58,16 +58,16 @@ public void Load()
}
}

public void Run(NumericType numericType, long id, long value)
public void Run(EventType.NumbericChange args)
{
List<INumericWatcher> list;
if (!this.allWatchers.TryGetValue(numericType, out list))
if (!this.allWatchers.TryGetValue(args.NumericType, out list))
{
return;
}
foreach (INumericWatcher numericWatcher in list)
{
numericWatcher.Run(id, value);
numericWatcher.Run(args);
}
}
}
Expand Down
Loading

0 comments on commit f22df5b

Please sign in to comment.