【优化】添加判断物体是否被销毁的方法,优化可能导致黑屏卡死的问题

dev_chengFeng
gaoxin 2021-08-25 20:59:26 +08:00
parent a6e93212d0
commit eebd99883b
16 changed files with 134 additions and 23 deletions

View File

@ -1 +1,66 @@
{"Setting":{"LanguagePackager":{"desc":"\u672C\u5730\u5316\u5904\u7406","versionCode":"26","isActive":"0"},"ServerVersion":{"desc":"\u7528\u4E8E\u5207\u6362\u6B63\u5F0F\u670D\u548C\u63D0\u5BA1\u670D","value":"0","versionCode":"26","isActive":"1"},"ThinkAnalysis_GetDeviceID":{"desc":"\u6570\u6570\u83B7\u53D6DeviceID\u65B9\u6CD5","versionCode":"24","isActive":"1"},"LayoutBuilderWrap":{"desc":"\u5F3A\u5236\u5237\u65B0layout\u7EC4\u4EF6\u5927\u5C0F\u7684\u65B9\u6CD5\u4FEE\u6539\u5230lua\u4E2D\u8C03\u7528","versionCode":"25","isActive":"1"},"IS_PLAY_VOICE":{"desc":"","versionCode":"1","isActive":"1"},"IS_TITLE_EFFECT_SCALE":{"desc":"","versionCode":"1","isActive":"1"},"IS_PLAY_LOGIN_VIDEO":{"desc":"","versionCode":"1","isActive":"1"},"PACKAGE_CC_CODE":{"desc":"","versionCode":"1","isActive":"1","value":"1001"},"CURVED_TEXT_CODE":{"desc":"\u662F\u5426\u53EF\u4EE5\u663E\u793A\u5F27\u5F62\u6587\u5B57","versionCode":"30","isActive":"1"},"IS_SELECT_RESLUTION":{"desc":"\u662F\u5426\u53EF\u4EE5\u9009\u62E9\u5E27\u7387","versionCode":"30","isActive":"1"}}}
{
"Setting": {
"LanguagePackager": {
"desc": "",
"versionCode": "26",
"isActive": "0"
},
"ServerVersion": {
"desc": "",
"value": "0",
"versionCode": "26",
"isActive": "1"
},
"ThinkAnalysis_GetDeviceID": {
"desc": "",
"versionCode": "24",
"isActive": "1"
},
"LayoutBuilderWrap": {
"desc": "",
"versionCode": "25",
"isActive": "1"
},
"IS_PLAY_VOICE": {
"desc": "",
"versionCode": "1",
"isActive": "1"
},
"IS_TITLE_EFFECT_SCALE": {
"desc": "",
"versionCode": "1",
"isActive": "1"
},
"IS_PLAY_LOGIN_VIDEO": {
"desc": "",
"versionCode": "1",
"isActive": "1"
},
"PACKAGE_CC_CODE": {
"desc": "",
"versionCode": "1",
"isActive": "1",
"value": "1001"
},
"CURVED_TEXT_CODE": {
"desc": "",
"versionCode": "30",
"isActive": "1"
},
"IS_SELECT_RESLUTION": {
"desc": "",
"versionCode": "30",
"isActive": "1"
},
"INNER_WEB_CONTROL": {
"desc": "",
"versionCode": "1",
"isActive": "1"
},
"IS_NULL": {
"desc": "",
"versionCode": "1",
"isActive": "1"
}
}
}

View File

@ -1341,7 +1341,14 @@ end
---obj必须是userdata(c#对象)
function IsNull(obj)
return obj == nil or obj:Equals(nil)
if not obj then
return true
end
if ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.IS_NULL) then
return obj:IsNull()
else
return obj == nil or obj:Equals(nil)
end
end
------- 红点相关 ----------

View File

@ -203,7 +203,8 @@ function PoolManager:UnLoadAsset(resName,res, assetType)
--then
if assetType == PoolManager.AssetType.GameObject
and res
and tostring(res) ~= "null" then
and tostring(res) ~= "null"
and not IsNull(res) then
res.transform:SetParent(self.mPoolTrans)
if #pool.resList <= 5 then
table.insert(pool.resList,res)

View File

@ -24,6 +24,7 @@ ServerConfigManager.SettingConfig = {
USER_PROTO = "USER_PROTO", -- 用户协议功能是否开启
IS_NO_NOTICE = "IS_NO_NOTICE", -- 是否禁用公告
INNER_WEB_CONTROL = "INNER_WEB_CONTROL", -- 是否使用内置浏览器
IS_NULL = "IS_NULL", -- 使用C#判断物体是否销毁
}

View File

@ -148,7 +148,7 @@ function this.GetBattleBestData(Id)
local battleRecord = this.GetBattleRecord(Id)
for _, data in pairs(battleRecord.data) do
-- 怪物只显示最后一层的怪物信息
if data.info.camp == 0 then
if data.info and data.info.camp == 0 then
-- 计算最大值(不计算异妖的)
if data.info.type == BattleUnitType.Role then
if data.damage > _MaxDamageValue then

View File

@ -47,6 +47,9 @@ function SkillCaster:OnSkillCast(skill)
local duration = combat.KeyFrame/1000
local function _PlaySkill()
if IsNull(self.owner.GameObject) then
return
end
-- 调用上层接口
if self.owner.OnSkillPlay then
self.owner:OnSkillPlay()

View File

@ -476,15 +476,6 @@ end
function CarbonScoreSortPanel:OnClose()
if callBack then callBack() end
this.noneImage:SetActive(false)
if this.ScrollView then
SubUIManager.Close(this.ScrollView)
end
this.ScrollView = nil
end
--界面销毁时调用(用于子类重写)
function CarbonScoreSortPanel:OnDestroy()
this.spLoader:Destroy()
for _, playerHead in pairs(_PlayerHeadList) do
playerHead:Recycle()
end
@ -495,5 +486,18 @@ function CarbonScoreSortPanel:OnDestroy()
this.ScrollView = nil
end
--界面销毁时调用(用于子类重写)
function CarbonScoreSortPanel:OnDestroy()
this.spLoader:Destroy()
-- for _, playerHead in pairs(_PlayerHeadList) do
-- playerHead:Recycle()
-- end
-- _PlayerHeadList = {}
-- if this.ScrollView then
-- SubUIManager.Close(this.ScrollView)
-- end
-- this.ScrollView = nil
end
return CarbonScoreSortPanel

View File

