CreateAnim.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections.Generic;
  4. using System.Reflection;
  5. using WXB;
  6. public class CreateAnim
  7. {
  8. [MenuItem("Assets/CheckFileName")]
  9. static void CheckFileName()
  10. {
  11. string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
  12. HashSet<string> guilds = new HashSet<string>(AssetDatabase.FindAssets("", new string[] { assetPath }));
  13. foreach (string guid in guilds)
  14. {
  15. string ap = AssetDatabase.GUIDToAssetPath(guid);
  16. //if (ap.EndsWith("_.png"))
  17. //{
  18. // Debug.LogFormat(ap);
  19. //}
  20. if (string.IsNullOrEmpty(ap) || !ap.EndsWith(".png", true, null))
  21. continue;
  22. int pos = ap.LastIndexOf('/');
  23. if (!ap.Substring(pos + 1).StartsWith("anim_"))
  24. continue;
  25. int pos_ = ap.LastIndexOf('_');
  26. if (pos_ == -1)
  27. continue;
  28. System.Text.StringBuilder sb = new System.Text.StringBuilder();
  29. sb.Append(ap.Substring(0, pos_ + 1));
  30. int m = pos_ + 1;
  31. int e = ap.LastIndexOf('.') - 1;
  32. for (; m < e; ++m)
  33. {
  34. if (ap[m] != '0')
  35. break;
  36. }
  37. sb.Append(ap.Substring(m, ap.Length - m));
  38. //Debug.LogFormat("{0}->{1}", ap.Substring(7), sb.ToString().Substring(7));
  39. AssetDatabase.CopyAsset(ap, sb.ToString());
  40. AssetDatabase.DeleteAsset(ap);
  41. }
  42. }
  43. [MenuItem("Assets/更新动画数据")]
  44. static void UpdateAnim()
  45. {
  46. EditorConfigCSV csvCfg = new EditorConfigCSV();
  47. string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
  48. HashSet<string> guids = new HashSet<string>(AssetDatabase.FindAssets("", new string[] { assetPath }));
  49. Dictionary<string, Sprite> sprites = new Dictionary<string, Sprite>();
  50. foreach (string guid in guids)
  51. {
  52. Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetDatabase.GUIDToAssetPath(guid));
  53. foreach (Object o in objs)
  54. {
  55. if (o is Sprite)
  56. sprites.Add(o.name, o as Sprite);
  57. }
  58. }
  59. Dictionary<string, Cartoon> Cartoons = new Dictionary<string, Cartoon>();
  60. List<Sprite> tempss = new List<Sprite>();
  61. for (int i = 0; i < 1000; ++i)
  62. {
  63. string animName = string.Format("anim_{0}_", i);
  64. for (int j = 0; j < 100; ++j)
  65. {
  66. string frameName = animName + j;
  67. Sprite s = null;
  68. if (sprites.TryGetValue(frameName, out s))
  69. tempss.Add(s);
  70. }
  71. if (tempss.Count != 0)
  72. {
  73. string content = csvCfg.GetValue((i + 1).ToString(), "FrameTime", "EmojiCfg");
  74. if (string.IsNullOrEmpty(content))
  75. {
  76. continue;
  77. }
  78. string[] array = content.Split(';');
  79. Cartoon c = new Cartoon();
  80. c.name = i.ToString();
  81. c.content = content;
  82. c.sprites = tempss.ToArray();
  83. string width = csvCfg.GetValue((i + 1).ToString(), "Width", "EmojiCfg");
  84. string height = csvCfg.GetValue((i + 1).ToString(), "Height", "EmojiCfg");
  85. int width1 = 0;
  86. int height1 = 0;
  87. int.TryParse(width, out width1);
  88. int.TryParse(height, out height1);
  89. c.width = width1;
  90. c.height = height1;
  91. string xOffset = csvCfg.GetValue((i + 1).ToString(), "XOffset", "EmojiCfg");
  92. string yOffset = csvCfg.GetValue((i + 1).ToString(), "YOffset", "EmojiCfg");
  93. int xOffset1 = 0;
  94. int yOffset1 = 0;
  95. int.TryParse(xOffset, out xOffset1);
  96. int.TryParse(yOffset, out yOffset1);
  97. c.xOffset = xOffset1;
  98. c.yOffset = yOffset1;
  99. Cartoons.Add(i.ToString(), c);
  100. tempss.Clear();
  101. }
  102. }
  103. List<Cartoon> cartoons = new List<Cartoon>(Cartoons.Values);
  104. cartoons.Sort((Cartoon x, Cartoon y) =>
  105. {
  106. return int.Parse(x.name).CompareTo(int.Parse(y.name));
  107. });
  108. string path = Constants.UICommonPath + "/SymbolTextInit.prefab";
  109. SymbolTextInit sti = AssetDatabase.LoadAssetAtPath<SymbolTextInit>(path);
  110. sti.cartoons = cartoons.ToArray();
  111. EditorUtility.SetDirty(sti);
  112. AssetDatabase.SaveAssets();
  113. Debug.Log("emoji update over");
  114. csvCfg = null;
  115. }
  116. }