源码10:InputField
InputField就是输入框 提供给用户输入文字内容的 是一个重要的交互手段。比如常见的用来输入用户名 ,密码等等。
public class InputField
: Selectable,
IUpdateSelectedHandler,
IBeginDragHandler,
IDragHandler,
IEndDragHandler,
IPointerClickHandler,
ISubmitHandler,
ICanvasElement,
ILayoutElement
{
...
}
上面就是InputField在实现过程中继承的类和接口 具体的接口描述就不再解释了,前面的文章说的比较多。
protected override void OnEnable()
{
base.OnEnable();
if (m_Text == null)
m_Text = string.Empty;
m_DrawStart = 0;
m_DrawEnd = m_Text.Length;
// If we have a cached renderer then we had OnDisable called so just restore the material.
if (m_CachedInputRenderer != null)
m_CachedInputRenderer.SetMaterial(m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture);
if (m_TextComponent != null)
{
m_TextComponent.RegisterDirtyVerticesCallback(MarkGeometryAsDirty);
m_TextComponent.RegisterDirtyVerticesCallback(UpdateLabel);
m_TextComponent.RegisterDirtyMaterialCallback(UpdateCaretMaterial);
UpdateLabel();
}
}
OnEnable 组件刚激活
1.设置了输入文字绘制开始和结束的位置
2.给文字组件添加了了两个RegisterDirtyVerticesCallback 事件MarkGeometryAsDirty 和UpdateLabel
调用了RegisterDirtyMaterialCallback,添加UpdateCaretMaterial回调
最后调用UpdateLable
private void MarkGeometryAsDirty()
{
#if UNITY_EDITOR
if (!Application.isPlaying || UnityEditor.PrefabUtility.IsPartOfPrefabAsset(gameObject))
return;
#endif
CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this);
}
M

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



