49 lines
1.1 KiB
Lua
49 lines
1.1 KiB
Lua
---
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
--- Created by yh.
|
|
--- DateTime: 2023/8/24 13:26
|
|
---
|
|
--- 存储变量,
|
|
local Attributes = {
|
|
};
|
|
|
|
-- 初始化对应属性表
|
|
function Attributes:InitAttributeTable(InTable)
|
|
if InTable == nil then
|
|
print(string.format("[Attributes:InitAttributeTable] 传入的表为空,无法进行初始化"))
|
|
return;
|
|
end
|
|
local TheType = type(InTable)
|
|
if TheType ~= 'table' then
|
|
print(string.format("[Attributes:InitAttributeTable] 传入的数据不是表类型结构,无法进行初始化"));
|
|
return;
|
|
end
|
|
|
|
-- 拷贝过来
|
|
TableHelper.CopyToTable(self, InTable);
|
|
end
|
|
|
|
-- 添加属性
|
|
function Attributes:AddAttribute(InKey, InValue)
|
|
if self[InKey] == nil then
|
|
self[InKey] = 0.
|
|
end
|
|
-- 检查一下是否是数值
|
|
assert(type(self[InKey]) == 'number', string.format("当前元素 %s 需要为数值", tostring(InKey)))
|
|
self[InKey] = self[InKey] + InValue;
|
|
end
|
|
|
|
-- 设置属性的值
|
|
function Attributes:SetAttribute(InKey, InValue)
|
|
self[InKey] = InValue;
|
|
end
|
|
|
|
function Attributes:GetAttribute(InKey)
|
|
return self[InKey];
|
|
end
|
|
|
|
function Attributes:GetAllAttributes()
|
|
return self;
|
|
end
|
|
|
|
return Attributes; |