Files
AIGame/Tools/build_animation_lab_ui.py

58 lines
4.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Author the animation comparison controls through the project's JSON UI pipeline."""
import json
from pathlib import Path
root=Path(__file__).resolve().parents[1]
nodes=[]
sprites={name:'Assets/Bundles/UI/Texture/Common/'+name+'.png' for name in [
'ui_panel_popup','btn_secondary_normal','btn_secondary_pressed','btn_primary_normal','btn_primary_pressed','btn_primary_disabled','progress_bg','progress_fill']}
def node(name,parent,rect,components):
nodes.append(dict(name=name,parent=parent,active=True,rect=rect,components=components))
def rect(x,y,w,h,anchor=(.5,1),pivot=(.5,1)):
return dict(anchorMin=anchor,anchorMax=anchor,pivot=pivot,anchoredPosition=[x,y],sizeDelta=[w,h])
def text(name,parent,value,x,y,w,h,size=28,color='#33405EFF'):
node(name,parent,rect(x,y,w,h),[dict(type='TextMeshProUGUI',text=value,fontSize=size,alignment='Center',color=color,raycastTarget=False)])
node('UI_CharacterAnimationLab',None,dict(anchorMin=[0,0],anchorMax=[1,1],offsetMin=[0,0],offsetMax=[0,0]),[
dict(type='Canvas',sortingOrder=100),dict(type='CanvasScaler',referenceResolution=[1080,1920],matchWidthOrHeight=.5),dict(type='GraphicRaycaster')])
node('Panel_Header','UI_CharacterAnimationLab',rect(0,-24,1032,188),[dict(type='Image',sprite='ui_panel_popup',imageType='Sliced',raycastTarget=False,color='#FFFFFFFF')])
text('Txt_Title','Panel_Header','角色动画对比',0,-12,960,58,42)
text('Txt_Subtitle','Panel_Header','相同骨架与动作 · 三版同步播放',0,-70,960,40,25)
for i,(label,color) in enumerate([('① Mixamo 网站','#1B8299FF'),('② TokenRig 原始','#B46A2AFF'),('③ 手部约束后','#458533FF')]):
text('Txt_Column'+str(i),'Panel_Header',label,(i-1)*336,-122,330,44,27,color)
node('Panel_Controls','UI_CharacterAnimationLab',rect(0,24,1032,600,(.5,0),(.5,0)),[dict(type='Image',sprite='ui_panel_popup',imageType='Sliced',raycastTarget=True,color='#FFFFFFFF')])
text('Txt_State','Panel_Controls','行走 · 三版同步对比',0,-12,978,46,30)
node('Btn_Seek','Panel_Controls',rect(0,-66,978,32),[dict(type='Image',sprite='progress_bg',imageType='Sliced',raycastTarget=True),
dict(type='MonoBehaviour',typeName='AIGame.Review.AnimationLabSeekBar')])
node('Img_Progress','Btn_Seek',dict(anchorMin=[0,0],anchorMax=[0,1],pivot=[0,.5],anchoredPosition=[0,0],sizeDelta=[2,0]),[
dict(type='Image',sprite='progress_fill',imageType='Sliced',raycastTarget=False)])
text('Txt_Time','Panel_Controls','0.00 / 1.03 秒',0,-104,978,34,23)
rows=[
[('Walk','行走'),('Breathe','呼吸待机'),('Happy','轻松待机')],
[('Play','暂停'),('Previous','上一帧'),('Next','下一帧'),('Restart','重播')],
[('Speed025','0.25×'),('Speed05','0.5×'),('Speed1','1×'),('Speed2','2×'),('Travel','原地循环')],
[('Front','正面'),('Side','侧面'),('Back','背面'),('Material','切灰模')],
[('All','三版并排'),('Focus1','看 ①'),('Focus2','看 ②'),('Focus3','看 ③'),('Detail','全身')]]
events=[]
for row,items in enumerate(rows):
width=(978-(len(items)-1)*12)/len(items)
for col,(key,label) in enumerate(items):
name='Btn_'+key
x=-489+width/2+col*(width+12)
primary=key in ('Play','All')
prefix='btn_primary' if primary else 'btn_secondary'
node(name,'Panel_Controls',rect(x,-148-row*76,width,62),[
dict(type='Image',sprite=prefix+'_normal',imageType='Sliced',raycastTarget=True),
dict(type='Button',transition='SpriteSwap',spritePressed=prefix+'_pressed',onClick='AnimationLab.'+key)])
node('Txt_'+key,name,dict(anchorMin=[0,0],anchorMax=[1,1],offsetMin=[3,1],offsetMax=[-3,-1]),[
dict(type='TextMeshProUGUI',text=label,fontSize=27,alignment='Center',fontStyle='Bold',color='#F6F8FFFF',raycastTarget=False),
dict(type='Outline',effectColor='#102033AA',effectDistance=[1,-1])])
events.append(dict(name='AnimationLab.'+key,node=name))
text('Txt_Help','Panel_Controls','拖动角色旋转 · 滚轮缩放 · 空格播放/暂停',0,-542,978,36,23)
document=dict(schemaVersion=1,prefabName='UI_CharacterAnimationLab',prefabPath='Assets/Bundles/UI/Prefab/UI_CharacterAnimationLab.prefab',
description='独立角色动画观看场景的同步播放、逐帧、进度、视角与放大控制。1080×1920;所有控件由 JSON→Prefab 创建。',
canvas=dict(canvasScaler=dict(referenceResolution=[1080,1920],matchWidthOrHeight=.5)),assets=dict(sprites=sprites),nodes=nodes,
bindings=['Txt_State','Txt_Time','Btn_Seek','Img_Progress']+[e['node'] for e in events],events=events)
path=root/'Doc/UIPrefabCreater/UI_CharacterAnimationLab.json'
path.write_text(json.dumps(document,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
print(path)