当前位置:网站首页>Ugui source code analysis - maskablegraphic
Ugui source code analysis - maskablegraphic
2022-07-24 02:48:00 【Hello Bug.】
One : Preface
seeing the name of a thing one thinks of its function ,MaskableGraphic Is an image that can be masked , Strictly speaking, it should be an image that can be masked and cropped , But it inherits from Graphic Classes and IClippable、IMaskable、IMaterialModifier Interface , stay Graphic It realizes the functions of clipping and masking
Image、RawImage、Text Inherit from MaskableGraphic class
Two : Source code analysis —— Class head

MaskableGraphic Inherited from Graphic class ,IClippable、IMaskable、IMaterialModifier Interface , Inherited from Graphic Class means that it is responsible for the display and update of images
Image、RawImage、Text Inherit from MaskableGraphic class
3、 ... and : The source code parsing —— Inherited from UIBehaviour Methods
——OnEnable
The first set m_ShouldRecalculateStencil( Whether the template material needs to be recalculated ) by true, Then call UpdateClipParent Update the corresponding RectMask2D object , And then call SetMaterialDirty Update material , If it is an image that can be masked, call MaskUtilities.NotifyStencilStateChanged Update material
UpdateClipParent The method is to realize RectMask2D, Other methods are to achieve Mask
——OnDisable
The first set m_ShouldRecalculateStencil( Whether the template material needs to be recalculated ) by true, Then call SetMaterialDirty Update material , And then call UpdateClipParent Update the corresponding RectMask2D object , Then remove the mask material and set it empty , If it is an image that can be masked, call MaskUtilities.NotifyStencilStateChanged Update material
UpdateClipParent The method is to realize RectMask2D, Other methods are to achieve Mask
Four : The source code parsing —— Inherited from IClippable Methods (RectMask2D Component related )
——RecalculateClipping
call UpdateClipParent Method , Update the corresponding RectMask2D object
stay MaskUtilities.Notify2DMaskStateChanged Call in method
——Cull
If validRect by false Or input clipRect And belong to Canvas The rectangular areas of do not coincide , call UpdateCull Method to add this object to the image reconstruction sequence
stay RectMask2D Of PerformClipping Call in method
——SetClipRect
according to validRect Parameters , by canvasRenderer Turn rectangle clipping on or off ( Pass in Shader)
stay RectMask2D Of PerformClipping Call in method
——SetClipSoftness
Set gradient
stay RectMask2D Of PerformClipping Call in method
5、 ... and : The source code parsing —— Inherited from IMaskable Methods
——RecalculateMasking
Remove the mask material and leave it empty , Set up m_ShouldRecalculateStencil( Whether the template material needs to be recalculated ) by true, Last call SetMaterialDirty Update material
stay MaskUtilities.NotifyStencilStateChanged Call in method
6、 ... and : The source code parsing —— Inherited from IMaterialModifier Methods
——GetModifiedMaterial
Get material ( Subclasses will be called when updating materials Graphic Of materialForRendering Get the currently rendered material and assign it to canvasRenderer Rendering )
If you need to recalculate the template material, first find the root canvas of the object , Then calculate the distance between itself and the root canvas Mask The number of , If there is only one oneself Mask be m_StencilValue by 0,m_StencilValue To express with Mask Of desiredStencilBit Reference value for comparison , If m_StencilValue Greater than 0 And this Graphic Not a mask image , adopt StencilMaterial.Add Get a new material (StencilOp.Replace-2,CompareFunction.Equal-3) And return this material to
Graphic There are three kinds of materials in :defaultMaterial( Default material )、material( texture of material ) and materialForRendering( Render material ), Give priority to rendering materials , If there is no implementation IMaterialModifier The components of the interface are rendered with the same material , If no material is assigned , Then use the default material
defaultMaterial:defaultGraphicMaterial
material: Assigned material , Generally, this material is used
materialForRendering: If there is an implementation IMaterialModifier The components of the interface will modify the material to achieve the mask effect , If there is no implementation IMaterialModifier The components of the interface are rendered with the same material
7、 ... and : The source code parsing ——MaskableGraphic Built-in methods
——UpdateClipParent![]()
to update m_ParentMask( In the parent object RectMask2D Components )
First, find the parent object RectMask2D Components (RectMask2D Components can be based on RectTransform Prune sub objects , The child object exceeds the parent RectTransform The part of the scope will be cut out )
If m_ParentMask Not empty and new RectMask2D Just like before m_ParentMask Different , Just take yourself from RectMask2D Of m_ClipTargets Remove from the crop target , And in RemoveClippable In the method , call clippable.SetClipRect(new Rect(), false), Turn off rectangle clipping
If the new RectMask2D Not empty and active , Just add yourself to RectMask2D Of m_ClipTargets Clipping target
Last , Put the new RectMask2D Assign a value to m_ParentMask
——UpdateCull
If canvasRenderer.cull When something changes , Send events m_OnCullStateChanged, And call the OnCullingChanged Method to add this object to the image reconstruction sequence
边栏推荐
- [FPGA tutorial case 39] communication case 9 - interleaving deinterleaving data transmission based on FPGA
- Mysql database, query
- Redis data type concept
- Mysql数据库,查询篇
- Attack and defense world web practice area (view_source, get_post, robots)
- Discussion on sending redundant API requests for Spartacus UI transfer state of SAP e-commerce cloud
- To forge ahead on a new journey, the city chain science and technology carnival was grandly held in Xiamen
- [diary of supplementary questions] [2022 Niuke summer school 1] i-chiitoitsu
- 508. 出现次数最多的子树元素和-哈希表法纯c实现
- Composition API (in setup) watch usage details
猜你喜欢

