Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

InlineText在列表划动过快时,表情容易位置偏移 #46

Open
lizijie opened this issue Sep 11, 2019 · 2 comments
Open

InlineText在列表划动过快时,表情容易位置偏移 #46

lizijie opened this issue Sep 11, 2019 · 2 comments

Comments

@lizijie
Copy link
Contributor

lizijie commented Sep 11, 2019

渲染一个表情在v3.0的实现里,流程大致如下:
【流程一】 InlineText.OnPopulateMesh转换表情顶点至全局坐标,InlineManager.UpdateTextInfo再将全局坐标转换到SpriteGraphic下的局部坐标。
【流程二】 InlineManager.Update合批相同表情ID的Mesh,转输到SpriteGraphic.OnPopulateMesh作最终渲染。

因为InlineManager.Update合批Mesh,所以这两个流程相差1帧。如果InlineText的坐标在这帧变动了(如列表划动),因为没其它逻辑去强刷缓存在InlineManager的EmojiText.Taurus.MeshInfo坐标,所以SpriteGraphic.OnPopulateMesh使用的是不正确的坐标。结果显示上表情位置偏移了。

像ChatTest样例中,监听ScrollRect.onValueChanged事件,修复SpriteGraphic坐标并未解决以上问题。因为它是与 【流程一】 同帧进行。依然与 【流程二】 相差了1帧。

private void OnSrcollViewChanged(Vector2 pos)
{
    _spriteRect.anchoredPosition = _scrollView.content.anchoredPosition;
}

测试代码如下:

public class Test : MonoBehaviour
{
    public InlineText inText = null;
    public SpriteGraphic graphic = null;

    void Start()
    {
        inText.text = "NewText[#emoji_0]";

		// 模拟在【流程一】与【流程二】中间1帧,修改了InlineText坐标
        graphic.RegisterDirtyVerticesCallback(() =>
        {
            inText.transform.localPosition = new Vector3(200, 200, 0);
        });
    }
}

执行结果如下
image

@lizijie lizijie changed the title InlineText位置偏移的原因 InlineText在列表划动过快时位置偏移 Sep 11, 2019
@lizijie lizijie changed the title InlineText在列表划动过快时位置偏移 InlineText在列表划动过快时,表情容易位置偏移 Sep 11, 2019
@linchenrr
Copy link

兄弟,这个问题找到解决办法了吗? 哪怕是牺牲一些性能对特定的会移动的文本框强制刷新也好

@lizijie
Copy link
Contributor Author

lizijie commented Oct 26, 2019

@linchenrr
像UGUI ScrollRect需要平滑过度,每次update强刷表情消耗太大了。我基于InlineText3. 0版本作了修改https://lizijie.github.io/2019/09/18/%E8%AE%B0%E4%B8%80%E6%AC%A1%E4%BF%AE%E6%94%B9unity3d%E5%AF%8C%E6%96%87%E6%9C%AC%E6%8F%92%E4%BB%B6%E7%9A%84%E8%AE%BE%E8%AE%A1%E7%BC%BA%E9%99%B7.html

对于不需要平滑过渡(瞬移),用作者ChatTest例子中监听ScrollRect得滑动事件的方法的可以了

private void OnSrcollViewChanged(Vector2 pos)
{
_spriteRect.anchoredPosition = _scrollView.content.anchoredPosition;
}

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

No branches or pull requests

2 participants