Files
JJBB/Assets/Project/Script/LuaScripts/UI/Lua/PropBaseAttr/PropBaseAttr.txt

193 lines
6.7 KiB
Plaintext
Raw Normal View History

2024-08-23 15:49:34 +08:00
require("LuaUtil")
require("Util")
PropBaseAttr = {}
--开始的属性显示
local _Attr1
local _Attr2
local _Attr3
--新的属性显示
local _newAttr1
local _newAttr2
local _newAttr3
function PropBaseAttr.Awake( )
_Attr1 = Attr1:GetComponent("Text")
_Attr2 = Attr2:GetComponent("Text")
_Attr3 = Attr3:GetComponent("Text")
_newAttr1 = newAttr1:GetComponent("Text")
_newAttr2 = newAttr2:GetComponent("Text")
_newAttr3 = newAttr3:GetComponent("Text")
_newAttr1.gameObject:SetActive(true)
_newAttr2.gameObject:SetActive(true)
_Attr1.text = ''
_Attr2.text = ''
_Attr3.text = ''
end
function PropBaseAttr.OnEnable( )
_Attr1.gameObject:SetActive(false)
_Attr2.gameObject:SetActive(false)
_Attr3.gameObject:SetActive(false)
end
local _isShowTime = 0
local newStrList = {}
function PropBaseAttr.Update( )
_isShowTime = _isShowTime + CS.UnityEngine.Time.deltaTime
-- 血量 14499<color=#3ce067>+5%(词条)</color>
if _isShowTime >= 0.2 then
_isShowTime = 0
PropBaseAttr.ShowNewAttr_oneAndTwo(_Attr1,_newAttr1)
PropBaseAttr.ShowNewAttr_oneAndTwo(_Attr2,_newAttr2)
PropBaseAttr.ShowNewAttr_Three(_Attr3,_newAttr3)
end
end
local PropertyName = '' -- 属性名
local _newStr = '' -- 第一次分割生成的没有属性名的字符串
local shuxingzhi = 0 -- 基础属性值
local ciTiao = 1 -- 词条没有百分号的值10
-- 获取属性一 和 属性二
function PropBaseAttr.ShowNewAttr_oneAndTwo(_Attrs,_newAttrs)
if _Attrs ~= nil and _Attrs.text ~= '' and _Attrs.text ~= nil then
-- 分割字符
PropBaseAttr.ShowNewAttrs(_Attrs,_newAttrs)
local _AllJiaHao = PropBaseAttr.split(_Attrs.text,"+")
for k=1,#_AllJiaHao do
local newAttrProp = shuxingzhi/ciTiao
_Attrs.gameObject:SetActive(false)
_newAttrs.gameObject:SetActive(true)
local _mnewAttrProp = math.ceil(newAttrProp)
--Log('获取属性的新值(去掉词条的加成):'.._mnewAttrProp)
_newAttrs.text = PropertyName..' '.._mnewAttrProp ..string.gsub(_newStr, shuxingzhi, "")
local _newStr2 = string.gsub(_newAttrs.text, "%", "(")
_newAttrs.text = string.gsub(_newStr2, "%", ")")
--Log('最后新的Text的值'.._newAttrs.text)
end
if PropertyName.text == CS.GCGame.Table.StrDictionary.GetClientDictionaryString("#{12004}") then
_newAttrs.text = ''
_Attrs.gameObject:SetActive(true)
end
end
end
-- 因为属性三 可能是 百分比格式,单独获取
function PropBaseAttr.ShowNewAttr_Three(_Attrs,_newAttrs)
if _Attrs ~= nil and _Attrs.text ~= '' and _Attrs.text ~= nil then
-- 分割字符
PropBaseAttr.ShowNewAttrs(_Attrs,_newAttrs)
local _AllJiaHao = PropBaseAttr.split(_Attrs.text,"+")
for k=1,#_AllJiaHao do
local newAttrProp = 0
if shuxingzhi/ciTiao > 99 then
local newAttrProp11 = shuxingzhi/ciTiao
newAttrProp = math.ceil(newAttrProp11)
else
newAttrProp = string.format("%0.2g", shuxingzhi/ciTiao)
end
_Attrs.gameObject:SetActive(false)
--Log('获取属性的新值(去掉词条的加成):'..newAttrProp)
_newAttrs.text = PropertyName..' '..newAttrProp..string.gsub(_newStr, shuxingzhi, "")
--Log('最后新的Text的值'.._newAttrs.text)
end
if PropertyName.text == CS.GCGame.Table.StrDictionary.GetClientDictionaryString("#{12004}") then
_newAttrs.text = ''
_Attrs.gameObject:SetActive(true)
end
end
end
-- 分割字符串获取并计算属性值
function PropBaseAttr.ShowNewAttrs(_startAttr,_newAttr)
--Log('获取C#代码赋值的Text的值'.._startAttr.text)
--Log('如果上面的显示没有或者缺少属性的加成那新的text文本也不会显示属性加成')
local citiaoStr = '' -- 词条有百分号的值10%
local _kong = PropBaseAttr.split(_startAttr.text," ")
local _kuoHao_Z = PropBaseAttr.split(_startAttr.text,"")
_startAttr.gameObject:SetActive(false)
--_newAttr.gameObject:SetActive(true)
for i=1,#_kong do
PropertyName = _kong[1]
--Log('获取属性的名字:'..PropertyName)
_newStr = _kong[2]
--Log('获取属性的值和属性加成:'.._newStr)
local _DanShuMingHao = PropBaseAttr.split(_newStr,"<")
for ii=1,#_DanShuMingHao do
local shuxingzhiStr = _DanShuMingHao[1]
shuxingzhi = string.gsub(shuxingzhiStr, "%%", "")
--Log('获取属性的值(白色数字):'..shuxingzhi)
end
end
for j=1,#_kuoHao_Z do
if #_kuoHao_Z <= 1 then
_startAttr.gameObject:SetActive(true)
_newAttr.gameObject:SetActive(false)
end
local _entry = _kuoHao_Z[1]
local _jiaHao = PropBaseAttr.split(_entry,"+")
for jj=1,#_jiaHao do
if jj == #_jiaHao and #_jiaHao > 1 and #_kuoHao_Z > 1 then
citiaoStr = _jiaHao[jj]
--Log('获取词条的加成:'..citiaoStr)
local _mycustom = string.gsub(citiaoStr, "%%", "") + 0
if _mycustom > 100 then
ciTiao = 1
else
ciTiao = string.gsub(citiaoStr, "%%", "")/100 + 1
end
_startAttr.gameObject:SetActive(false)
if _startAttr == _newAttr3 then
_newAttr.gameObject:SetActive(true)
end
else
_startAttr.gameObject:SetActive(true)
if _startAttr == _newAttr3 then
_newAttr.gameObject:SetActive(false)
end
end
end
end
end
-- 参数:待分割的字符串,分割字符
-- 返回:子串表.(含有空串)
function PropBaseAttr.split(str, split_char)
if split_char ~= nil then
local sub_str_tab = {}
while true do
local pos = string.find(str, split_char)
if not pos then
table.insert(sub_str_tab,str)
break
end
local sub_str = string.sub(str, 1, pos - 1)
table.insert(sub_str_tab,sub_str)
str = string.sub(str, pos + 1, string.len(str))
end
return sub_str_tab
end
end
-- -- 使用空格分隔字符串
-- function PropBaseAttr.Ssplit(str, split_char)
-- local sub_str_tab = {}
-- for w in string.gmatch(str, "%S+") do
-- table.insert(sub_str_tab,w)
-- end
-- return sub_str_tab
-- end