static List <UnitAnimInfo> GetHeroAnimInfo() { string HeroAnimPath = ResourcesPath.GetRelativePath(ResourcesType.HeroAnim, ResourcesPathMode.Editor); List <UnitAnimInfo> list = new List <UnitAnimInfo>(); DirectoryInfo dir = new DirectoryInfo(Application.dataPath + "/" + HeroAnimPath); DirectoryInfo[] subDirs = dir.GetDirectories(); for (int i = 0; i < subDirs.Length; i++) { FileInfo[] files = subDirs[i].GetFiles(); for (int j = 0; j < files.Length; j++) { if (!files[j].Name.EndsWith(".anim")) { continue; } string assetPath = "Assets/" + HeroAnimPath + subDirs[i].Name + "/" + files[j].Name; AnimationClip anim = AssetDatabase.LoadAssetAtPath(assetPath, typeof(AnimationClip)) as AnimationClip; if (null != anim) { UnitAnimInfo info = new UnitAnimInfo(); info.ActorName = subDirs[i].Name; info.ActName = files[j].Name.Remove(files[j].Name.LastIndexOf('.')); info.FrameCount = (uint)(anim.frameRate * anim.length); list.Add(info); } } EditorUtility.DisplayProgressBar("导出英雄动画帧数", subDirs[i].Name, (float)(i + 1) / subDirs.Length); } EditorUtility.ClearProgressBar(); return(list); }
private void DrawAnimInfo(AType type, Dictionary <string, UnitAnimInfo> anims) { string key = EnumTool.Description(type); if (!anims.ContainsKey(key)) { anims.Add(key, new UnitAnimInfo(key)); } UnitAnimInfo info = anims[key]; EditorGUILayout.BeginVertical(); GUILayout.Toggle(true, string.Format("{0} 数据", info.Title), "dragtab"); int Count = info.List.Count; string[] names = AnimNames.ToArray(); List <int> reduce = new List <int>(); for (int i = 0; i < Count; i++) { GUILayout.BeginHorizontal(); string title = " "; if (i == 0) { title = "动作组:"; } GUILayout.Label(title, GUILayout.Width(80)); GUILayout.Button(info.List[i], "button"); if (GUILayout.Button("-", GUILayout.Width(24))) { reduce.Add(i); } int index = EditorGUILayout.Popup(title, StrTool.IndexOfToStr(names, info.List[i]), names); if (index != -1) { info.List[i] = names[index]; } GUILayout.EndHorizontal(); } if (reduce.Count > 0) { for (int i = 0; i < reduce.Count; i++) { info.List.RemoveAt(reduce[i]); } } if (GUILayout.Button("+")) { info.List.Add(string.Empty); } EditorGUILayout.EndVertical(); }
static List <UnitAnimInfo> GetTroopAnimInfo() { const string TroopModelPath = "Models/Units/Solider/"; List <UnitAnimInfo> list = new List <UnitAnimInfo>(); DirectoryInfo dir = new DirectoryInfo(Application.dataPath + "/" + TroopModelPath); DirectoryInfo[] subDirs = dir.GetDirectories(); for (int i = 0; i < subDirs.Length; i++) { FileInfo[] files = subDirs[i].GetFiles(); for (int j = 0; j < files.Length; j++) { //非模型跳过 if (!files[j].Name.EndsWith(".FBX")) { continue; } //非包含动画的模型也跳过 if (!files[j].Name.Contains("@") || files[j].Name.Contains("@skin")) { continue; } string assetPath = "Assets/" + TroopModelPath + subDirs[i].Name + "/" + files[j].Name; GameObject fbx = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject; if (null != fbx) { Animation fbxAnim = fbx.GetComponent <Animation>(); if (null != fbxAnim && null != fbxAnim.clip) { UnitAnimInfo info = new UnitAnimInfo(); info.ActorName = subDirs[i].Name; info.ActName = files[j].Name.Remove(files[j].Name.LastIndexOf('.')); info.ActName = info.ActName.Remove(0, info.ActName.LastIndexOf('@') + 1); info.FrameCount = (uint)(fbxAnim.clip.frameRate * fbxAnim.clip.length); list.Add(info); } } } EditorUtility.DisplayProgressBar("导出小兵动画帧数", subDirs[i].Name, (float)(i + 1) / subDirs.Length); } EditorUtility.ClearProgressBar(); return(list); }