Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UICanvas.lua代码中存在逻辑异常 #68

Open
zhang00lei opened this issue Jun 23, 2021 · 1 comment
Open

UICanvas.lua代码中存在逻辑异常 #68

zhang00lei opened this issue Jun 23, 2021 · 1 comment

Comments

@zhang00lei
Copy link

local function OnCreate(self, relative_order)
	base.OnCreate(self)
	-- Unity侧原生组件
	self.unity_canvas = nil
	self.unity_graphic_raycaster = nil
	
	-- canvas
	self.unity_canvas = UIUtil.FindComponent(self.transform, typeof(CS.UnityEngine.Canvas))
	if IsNull(self.unity_canvas) then
		self.unity_canvas = self.gameObject:AddComponent(typeof(CS.UnityEngine.Canvas))
	end
	self.unity_canvas.overrideSorting = true
	self.unity_canvas.sortingLayerName = SortingLayerNames.UI
	
	-- raycaster
	self.unity_graphic_raycaster = UIUtil.FindComponent(self.transform, typeof(CS.UnityEngine.UI.GraphicRaycaster))
	if IsNull(self.unity_graphic_raycaster) then
		self.unity_graphic_raycaster = self.gameObject:AddComponent(typeof(CS.UnityEngine.UI.GraphicRaycaster))
	end
	
	-- order
	self.relative_order = relative_order or 0
	self:SetOrder(self.relative_order)
end

若self.transform不存在Canvas组件,但是子物体存在Canvas组件,则这条代码self.unity_canvas = UIUtil.FindComponent(self.transform, typeof(CS.UnityEngine.Canvas))获取到的unity_canvas为子物体的Canvas,并未在当前self.transform上添加组件Canvas。GraphicRaycaster组件同理。
不知是否为有意为之。

@zhCNLiang
Copy link

是一个bug,获取子节点Canvas没有意义

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants