RolePreviewWindow.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEditor;
  6. using UnityEditor.Callbacks;
  7. using UnityEditor.Compilation;
  8. using UnityEditor.Experimental.UIElements.GraphView;
  9. using LuaInterface;
  10. using UnityEditor.Experimental.GraphView;
  11. namespace RO.Editor
  12. {
  13. public class RolePreviewWindow : EditorWindow, ISearchWindowProvider
  14. {
  15. [MenuItem("RO_Tool/主角预览")]
  16. private static RolePreviewWindow OpenWindow()
  17. {
  18. var window = EditorWindow.GetWindow<RolePreviewWindow>("主角预览");
  19. window.minSize = new Vector2(260, 280);
  20. return window;
  21. }
  22. [DidReloadScripts]
  23. private static void OnScriptReload()
  24. {
  25. var windows = Resources.FindObjectsOfTypeAll(typeof(RolePreviewWindow));
  26. foreach (var window in windows)
  27. {
  28. try
  29. {
  30. ((RolePreviewWindow)window).OnDisable();
  31. ((RolePreviewWindow)window).OnEnable();
  32. }
  33. catch
  34. {
  35. DestroyImmediate(window);
  36. }
  37. }
  38. }
  39. public enum SearchTreeType
  40. {
  41. None,
  42. RoleCfg,
  43. FashionCfg,
  44. }
  45. public enum SexType
  46. {
  47. Man = 2,
  48. Woman = 1,
  49. }
  50. public enum HandWeaponType
  51. {
  52. Right = 1,
  53. Left = 2,
  54. Double = 3,
  55. }
  56. public enum FashionSlotType
  57. {
  58. HeadTop = 1, // 头上
  59. HeadMiddle = 2, // 头中
  60. HeadBottom = 3, // 头下
  61. Cloth = 4, // 衣服
  62. Weapon = 5, // 武器
  63. BodyBack = 6, // 背部
  64. HairStyle = 7, // 发型
  65. Pupil = 8, // 瞳孔
  66. }
  67. public enum SkinSlotType
  68. {
  69. HeadTop = 1, // 头上
  70. HeadMiddle = 2, // 头中
  71. HeadBottom = 3, // 头下
  72. Cloth = 4, // 衣服
  73. LeftHand = 5, // 左手
  74. RightHand = 6, // 右手
  75. BodyBack = 7, // 背部
  76. HairStyle = 8, // 发型
  77. Pupil = 9, // 瞳孔
  78. HairColor = 101, // 头发颜色
  79. Face = 1000, // 脸型
  80. }
  81. public enum RoleInEnvType
  82. {
  83. Battle = 1,
  84. GuildLobby = 2,
  85. CreateRole = 3,
  86. RoleMainView = 4,
  87. Transfer = 5,
  88. }
  89. public struct RoleCfgData
  90. {
  91. public int id;
  92. public string name;
  93. public int avatarId;
  94. public SexType sex;
  95. public int leftWeaponId;
  96. public int rightWeaponId;
  97. public int clothId;
  98. public int hairId;
  99. public int eyeId;
  100. public int headTopId;
  101. public int headMiddleId;
  102. public int headBottomId;
  103. public int bodyBackId;
  104. public string battleCtrl;
  105. public string cityCtrl;
  106. public string createShowCtrl;
  107. public string roleShowCtrl;
  108. public string transferShowCtrl;
  109. }
  110. public struct FashionCfgData
  111. {
  112. public int id;
  113. public string name;
  114. public int avatarId;
  115. public int extAvatarId;
  116. public bool hideHair;
  117. public FashionSlotType fashionSlotType;
  118. }
  119. public struct RoleAvatarCfgData
  120. {
  121. public int id;
  122. public string avatarPrefab;
  123. public Vector3? position;
  124. public Quaternion? quaternion;
  125. public Vector3? scale;
  126. }
  127. public struct AvatarCfgData
  128. {
  129. public int id;
  130. public string avatarPrefab;
  131. }
  132. public class PopupData
  133. {
  134. private List<string> m_NameLs = new List<string>();
  135. private List<int> m_IdLs = new List<int>();
  136. public string[] names;
  137. public int[] ids;
  138. public void Add(string name, int id)
  139. {
  140. m_NameLs.Add(name);
  141. m_IdLs.Add(id);
  142. }
  143. public void Normalize()
  144. {
  145. names = m_NameLs.ToArray();
  146. ids = m_IdLs.ToArray();
  147. m_NameLs.Clear();
  148. m_IdLs.Clear();
  149. }
  150. }
  151. private const string c_GlobalCfgPath = "Assets/Content/Config/GlobalCfg.csv";
  152. private const string c_RoleCfgPath = "Assets/Lua/Config/RoleCfg.lua";
  153. private const string c_FashionCfgPath = "Assets/Lua/Config/FashionCfg.lua";
  154. private const string c_RoleAvatarCfgPath = "Assets/Lua/Config/RoleAvatarCfg.lua";
  155. private const string c_AvatarCfgPath = "Assets/Lua/Config/AvatarCfg.lua";
  156. private const string c_LanguagePackagePath = "Assets/Content/Config/LanguagePackage_cn.csv";
  157. private bool m_Inited = false;
  158. private string m_DefaultMaleBaseAvatarPrefab = "";
  159. private string m_DefaultFemaleBaseAvatarPrefab = "";
  160. private int m_DefaultMaleFaceAvatarId = -1;
  161. private int m_DefaultFemaleFaceAvatarId = -1;
  162. private Dictionary<int, RoleCfgData> m_RoleCfgMap = new Dictionary<int, RoleCfgData>();
  163. private Dictionary<int, FashionCfgData> m_FashionCfgMap = new Dictionary<int, FashionCfgData>();
  164. private Dictionary<int, RoleAvatarCfgData> m_RoleAvatarCfgMap = new Dictionary<int, RoleAvatarCfgData>();
  165. private Dictionary<int, AvatarCfgData> m_AvatarCfgMap = new Dictionary<int, AvatarCfgData>();
  166. private Dictionary<string, string> m_LanguageMap = new Dictionary<string, string>();
  167. private List<SearchTreeEntry> m_RoleCfgSearchTree = new List<SearchTreeEntry>();
  168. private Dictionary<FashionSlotType, List<SearchTreeEntry>> m_FashionCfgSearchTree = new Dictionary<FashionSlotType, List<SearchTreeEntry>>();
  169. private SearchTreeType m_SearchTreeType = SearchTreeType.None;
  170. private FashionSlotType m_SearchTreeFashionSlotType = FashionSlotType.HeadTop;
  171. private int m_CurrentRoleCfgId = -1;
  172. private RoleInEnvType m_CurrentRoleInEnvType = RoleInEnvType.Battle;
  173. private Dictionary<FashionSlotType, int> m_EquipFashionMap = new Dictionary<FashionSlotType, int>();
  174. private Dictionary<FashionSlotType, string> m_FashionSlotTypeNameMap = new Dictionary<FashionSlotType, string>()
  175. {
  176. [FashionSlotType.HeadTop] = "头上",
  177. [FashionSlotType.HeadMiddle] = "头中",
  178. [FashionSlotType.HeadBottom] = "头下",
  179. [FashionSlotType.Cloth] = "衣服",
  180. [FashionSlotType.Weapon] = "武器",
  181. [FashionSlotType.BodyBack] = "背部",
  182. [FashionSlotType.HairStyle] = "发型",
  183. [FashionSlotType.Pupil] = "瞳孔",
  184. };
  185. private Dictionary<FashionSlotType, SkinSlotType> m_FashionSlotToSkinSlotMap = new Dictionary<FashionSlotType, SkinSlotType>()
  186. {
  187. [FashionSlotType.HeadTop] = SkinSlotType.HeadTop,
  188. [FashionSlotType.HeadMiddle] = SkinSlotType.HeadMiddle,
  189. [FashionSlotType.HeadBottom] = SkinSlotType.HeadBottom,
  190. [FashionSlotType.Cloth] = SkinSlotType.Cloth,
  191. [FashionSlotType.BodyBack] = SkinSlotType.BodyBack,
  192. [FashionSlotType.HairStyle] = SkinSlotType.HairStyle,
  193. [FashionSlotType.Pupil] = SkinSlotType.Pupil,
  194. };
  195. private Dictionary<SkinSlotType, string> m_SkinSlotBindBone = new Dictionary<SkinSlotType, string>()
  196. {
  197. [SkinSlotType.HeadTop] = "Head_Point",
  198. [SkinSlotType.HeadMiddle] = "Head_Point",
  199. [SkinSlotType.HeadBottom] = "Head_Point",
  200. [SkinSlotType.Cloth] = "Bip001 Spine1",
  201. [SkinSlotType.LeftHand] = "LHand_Point",
  202. [SkinSlotType.RightHand] = "RHand_Point",
  203. [SkinSlotType.BodyBack] = "Back_Point",
  204. [SkinSlotType.HairStyle] = "Bip001 Head",
  205. [SkinSlotType.Pupil] = "Bip001 Head",
  206. };
  207. private GameObject m_CurrentGo;
  208. private Dictionary<string, Transform> m_CurrentGoBoneMap = new Dictionary<string, Transform>();
  209. private Dictionary<SkinSlotType, List<Renderer>> m_BaseSkinSlotTypeMap = new Dictionary<SkinSlotType, List<Renderer>>();
  210. private Dictionary<SkinSlotType, List<Renderer>> m_ExtSkinSlotTypeMap = new Dictionary<SkinSlotType, List<Renderer>>();
  211. private void OnEnable()
  212. {
  213. InitConfig();
  214. CompilationPipeline.assemblyCompilationStarted += OnAssemblyCompilationStarted;
  215. CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished;
  216. }
  217. private void OnDisable()
  218. {
  219. CompilationPipeline.assemblyCompilationStarted -= OnAssemblyCompilationStarted;
  220. CompilationPipeline.assemblyCompilationFinished -= OnAssemblyCompilationFinished;
  221. DisposeModel();
  222. m_CurrentRoleCfgId = -1;
  223. m_CurrentRoleInEnvType = RoleInEnvType.Battle;
  224. m_Inited = false;
  225. }
  226. private void OnFocus()
  227. {
  228. if (m_CurrentGo)
  229. {
  230. Selection.activeObject = m_CurrentGo;
  231. }
  232. }
  233. private void OnAssemblyCompilationStarted(string path)
  234. {
  235. if (path.EndsWith("Assembly-CSharp-Editor.dll"))
  236. DisposeModel();
  237. }
  238. private void OnAssemblyCompilationFinished(string path, CompilerMessage[] messages)
  239. {
  240. if (path.EndsWith("Assembly-CSharp-Editor.dll"))
  241. CreateModel();
  242. }
  243. private void OnGUI()
  244. {
  245. if (!m_Inited)
  246. {
  247. GUILayout.FlexibleSpace();
  248. EditorGUILayout.HelpBox("配置初始化失败,请检查相关配置", MessageType.Error);
  249. GUILayout.FlexibleSpace();
  250. return;
  251. }
  252. EditorGUILayout.Space();
  253. EditorGUILayout.BeginHorizontal();
  254. EditorGUILayout.LabelField("当前角色的使用环境", GUILayout.MaxWidth(100));
  255. var newRoleInEnvType = (RoleInEnvType)EditorGUILayout.EnumPopup(m_CurrentRoleInEnvType);
  256. if (newRoleInEnvType != m_CurrentRoleInEnvType)
  257. {
  258. m_CurrentRoleInEnvType = newRoleInEnvType;
  259. RefreshAnimator();
  260. }
  261. EditorGUILayout.EndHorizontal();
  262. EditorGUILayout.Space();
  263. EditorGUILayout.BeginHorizontal();
  264. EditorGUILayout.LabelField("选择角色基础模型", GUILayout.MaxWidth(100));
  265. string roleCfgName = "无";
  266. if (m_RoleCfgMap.ContainsKey(m_CurrentRoleCfgId))
  267. {
  268. roleCfgName = m_RoleCfgMap[m_CurrentRoleCfgId].name;
  269. }
  270. GUIContent content = EditorGUIUtility.TrTempContent(roleCfgName);
  271. GUIStyle style = "MiniPullDown";
  272. Rect rect = GUILayoutUtility.GetRect(content, style);
  273. if (EditorGUI.DropdownButton(rect, content, FocusType.Passive, style))
  274. {
  275. OpenSearchWindw(EditorGUIUtility.GUIToScreenPoint(new Vector2(rect.xMin, rect.yMax)), SearchTreeType.RoleCfg);
  276. }
  277. EditorGUILayout.EndHorizontal();
  278. EditorGUI.BeginDisabledGroup(!m_RoleCfgMap.ContainsKey(m_CurrentRoleCfgId));
  279. EditorGUILayout.Separator();
  280. for (FashionSlotType fashionSlotType = FashionSlotType.HeadTop; fashionSlotType <= FashionSlotType.Pupil; fashionSlotType++)
  281. {
  282. EditorGUILayout.BeginHorizontal();
  283. EditorGUILayout.LabelField("选择 " + m_FashionSlotTypeNameMap[fashionSlotType] + " 时装", GUILayout.MaxWidth(100));
  284. string fashionCfgName = "无";
  285. if (m_EquipFashionMap.ContainsKey(fashionSlotType))
  286. {
  287. int id = m_EquipFashionMap[fashionSlotType];
  288. if (m_FashionCfgMap.ContainsKey(id))
  289. {
  290. fashionCfgName = m_FashionCfgMap[id].name;
  291. }
  292. }
  293. content = EditorGUIUtility.TrTempContent(fashionCfgName);
  294. rect = GUILayoutUtility.GetRect(content, style);
  295. if (EditorGUI.DropdownButton(rect, content, FocusType.Passive, style))
  296. {
  297. OpenSearchWindw(EditorGUIUtility.GUIToScreenPoint(new Vector2(rect.xMin, rect.yMax)), SearchTreeType.FashionCfg, fashionSlotType);
  298. }
  299. EditorGUILayout.EndHorizontal();
  300. EditorGUILayout.Space();
  301. }
  302. EditorGUILayout.Separator();
  303. EditorGUI.EndDisabledGroup();
  304. }
  305. #region Init Config
  306. private void InitConfig()
  307. {
  308. ShowNotification(EditorGUIUtility.TrTempContent("读取配置中"));
  309. m_Inited = false;
  310. m_DefaultMaleFaceAvatarId = -1;
  311. m_DefaultFemaleFaceAvatarId = -1;
  312. m_RoleCfgMap.Clear();
  313. m_FashionCfgMap.Clear();
  314. m_RoleAvatarCfgMap.Clear();
  315. m_AvatarCfgMap.Clear();
  316. m_LanguageMap.Clear();
  317. try
  318. {
  319. TextAsset textAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(c_LanguagePackagePath);
  320. string text = textAsset.text;
  321. string[] lines = text.Split('\n');
  322. for (int i = 3, iMax = lines.Length; i < iMax; i++)
  323. {
  324. string line = lines[i];
  325. if (string.IsNullOrEmpty(line)) continue;
  326. string[] values = line.Split(',');
  327. if (values.Length < 2) continue;
  328. if (string.IsNullOrEmpty(values[0])) continue;
  329. if (m_LanguageMap.ContainsKey(values[0]))
  330. {
  331. Debug.LogError(c_LanguagePackagePath + "存在相同的Id :" + values[0]);
  332. continue;
  333. }
  334. m_LanguageMap.Add(values[0], values[1]);
  335. }
  336. textAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(c_GlobalCfgPath);
  337. text = textAsset.text;
  338. lines = text.Split('\n');
  339. for (int i = 3, iMax = lines.Length; i < iMax; i++)
  340. {
  341. string line = lines[i];
  342. if (string.IsNullOrEmpty(line)) continue;
  343. string[] values = line.Split(',');
  344. if (values.Length < 5) continue;
  345. if (string.IsNullOrEmpty(values[0])) continue;
  346. switch (values[0])
  347. {
  348. case "42":
  349. int.TryParse(values[2], out m_DefaultMaleFaceAvatarId);
  350. break;
  351. case "43":
  352. int.TryParse(values[2], out m_DefaultFemaleFaceAvatarId);
  353. break;
  354. case "44":
  355. m_DefaultMaleBaseAvatarPrefab = values[3];
  356. break;
  357. case "45":
  358. m_DefaultFemaleBaseAvatarPrefab = values[3];
  359. break;
  360. }
  361. }
  362. using (LuaState luaState = new LuaState())
  363. {
  364. try
  365. {
  366. luaState.Start();
  367. // LuaForEach<int, LuaTable>(luaState, c_GlobalCfgPath, InitFaceConfig);
  368. LuaForEach<int, LuaTable>(luaState, c_RoleCfgPath, InitRoleConfig);
  369. LuaForEach<int, LuaTable>(luaState, c_FashionCfgPath, InitFashionConfig);
  370. LuaForEach<int, LuaTable>(luaState, c_RoleAvatarCfgPath, InitRoleAvatarConfig);
  371. LuaForEach<int, LuaTable>(luaState, c_AvatarCfgPath, InitAvatarConfig);
  372. m_Inited = true;
  373. }
  374. catch (Exception e)
  375. {
  376. Debug.LogException(e);
  377. }
  378. }
  379. }
  380. catch (Exception e)
  381. {
  382. Debug.LogException(e);
  383. }
  384. m_RoleCfgSearchTree.Clear();
  385. List<int> m_ManIds = new List<int>();
  386. List<int> m_WomanIds = new List<int>();
  387. foreach (var item in m_RoleCfgMap)
  388. {
  389. if (item.Value.sex == SexType.Man)
  390. {
  391. m_ManIds.Add(item.Key);
  392. }
  393. else
  394. {
  395. m_WomanIds.Add(item.Key);
  396. }
  397. }
  398. m_ManIds.Sort();
  399. m_WomanIds.Sort();
  400. int level = 0;
  401. SearchTreeGroupEntry rootEntry = new SearchTreeGroupEntry(new GUIContent("性别"), level);
  402. m_RoleCfgSearchTree.Add(rootEntry);
  403. level++;
  404. SearchTreeGroupEntry manEntry = new SearchTreeGroupEntry(new GUIContent("男"), level);
  405. manEntry.userData = SexType.Man;
  406. m_RoleCfgSearchTree.Add(manEntry);
  407. level++;
  408. for (int i = 0, iMax = m_ManIds.Count; i < iMax; i++)
  409. {
  410. int id = m_ManIds[i];
  411. SearchTreeEntry itemEntry = new SearchTreeEntry(new GUIContent(m_RoleCfgMap[id].name));
  412. itemEntry.level = level;
  413. itemEntry.userData = m_RoleCfgMap[id];
  414. m_RoleCfgSearchTree.Add(itemEntry);
  415. }
  416. level--;
  417. SearchTreeGroupEntry womanEntry = new SearchTreeGroupEntry(new GUIContent("女"), level);
  418. level++;
  419. m_RoleCfgSearchTree.Add(womanEntry);
  420. for (int i = 0, iMax = m_WomanIds.Count; i < iMax; i++)
  421. {
  422. int id = m_WomanIds[i];
  423. SearchTreeEntry itemEntry = new SearchTreeEntry(new GUIContent(m_RoleCfgMap[id].name));
  424. itemEntry.userData = m_RoleCfgMap[id];
  425. itemEntry.level = level;
  426. m_RoleCfgSearchTree.Add(itemEntry);
  427. }
  428. level--;
  429. level--;
  430. Dictionary<FashionSlotType, List<int>> dic = new Dictionary<FashionSlotType, List<int>>();
  431. foreach (var item in m_FashionCfgMap)
  432. {
  433. List<int> ls;
  434. if (!dic.TryGetValue(item.Value.fashionSlotType, out ls))
  435. {
  436. ls = new List<int>();
  437. dic.Add(item.Value.fashionSlotType, ls);
  438. }
  439. ls.Add(item.Key);
  440. }
  441. level = 0;
  442. m_FashionCfgSearchTree.Clear();
  443. for (FashionSlotType fashionSlotType = FashionSlotType.HeadTop; fashionSlotType <= FashionSlotType.Pupil; fashionSlotType++)
  444. {
  445. List<SearchTreeEntry> ls = new List<SearchTreeEntry>();
  446. SearchTreeGroupEntry groupEntry = new SearchTreeGroupEntry(new GUIContent(m_FashionSlotTypeNameMap[fashionSlotType]), level);
  447. groupEntry.userData = fashionSlotType;
  448. ls.Add(groupEntry);
  449. level++;
  450. SearchTreeEntry nullEntry = new SearchTreeEntry(new GUIContent("空"));
  451. nullEntry.level = level;
  452. nullEntry.userData = fashionSlotType;
  453. ls.Add(nullEntry);
  454. if (dic.ContainsKey(fashionSlotType))
  455. {
  456. List<int> ids = dic[fashionSlotType];
  457. ids.Sort();
  458. for (int i = 0, iMax = ids.Count; i < iMax; i++)
  459. {
  460. int id = ids[i];
  461. SearchTreeEntry itemEntry = new SearchTreeEntry(new GUIContent(m_FashionCfgMap[id].name));
  462. itemEntry.userData = m_FashionCfgMap[id];
  463. itemEntry.level = level;
  464. ls.Add(itemEntry);
  465. }
  466. }
  467. m_FashionCfgSearchTree.Add(fashionSlotType, ls);
  468. level--;
  469. }
  470. RemoveNotification();
  471. }
  472. private void InitFaceConfig(int key, LuaTable value)
  473. {
  474. if (key == 42)
  475. {
  476. m_DefaultMaleFaceAvatarId = value.RawGet<string, int>("IVal");
  477. }
  478. else if (key == 43)
  479. {
  480. m_DefaultFemaleFaceAvatarId = value.RawGet<string, int>("IVal");
  481. }
  482. else if (key == 44)
  483. {
  484. m_DefaultMaleBaseAvatarPrefab = value.RawGet<string, string>("SVal");
  485. }
  486. else if (key == 45)
  487. {
  488. m_DefaultFemaleBaseAvatarPrefab = value.RawGet<string, string>("SVal");
  489. }
  490. }
  491. private void InitRoleConfig(int key, LuaTable value)
  492. {
  493. if (m_RoleCfgMap.ContainsKey(key))
  494. {
  495. Debug.LogError(c_RoleCfgPath + "存在相同的Id :" + key);
  496. return;
  497. }
  498. RoleCfgData roleCfgData = new RoleCfgData()
  499. {
  500. id = key,
  501. name = value.RawGet<string, string>("Name"),
  502. avatarId = value.RawGet<string, int>("AvatarId"),
  503. sex = (SexType)value.RawGet<string, int>("Sex"),
  504. leftWeaponId = value.RawGet<string, int>("LeftWeapon"),
  505. rightWeaponId = value.RawGet<string, int>("RightWeapon"),
  506. clothId = value.RawGet<string, int>("ClothId"),
  507. hairId = value.RawGet<string, int>("Hair"),
  508. eyeId = value.RawGet<string, int>("Eye"),
  509. headTopId = value.RawGet<string, int>("HeadTop"),
  510. headMiddleId = value.RawGet<string, int>("HeadMiddle"),
  511. headBottomId = value.RawGet<string, int>("HeadBottom"),
  512. bodyBackId = value.RawGet<string, int>("BodyBackId"),
  513. battleCtrl = value.RawGet<string, string>("BattleCtrl"),
  514. cityCtrl = value.RawGet<string, string>("CityCtrl"),
  515. createShowCtrl = value.RawGet<string, string>("CreateShowCtrl"),
  516. roleShowCtrl = value.RawGet<string, string>("RoleShowCtrl"),
  517. transferShowCtrl = value.RawGet<string, string>("TransferShowCtrl"),
  518. };
  519. if (m_LanguageMap.ContainsKey(roleCfgData.name))
  520. {
  521. roleCfgData.name = roleCfgData.id + " (" + m_LanguageMap[roleCfgData.name] + ")";
  522. }
  523. else
  524. {
  525. roleCfgData.name = roleCfgData.id + " (" + roleCfgData.name + ")";
  526. }
  527. m_RoleCfgMap.Add(key, roleCfgData);
  528. }
  529. private void InitFashionConfig(int key, LuaTable value)
  530. {
  531. if (m_FashionCfgMap.ContainsKey(key))
  532. {
  533. Debug.LogError(c_FashionCfgPath + "存在相同的Id :" + key);
  534. return;
  535. }
  536. FashionCfgData fashionCfgData = new FashionCfgData()
  537. {
  538. id = key,
  539. name = value.RawGet<string, string>("FashionName"),
  540. avatarId = value.RawGet<string, int>("RoleAvatarID"),
  541. extAvatarId = value.RawGet<string, int>("ExtRoleAvatarID"),
  542. hideHair = value.RawGet<string, bool>("FashionHideHair"),
  543. fashionSlotType = (FashionSlotType)value.RawGet<string, int>("FashionLocation"),
  544. };
  545. if (m_LanguageMap.ContainsKey(fashionCfgData.name))
  546. {
  547. fashionCfgData.name = fashionCfgData.id + " (" + m_LanguageMap[fashionCfgData.name] + ")";
  548. }
  549. else
  550. {
  551. fashionCfgData.name = fashionCfgData.id + " (" + fashionCfgData.name + ")";
  552. }
  553. m_FashionCfgMap.Add(key, fashionCfgData);
  554. }
  555. private void InitRoleAvatarConfig(int key, LuaTable value)
  556. {
  557. if (m_RoleAvatarCfgMap.ContainsKey(key))
  558. {
  559. Debug.LogError(c_RoleAvatarCfgPath + "存在相同的Id :" + key);
  560. return;
  561. }
  562. RoleAvatarCfgData roleAvatarCfgData = new RoleAvatarCfgData()
  563. {
  564. id = key,
  565. avatarPrefab = value.RawGet<string, string>("AvatarPrefab"),
  566. };
  567. LuaTable childValue = value.RawGet<string, LuaTable>("ModelPosition");
  568. if (childValue != null)
  569. roleAvatarCfgData.position = LuaTableToVector3(childValue);
  570. childValue = value.RawGet<string, LuaTable>("ModelRotation");
  571. if (childValue != null)
  572. roleAvatarCfgData.quaternion = Quaternion.Euler(LuaTableToVector3(childValue));
  573. childValue = value.RawGet<string, LuaTable>("ModelScale");
  574. if (childValue != null)
  575. roleAvatarCfgData.scale = LuaTableToVector3(childValue);
  576. m_RoleAvatarCfgMap.Add(key, roleAvatarCfgData);
  577. }
  578. private void InitAvatarConfig(int key, LuaTable value)
  579. {
  580. if (m_AvatarCfgMap.ContainsKey(key))
  581. {
  582. Debug.LogError(c_AvatarCfgPath + "存在相同的Id :" + key);
  583. return;
  584. }
  585. AvatarCfgData avatarCfgData = new AvatarCfgData()
  586. {
  587. id = key,
  588. avatarPrefab = value.RawGet<string, string>("AvatarPrefab"),
  589. };
  590. m_AvatarCfgMap.Add(key, avatarCfgData);
  591. }
  592. private void InitLanguagePackage(string key, LuaTable value)
  593. {
  594. if (m_LanguageMap.ContainsKey(key))
  595. {
  596. Debug.LogError(c_LanguagePackagePath + "存在相同的Id :" + key);
  597. return;
  598. }
  599. string language = value.RawGet<string, string>("Language");
  600. m_LanguageMap.Add(key, language);
  601. }
  602. public static void LuaForEach<K, V>(LuaState luaState, string luaFile, Action<K, V> foreachFun,Action<LuaTable> EndCB = null)
  603. {
  604. using (LuaTable luaTable = luaState.DoFile<LuaTable>(luaFile))
  605. {
  606. try
  607. {
  608. using (LuaDictTable<K, V> luaDictTable = luaTable.ToDictTable<K, V>())
  609. {
  610. try
  611. {
  612. foreach (var item in luaDictTable)
  613. {
  614. foreachFun(item.Key, item.Value);
  615. }
  616. }
  617. catch (Exception e)
  618. {
  619. Debug.LogException(e);
  620. }
  621. }
  622. }
  623. catch (Exception e)
  624. {
  625. Debug.LogException(e);
  626. }
  627. EndCB?.Invoke(luaTable);
  628. }
  629. }
  630. public static void SaveToLua(LuaState runTime,string path,LuaTable luaTable,string tableName,string log)
  631. {
  632. string luaCode = @"
  633. local SaveHelper = {}
  634. function SaveHelper:SaveToLua(path,luatable,tableName,isLog)
  635. if isLog == '1' then
  636. LogError(path)
  637. end
  638. --
  639. --local file = io.open(path, 'w')
  640. --if file then
  641. -- table.save(luatable, file)
  642. -- file:close()
  643. -- LogError('保存到路径:'..path)
  644. --else
  645. -- LogError('保存失败')
  646. --end
  647. --saveErr = table.save(luatable,path)
  648. saveErr = table.SaveTable(luatable,path,tableName)
  649. if isLog == '1' then
  650. if saveErr ~= nil then
  651. LogError('保存失败'..saveErr)
  652. else
  653. LogError('保存到路径:'..path)
  654. end
  655. end
  656. end
  657. return SaveHelper
  658. ";
  659. LuaTable saveHelper = runTime.DoString<LuaTable>(luaCode);
  660. saveHelper.Call("SaveToLua", saveHelper, path, luaTable, tableName, log);
  661. }
  662. private Vector3 LuaTableToVector3(LuaTable luaArrayTable)
  663. {
  664. Vector3 value = Vector3.zero;
  665. value.x = ((luaArrayTable[1] != null) ? (luaArrayTable.RawGetIndex<float>(1)) : 0);
  666. value.y = ((luaArrayTable[2] != null) ? (luaArrayTable.RawGetIndex<float>(2)) : 0);
  667. value.z = ((luaArrayTable[3] != null) ? (luaArrayTable.RawGetIndex<float>(3)) : 0);
  668. return value;
  669. }
  670. #endregion
  671. #region Search Windw
  672. private void OpenSearchWindw(Vector2 alginPos, SearchTreeType searchTreeType, FashionSlotType fashionSlotType = FashionSlotType.HeadTop)
  673. {
  674. m_SearchTreeType = searchTreeType;
  675. m_SearchTreeFashionSlotType = fashionSlotType;
  676. if (m_SearchTreeType == SearchTreeType.None) return;
  677. SearchWindowContext context = new SearchWindowContext(alginPos + new Vector2(120, 16));
  678. SearchWindow.Open(context, this);
  679. }
  680. #region ISearchWindowProvider
  681. public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context)
  682. {
  683. if (m_SearchTreeType == SearchTreeType.RoleCfg)
  684. {
  685. return m_RoleCfgSearchTree;
  686. }
  687. if (m_SearchTreeType == SearchTreeType.FashionCfg)
  688. {
  689. return m_FashionCfgSearchTree[m_SearchTreeFashionSlotType];
  690. }
  691. return null;
  692. }
  693. public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context)
  694. {
  695. if (m_SearchTreeType == SearchTreeType.RoleCfg)
  696. {
  697. if (SearchTreeEntry.userData == null)
  698. {
  699. if (m_CurrentRoleCfgId != -1)
  700. {
  701. m_CurrentRoleCfgId = -1;
  702. m_EquipFashionMap.Clear();
  703. CreateModel();
  704. }
  705. }
  706. else
  707. {
  708. RoleCfgData roleCfgData = (RoleCfgData)SearchTreeEntry.userData;
  709. int id = roleCfgData.id;
  710. if (m_CurrentRoleCfgId != id)
  711. {
  712. m_CurrentRoleCfgId = id;
  713. m_EquipFashionMap.Clear();
  714. CreateModel();
  715. }
  716. }
  717. }
  718. else if (m_SearchTreeType == SearchTreeType.FashionCfg)
  719. {
  720. if (SearchTreeEntry.userData is FashionSlotType)
  721. {
  722. m_EquipFashionMap.Remove((FashionSlotType)SearchTreeEntry.userData);
  723. RefreshModel();
  724. }
  725. else
  726. {
  727. FashionCfgData fashionCfgData = (FashionCfgData)SearchTreeEntry.userData;
  728. if (m_EquipFashionMap.ContainsKey(fashionCfgData.fashionSlotType))
  729. {
  730. if (m_EquipFashionMap[fashionCfgData.fashionSlotType] != fashionCfgData.id)
  731. {
  732. m_EquipFashionMap[fashionCfgData.fashionSlotType] = fashionCfgData.id;
  733. RefreshModel();
  734. }
  735. }
  736. else
  737. {
  738. m_EquipFashionMap.Add(fashionCfgData.fashionSlotType, fashionCfgData.id);
  739. RefreshModel();
  740. }
  741. }
  742. }
  743. m_SearchTreeType = SearchTreeType.None;
  744. Repaint();
  745. return true;
  746. }
  747. #endregion
  748. #endregion
  749. #region Model
  750. private void CreateModel()
  751. {
  752. DisposeModel();
  753. if (!m_RoleCfgMap.ContainsKey(m_CurrentRoleCfgId)) return;
  754. RoleCfgData roleCfgData = m_RoleCfgMap[m_CurrentRoleCfgId];
  755. string avatarPrefab = ((roleCfgData.sex == SexType.Man) ? m_DefaultMaleBaseAvatarPrefab : m_DefaultFemaleBaseAvatarPrefab);
  756. if (string.IsNullOrEmpty(avatarPrefab)) return;
  757. GameObject sourceGo = AssetDatabase.LoadAssetAtPath<GameObject>(Constants.ModelPath + "/" + avatarPrefab + ".prefab");
  758. if (!sourceGo) return;
  759. m_CurrentGo = Instantiate(sourceGo);
  760. m_CurrentGo.transform.SetParent(null);
  761. m_CurrentGo.transform.localPosition = Vector3.zero;
  762. m_CurrentGo.transform.localRotation = Quaternion.identity;
  763. m_CurrentGo.transform.localScale = Vector3.one;
  764. BuildBoneMap(m_CurrentGo.transform.Find("Bip001"));
  765. // 脸
  766. int faceAvatarId = -1;
  767. faceAvatarId = ((roleCfgData.sex == SexType.Man) ? m_DefaultMaleFaceAvatarId : m_DefaultFemaleFaceAvatarId);
  768. if (m_RoleAvatarCfgMap.ContainsKey(faceAvatarId))
  769. {
  770. var roleAvatarCfg = m_RoleAvatarCfgMap[faceAvatarId];
  771. GameObject faceGo = AssetDatabase.LoadAssetAtPath<GameObject>(Constants.ModelPath + "/" + roleAvatarCfg.avatarPrefab + ".prefab");
  772. m_BaseSkinSlotTypeMap.Add(SkinSlotType.Face, BindGo(SkinSlotType.Face, faceGo, roleAvatarCfg.position, roleAvatarCfg.quaternion, roleAvatarCfg.scale));
  773. }
  774. RefreshAnimator();
  775. RefreshModel();
  776. RefreshPreviewGo();
  777. }
  778. private void DisposeModel()
  779. {
  780. m_CurrentGoBoneMap.Clear();
  781. m_BaseSkinSlotTypeMap.Clear();
  782. m_ExtSkinSlotTypeMap.Clear();
  783. if (!m_CurrentGo) return;
  784. GameObject.DestroyImmediate(m_CurrentGo);
  785. m_CurrentGo = null;
  786. }
  787. private void RefreshAnimator()
  788. {
  789. if (!m_CurrentGo) return;
  790. Animator animator = m_CurrentGo.GetComponent<Animator>();
  791. if (!animator)
  792. {
  793. animator = m_CurrentGo.AddComponent<Animator>();
  794. }
  795. RoleCfgData roleCfgData = m_RoleCfgMap[m_CurrentRoleCfgId];
  796. string controllerPath = null;
  797. if (m_CurrentRoleInEnvType == RoleInEnvType.Battle)
  798. controllerPath = roleCfgData.battleCtrl;
  799. else if (m_CurrentRoleInEnvType == RoleInEnvType.GuildLobby)
  800. controllerPath = roleCfgData.cityCtrl;
  801. else if (m_CurrentRoleInEnvType == RoleInEnvType.CreateRole)
  802. controllerPath = roleCfgData.createShowCtrl;
  803. else if (m_CurrentRoleInEnvType == RoleInEnvType.RoleMainView)
  804. controllerPath = roleCfgData.roleShowCtrl;
  805. else if (m_CurrentRoleInEnvType == RoleInEnvType.Transfer)
  806. controllerPath = roleCfgData.transferShowCtrl;
  807. if (!string.IsNullOrEmpty(controllerPath))
  808. {
  809. var controller = AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(Constants.AnimatorPath + "/" + controllerPath + ".controller");
  810. if (controller)
  811. {
  812. animator.runtimeAnimatorController = controller;
  813. return;
  814. }
  815. }
  816. animator.runtimeAnimatorController = null;
  817. }
  818. private void RefreshModel()
  819. {
  820. if (!m_CurrentGo) return;
  821. RoleCfgData roleCfgData = m_RoleCfgMap[m_CurrentRoleCfgId];
  822. // 找是否有互斥的数据 (目前是头发)
  823. bool isHideHair = false;
  824. if (m_EquipFashionMap.ContainsKey(FashionSlotType.HeadTop))
  825. {
  826. int fashionId = m_EquipFashionMap[FashionSlotType.HeadTop];
  827. if (m_FashionCfgMap.ContainsKey(fashionId))
  828. {
  829. isHideHair = m_FashionCfgMap[fashionId].hideHair;
  830. }
  831. }
  832. for (FashionSlotType fashionSlotType = FashionSlotType.HeadTop; fashionSlotType <= FashionSlotType.Pupil; fashionSlotType++)
  833. {
  834. int avatarId = 0;
  835. if (fashionSlotType == FashionSlotType.Weapon)
  836. {
  837. RemoveSkinSlotType(m_BaseSkinSlotTypeMap, SkinSlotType.LeftHand);
  838. RemoveSkinSlotType(m_BaseSkinSlotTypeMap, SkinSlotType.RightHand);
  839. if (roleCfgData.leftWeaponId != 0)
  840. {
  841. if (m_EquipFashionMap.ContainsKey(fashionSlotType))
  842. {
  843. int fashionId = m_EquipFashionMap[fashionSlotType];
  844. if (m_FashionCfgMap.ContainsKey(fashionId))
  845. {
  846. avatarId = m_FashionCfgMap[fashionId].avatarId;
  847. }
  848. }
  849. if (avatarId == 0)
  850. {
  851. avatarId = roleCfgData.leftWeaponId;
  852. }
  853. if (m_RoleAvatarCfgMap.ContainsKey(avatarId))
  854. {
  855. var roleAvatarCfg = m_RoleAvatarCfgMap[avatarId];
  856. GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(Constants.ModelPath + "/" + roleAvatarCfg.avatarPrefab + ".prefab");
  857. m_BaseSkinSlotTypeMap.Add(SkinSlotType.LeftHand, BindGo(SkinSlotType.LeftHand, go, roleAvatarCfg.position, roleAvatarCfg.quaternion, roleAvatarCfg.scale));
  858. }
  859. }
  860. avatarId = 0;
  861. if (roleCfgData.rightWeaponId != 0)
  862. {
  863. if (m_EquipFashionMap.ContainsKey(fashionSlotType))
  864. {
  865. int fashionId = m_EquipFashionMap[fashionSlotType];
  866. if (m_FashionCfgMap.ContainsKey(fashionId))
  867. {
  868. avatarId = m_FashionCfgMap[fashionId].extAvatarId;
  869. }
  870. }
  871. if (avatarId == 0)
  872. {
  873. avatarId = roleCfgData.rightWeaponId;
  874. }
  875. if (m_RoleAvatarCfgMap.ContainsKey(avatarId))
  876. {
  877. var roleAvatarCfg = m_RoleAvatarCfgMap[avatarId];
  878. GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(Constants.ModelPath + "/" + roleAvatarCfg.avatarPrefab + ".prefab");
  879. m_BaseSkinSlotTypeMap.Add(SkinSlotType.RightHand, BindGo(SkinSlotType.RightHand, go, roleAvatarCfg.position, roleAvatarCfg.quaternion, roleAvatarCfg.scale));
  880. }
  881. }
  882. }
  883. else
  884. {
  885. if (m_EquipFashionMap.ContainsKey(fashionSlotType))
  886. {
  887. int fashionId = m_EquipFashionMap[fashionSlotType];
  888. if (m_FashionCfgMap.ContainsKey(fashionId))
  889. {
  890. avatarId = m_FashionCfgMap[fashionId].avatarId;
  891. }
  892. }
  893. if (avatarId == 0)
  894. {
  895. avatarId = GetDefaultAvatarId(roleCfgData, fashionSlotType);
  896. }
  897. SkinSlotType skinSlotType = m_FashionSlotToSkinSlotMap[fashionSlotType];
  898. if (skinSlotType == SkinSlotType.HairStyle && isHideHair)
  899. {
  900. avatarId = 0;
  901. }
  902. RemoveSkinSlotType(m_BaseSkinSlotTypeMap, skinSlotType);
  903. if (m_RoleAvatarCfgMap.ContainsKey(avatarId))
  904. {
  905. var roleAvatarCfg = m_RoleAvatarCfgMap[avatarId];
  906. GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(Constants.ModelPath + "/" + roleAvatarCfg.avatarPrefab + ".prefab");
  907. m_BaseSkinSlotTypeMap.Add(skinSlotType, BindGo(skinSlotType, go, roleAvatarCfg.position, roleAvatarCfg.quaternion, roleAvatarCfg.scale));
  908. }
  909. }
  910. }
  911. }
  912. private void RemoveSkinSlotType(Dictionary<SkinSlotType, List<Renderer>> map, SkinSlotType skinSlotType)
  913. {
  914. if (map.ContainsKey(skinSlotType))
  915. {
  916. if (map[skinSlotType] != null)
  917. {
  918. foreach (var item in map[skinSlotType])
  919. {
  920. GameObject.DestroyImmediate(item.gameObject);
  921. }
  922. }
  923. map.Remove(skinSlotType);
  924. }
  925. }
  926. private int GetDefaultAvatarId(RoleCfgData roleCfgData, FashionSlotType fashionSlotType)
  927. {
  928. if (fashionSlotType == FashionSlotType.HeadTop)
  929. return roleCfgData.headTopId;
  930. else if (fashionSlotType == FashionSlotType.HeadMiddle)
  931. return roleCfgData.headMiddleId;
  932. else if (fashionSlotType == FashionSlotType.HeadBottom)
  933. return roleCfgData.headBottomId;
  934. // else if (fashionSlotType == FashionSlotType.Weapon)
  935. // return roleCfgData.leftWeaponId;
  936. else if (fashionSlotType == FashionSlotType.Cloth)
  937. return roleCfgData.clothId;
  938. else if (fashionSlotType == FashionSlotType.BodyBack)
  939. return roleCfgData.bodyBackId;
  940. else if (fashionSlotType == FashionSlotType.HairStyle)
  941. return roleCfgData.hairId;
  942. else if (fashionSlotType == FashionSlotType.Pupil)
  943. return roleCfgData.eyeId;
  944. return 0;
  945. }
  946. private List<Renderer> BindGo(SkinSlotType skinSlotType, GameObject go, Vector3? pos, Quaternion? quaternion, Vector3? scale)
  947. {
  948. if (!m_CurrentGo) return null;
  949. if (!go) return null;
  950. bool needDestroy = true;
  951. var sourceTrans = go.transform;
  952. go = GameObject.Instantiate(go);
  953. var trans = go.transform;
  954. Transform parentTrans = null;
  955. if (m_SkinSlotBindBone.ContainsKey(skinSlotType))
  956. {
  957. if (m_CurrentGoBoneMap.ContainsKey(m_SkinSlotBindBone[skinSlotType]))
  958. {
  959. parentTrans = m_CurrentGoBoneMap[m_SkinSlotBindBone[skinSlotType]];
  960. }
  961. else
  962. {
  963. parentTrans = m_CurrentGo.transform;
  964. }
  965. }
  966. else
  967. {
  968. parentTrans = m_CurrentGo.transform;
  969. }
  970. trans.SetParent(parentTrans);
  971. trans.localPosition = ((pos.HasValue) ? pos.Value : sourceTrans.localPosition);
  972. trans.localRotation = ((quaternion.HasValue) ? quaternion.Value : sourceTrans.localRotation);
  973. trans.localScale = ((scale.HasValue) ? scale.Value : sourceTrans.localScale);
  974. Renderer[] renderers = go.GetComponentsInChildren<Renderer>();
  975. List<Renderer> ls = new List<Renderer>();
  976. foreach (var renderer in renderers)
  977. {
  978. var mrTrans = renderer.transform;
  979. if (mrTrans == trans)
  980. {
  981. needDestroy = false;
  982. }
  983. if (renderer is SkinnedMeshRenderer)
  984. {
  985. mrTrans.SetParent(m_CurrentGo.transform);
  986. ls.Add(BindSMR(renderer as SkinnedMeshRenderer));
  987. }
  988. else
  989. {
  990. mrTrans.SetParent(parentTrans);
  991. mrTrans.gameObject.layer = m_CurrentGo.layer;
  992. ls.Add(renderer);
  993. }
  994. }
  995. if (needDestroy)
  996. {
  997. GameObject.DestroyImmediate(go);
  998. }
  999. return ls;
  1000. }
  1001. private SkinnedMeshRenderer BindSMR(SkinnedMeshRenderer smr)
  1002. {
  1003. smr.transform.SetParent(m_CurrentGo.transform);
  1004. smr.transform.localPosition = Vector3.zero;
  1005. smr.transform.localRotation = Quaternion.identity;
  1006. smr.transform.localScale = Vector3.one;
  1007. smr.gameObject.layer = m_CurrentGo.layer;
  1008. var rootBone = smr.rootBone;
  1009. if (rootBone)
  1010. {
  1011. if (m_CurrentGoBoneMap.ContainsKey(rootBone.name))
  1012. {
  1013. smr.rootBone = m_CurrentGoBoneMap[rootBone.name];
  1014. }
  1015. else
  1016. {
  1017. smr.rootBone = null;
  1018. }
  1019. }
  1020. Transform[] bones = smr.bones;
  1021. for (int i = 0, iMax = bones.Length; i < iMax; i++)
  1022. {
  1023. if (bones[i])
  1024. {
  1025. if (m_CurrentGoBoneMap.ContainsKey(bones[i].name))
  1026. {
  1027. bones[i] = m_CurrentGoBoneMap[bones[i].name];
  1028. }
  1029. else
  1030. {
  1031. bones[i] = null;
  1032. }
  1033. }
  1034. }
  1035. smr.bones = bones;
  1036. return smr;
  1037. }
  1038. private void BuildBoneMap(Transform root)
  1039. {
  1040. if (!root) return;
  1041. if (m_CurrentGoBoneMap.ContainsKey(root.name))
  1042. {
  1043. return;
  1044. }
  1045. m_CurrentGoBoneMap.Add(root.name, root);
  1046. for (int i = 0, iMax = root.childCount; i < iMax; i++)
  1047. {
  1048. BuildBoneMap(root.GetChild(i));
  1049. }
  1050. }
  1051. #endregion
  1052. #region Preview
  1053. private void RefreshPreviewGo()
  1054. {
  1055. if (!m_CurrentGo) return;
  1056. Selection.activeObject = m_CurrentGo;
  1057. }
  1058. #endregion
  1059. }
  1060. }