80 lines
2.3 KiB
Lua
80 lines
2.3 KiB
Lua
local M = {
|
|
--记录当前地图自定义图标生成的GUID
|
|
GenGUID = 0,
|
|
--自定义对象字典
|
|
CustomIdDic = Dictionary:New(),
|
|
CustomTypeDic = Dictionary:New(),
|
|
}
|
|
|
|
function M:Initialize()
|
|
self.GenGUID = 0;
|
|
self.CustomIdDic:Clear();
|
|
self.CustomTypeDic:Clear();
|
|
end
|
|
|
|
function M:UnInitialize()
|
|
|
|
end
|
|
|
|
--获取地图自定义图标生成的唯一ID
|
|
function M:GetGUID()
|
|
self.GenGUID = self.GenGUID + 1;
|
|
return self.GenGUID;
|
|
end
|
|
|
|
--增加自定义对象[customType : MapCustomType]
|
|
function M:AddObject(customType, name, worldPosX, worldPosZ)
|
|
local _guid = self:GetGUID();
|
|
local _data = {Id = _guid, CustomType = customType, Name = name or "", WorldPosX = worldPosX, WorldPosZ = worldPosZ};
|
|
self.CustomIdDic:Add(_guid, _data);
|
|
if not self.CustomTypeDic:ContainsKey(customType) then
|
|
self.CustomTypeDic:Add(customType, Dictionary:New());
|
|
end
|
|
self.CustomTypeDic[customType]:Add(_guid, _data)
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_MAP_CUSTOMOBJECT_REFESH);
|
|
return _guid;
|
|
end
|
|
|
|
--设置位置
|
|
function M:SetPos(id, worldPosX, worldPosZ)
|
|
local _customObj = self.CustomIdDic[id];
|
|
if _customObj then
|
|
_customObj.WorldPosX = worldPosX;
|
|
_customObj.WorldPosZ = worldPosZ;
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_MAP_CUSTOMOBJECT_REFESH);
|
|
end
|
|
end
|
|
|
|
--改变名字
|
|
function M:ChangeName(id, name)
|
|
local _customObj = self.CustomIdDic[id];
|
|
if _customObj then
|
|
_customObj.Name = name or "";
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_MAP_CUSTOMOBJECT_REFESH);
|
|
end
|
|
end
|
|
|
|
--移除自定义对象
|
|
function M:RemoveObject(id)
|
|
local _data = self.CustomIdDic[id];
|
|
if _data then
|
|
self.CustomIdDic:Remove(id);
|
|
self.CustomTypeDic[_data.CustomType]:Remove(id)
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_MAP_CUSTOMOBJECT_REFESH);
|
|
end
|
|
end
|
|
|
|
--按类型移除自定义对象
|
|
function M:RemoveObjectByType()
|
|
--TODO
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_MAP_CUSTOMOBJECT_REFESH);
|
|
end
|
|
|
|
--移除所有自定义对象
|
|
function M:ClearObject()
|
|
self.CustomIdDic:Clear();
|
|
self.CustomTypeDic:Clear();
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_MAP_CUSTOMOBJECT_REFESH);
|
|
end
|
|
|
|
return M |