所以我设法创建了一个自定义编辑器窗口,用于选择动画片段并将其所有文本读入字符串。现在我需要解析字符串以找出曲线计数和curveMapping,这样我就可以创建一个覆盖值的新文件。我感兴趣的字符串部分如下所示:
m_PPtrCurves:
- curve:
- time: 0
value: {fileID: 21300000, guid: 1fa82f3b0bb4e1f49ab9a9ffd4e891b1, type: 3}
- time: 0.6
value: {fileID: 21300000, guid: ae9111d826eb24442b21523b30b748bd, type: 3}
- time: 0.6666667
value: {fileID: 21300000, guid: 88840e4f59c4a6040922d9b6eed3dec3, type: 3}
- time: 1.2333333
value: {fileID: 21300000, guid: 88840e4f59c4a6040922d9b6eed3dec3, type: 3}
- time: 2.0001667
value: {fileID: 21300000, guid: ae9111d826eb24442b21523b30b748bd, type: 3}
- time: 2.05
value: {fileID: 21300000, guid: 1fa82f3b0bb4e1f49ab9a9ffd4e891b1, type: 3}
- time: 3.1166666
value: {fileID: 21300000, guid: 502fc97a961e4424ea008c0e546c83ef, type: 3}
- time: 3.45
value: {fileID: 21300000, guid: 1fa82f3b0bb4e1f49ab9a9ffd4e891b1, type: 3}
attribute: m_Sprite
path:
classID: 114
script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
并且:
pptrCurveMapping:
- {fileID: 21300000, guid: 1fa82f3b0bb4e1f49ab9a9ffd4e891b1, type: 3}
- {fileID: 21300000, guid: ae9111d826eb24442b21523b30b748bd, type: 3}
- {fileID: 21300000, guid: 88840e4f59c4a6040922d9b6eed3dec3, type: 3}
- {fileID: 21300000, guid: 88840e4f59c4a6040922d9b6eed3dec3, type: 3}
- {fileID: 21300000, guid: ae9111d826eb24442b21523b30b748bd, type: 3}
- {fileID: 21300000, guid: 1fa82f3b0bb4e1f49ab9a9ffd4e891b1, type: 3}
- {fileID: 21300000, guid: 502fc97a961e4424ea008c0e546c83ef, type: 3}
- {fileID: 21300000, guid: 1fa82f3b0bb4e1f49ab9a9ffd4e891b1, type: 3}
现在我会完全诚实。在这种情况下,我对RegEx一无所知或如何构建它以帮助我。首先,我需要计算曲线以在我的自定义窗口中生成适当数量的项目,然后我需要用新的曲线替换每条曲线的guid值。
答案 0 :(得分:4)
这只是一个YAML文件,不要试图用Regex解析它,它会造成一个难以维护的混乱。
添加类似YamlDotNet之类的内容,并通过一个简单易读的面向对象的界面访问它,而不是凌乱的正则表达式(注意:我没有使用过YamlDotNet,我的YAML体验是在python中)
(我用http://yaml-online-parser.appspot.com/对文件进行了测试,以仔细检查其格式,完全解析)