@ -288,7 +288,7 @@ function this.RemainTimeDown(_timeTextExpertgo,_timeTextExpert,timeDown,str)
this.timer = nil
end
this.timer = Timer.New(function()
if _timeTextExpert and tostring(_timeTextExpert) ~= "null" then
if not IsNull(_timeTextExpert) and tostring(_timeTextExpert) ~= "null" then
if str then
_timeTextExpert.text = str..this.TimeStampToDateString(timeDown)
else
@ -296,7 +296,7 @@ function this.RemainTimeDown(_timeTextExpertgo,_timeTextExpert,timeDown,str)
end
end
if timeDown < 0 then
if _timeTextExpertgo then
if not IsNull(_timeTextExpertgo) then
_timeTextExpertgo:SetActive(false)
end
this.timer:Stop()

View File

@ -127,7 +127,7 @@ function SingleRecruitPanel:BindEvent()
end
end)
Util.AddClick(this.dragView.gameObject, function ()
if testLiveGO then
if not IsNull(testLiveGO) then
local SkeletonGraphic = testLiveGO:GetComponent("SkeletonGraphic")
SkeletonGraphic.AnimationState:SetAnimation(0, "touch", false)
end

View File

@ -403,7 +403,11 @@ function this:UpdateBtnList()
tabsList = {}
end
for k,v in pairs(tabsList) do
tabsList[k].gameObject:SetActive(false)
if IsNull(tabsList[k]) then
tabsList[k] = nil
else
tabsList[k].gameObject:SetActive(false)
end
end
for k,v in ipairs(tabs) do
if not tabsList[k] then

View File

@ -468,8 +468,8 @@ function this:SetShow(showIndex)
item = self.cellItemList[j][i]
index = j+(i-1)*self.fixedCount
dataIndex = j+(i-1 + self.dataLine)*self.fixedCount
if not item.go then
if IsNull(item.go) then
local go = newObject(self.item)
go.transform:SetParent(self.dragGO.transform)
go.transform.localScale = Vector3.one

View File

@ -745,7 +745,7 @@ function SingleFightPlayerView:pravite_ShakeObjOnce(go, isReverse, roleFaceDir,
local offSet = isReverse and 90 or 120
offSet = offSet / math.min(Screen.width/1080, Screen.height/1920)
if go then
if not IsNull(go) then
local originPos = go:GetComponent("RectTransform").anchoredPosition
local value = isReverse and -1 or 1
local targetPos = originPos + Vector2.New(offSet * roleFaceDir.x * value, offSet * roleFaceDir.y * value)

View File

@ -209,7 +209,7 @@ function UpView:UpdateGoldVal()
local panelShowItemList = self.itemList
for i = 1, _ItemMaxNum do
if panelShowItemList[i] then
if self.cnyList[i].gameObject then
if not IsNull(self.cnyList[i]) and self.cnyList[i].gameObject then
self.cnyList[i].gameObject:SetActive(true)
Util.GetGameObject(self.cnyList[i].gameObject, "icon"):GetComponent("Image").sprite = SetIcon(self.spLoader, panelShowItemList[i])
Util.GetGameObject(self.cnyList[i].gameObject, "addFlag"):SetActive(_IsShowPlus(panelShowItemList[i]))
@ -234,7 +234,7 @@ function UpView:UpdateGoldVal()
self:_BindRP(panelShowItemList[i], redpot)
end
else
if self.cnyList[i].gameObject then
if not IsNull(self.cnyList[i]) and self.cnyList[i].gameObject then
self.cnyList[i].gameObject:SetActive(false)
end
end

View File

@ -123,7 +123,7 @@ public static class CustomSettings
_GT(typeof(PlayerPrefs)),
_GT(typeof(Behaviour)),
_GT(typeof(MonoBehaviour)),
_GT(typeof(GameObject)),
_GT(typeof(GameObject)).AddExtendType(typeof(UnityEngineObjectExtention)),
_GT(typeof(TrackedReference)),
_GT(typeof(Application)),
_GT(typeof(Physics)),

View File

@ -15,4 +15,11 @@ namespace GameLogic
return t;
}
}
public static class UnityEngineObjectExtention
{
public static bool IsNull(this UnityEngine.Object o) // 或者名字叫IsDestroyed等等
{
return o == null;
}
}
}

View File

@ -1,5 +1,6 @@
//this source code was auto-generated by tolua#, do not modify it
using System;
using GameLogic;
using LuaInterface;
public class UnityEngine_GameObjectWrap
@ -24,6 +25,7 @@ public class UnityEngine_GameObjectWrap
L.RegFunction("BroadcastMessage", BroadcastMessage);
L.RegFunction("SendMessageUpwards", SendMessageUpwards);
L.RegFunction("SendMessage", SendMessage);
L.RegFunction("IsNull", IsNull);
L.RegFunction("New", _CreateUnityEngine_GameObject);
L.RegFunction("__eq", op_Equality);
L.RegFunction("__tostring", ToLua.op_ToString);
@ -716,6 +718,23 @@ public class UnityEngine_GameObjectWrap
}
}
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int IsNull(IntPtr L)
{
try
{
ToLua.CheckArgsCount(L, 1);
UnityEngine.GameObject obj = (UnityEngine.GameObject)ToLua.CheckObject(L, 1, typeof(UnityEngine.GameObject));
bool o = obj.IsNull();
LuaDLL.lua_pushboolean(L, o);
return 1;
}
catch (Exception e)
{
return LuaDLL.toluaL_exception(L, e);
}
}
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int op_Equality(IntPtr L)
{