Tutoriel sur l'utilisation de la ligne de temps unitaire

Attack and defense world web practice area (view_source, get_post, robots)

Unity TimeLine使用教程

Nirvana rebirth! Byte Daniel recommends a large distributed manual, and the Phoenix architecture makes you become a God in fire
![[datasets] - downloading some datasets of flyingthings3d optical flow](/img/00/5d87b378ebab49e9dc400d8e3634f3.png)
[datasets] - downloading some datasets of flyingthings3d optical flow

508. The subtree element with the most occurrences and the pure C implementation of hash table method
![[leetcode] sword finger offer 61. shunzi in playing cards](/img/ca/1756f1c33cf9b18d0c88d46bac636e.png)
[leetcode] sword finger offer 61. shunzi in playing cards
![[knowledge atlas] practice -- Practice of question and answer system based on medical knowledge atlas (Part2): Atlas data preparation and import](/img/4b/c24ac8a11d15285a49d7b3b9bde4e3.png)
[knowledge atlas] practice -- Practice of question and answer system based on medical knowledge atlas (Part2): Atlas data preparation and import

Composition API (in setup) watch usage details

Dynamic programming-01 knapsack problem
随机推荐
Summernote supports custom video upload function
C language exercises
Causal learning open source project: from prediction to decision!
I'm a novice. I heard that there is a breakeven financial product in opening an account. What is it?
云原生讲解【扩展篇】
(6) Decorator extension [email protected] Principle of use
go IO操作-文件读
Unscramble the category and application principle of robot vision
SIGIR‘22 推荐系统论文之多样性篇
TP5 framework link promotion project
508. The subtree element with the most occurrences and the pure C implementation of hash table method
攻防世界WEB练习区(view_source、get_post、robots)
Only beautiful ones can be opened
相关性(correlation)
SSM family financial management personal financial management system accounting system
Openresty Lua resty balancer dynamic load balancing
js傳參時傳入 string有數據;傳入 number時沒有數據;2[0]是對的!number類型數據可以取下標
summernote富文本编辑器
Understand the timing of loading classes into the JVM
C language actual combat guessing game