Files
MinFt/Client/Assets/Editor/FishiTool/FishAnimationLoop.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

151 lines
4.9 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections.Generic;
using System.Linq;
public class SetFishAnimationLoop : EditorWindow
{
// 需要设置Loop的动画名称
private string[] loopAnimations = new string[] { "Show01", "Swim01", "Idle01" };
// 手动输入鱼类名称(备用输入方式)
private string manualInput = "";
// 拖入的 fishprocess_list.cs 文件引用
private TextAsset fishProcessListAsset;
// 从 fishprocess_list.cs 中加载的鱼名
private string[] loadedFishList = null;
[MenuItem("Tools/FishTools/Set Animation Loop")]
static void Init()
{
SetFishAnimationLoop window = (SetFishAnimationLoop)EditorWindow.GetWindow(typeof(SetFishAnimationLoop));
window.titleContent = new GUIContent("Set Fish Loop Animations");
window.Show();
}
void OnGUI()
{
GUILayout.Label("🎣 Fish Animation Loop Settings", EditorStyles.boldLabel);
GUILayout.Space(10);
GUILayout.Label("1⃣ 手动输入鱼名(逗号或换行分隔):");
manualInput = EditorGUILayout.TextArea(manualInput, GUILayout.Height(60));
GUILayout.Space(15);
GUILayout.Label("2⃣ 或者拖入 fishprocess_list.cs 文件:");
fishProcessListAsset = (TextAsset)EditorGUILayout.ObjectField("fishprocess_list.cs", fishProcessListAsset, typeof(TextAsset), false);
if (fishProcessListAsset != null)
{
if (GUILayout.Button("加载鱼类名单"))
{
LoadFishListFromAsset(fishProcessListAsset);
}
}
if (loadedFishList != null && loadedFishList.Length > 0)
{
GUILayout.Label($"✅ 已加载 {loadedFishList.Length} 个鱼类");
}
GUILayout.Space(20);
if (GUILayout.Button("开始批量设置动画 Loop"))
{
ProcessFishAnimations();
}
}
private void LoadFishListFromAsset(TextAsset asset)
{
string content = asset.text;
int start = content.IndexOf('{');
int end = content.IndexOf('}');
if (start == -1 || end == -1 || end <= start)
{
Debug.LogError("❌ 无法从文件中解析鱼类名单,请检查 fishprocess_list.cs 格式");
return;
}
string inside = content.Substring(start + 1, end - start - 1);
loadedFishList = inside
.Split(',')
.Select(s => s.Trim().Trim('"').Trim('}', '{', ';'))
.Where(s => !string.IsNullOrEmpty(s) && s.StartsWith("F_"))
.ToArray();
Debug.Log($"✅ 成功从 {asset.name} 加载 {loadedFishList.Length} 个鱼类");
}
private void ProcessFishAnimations()
{
List<string> fishList = new List<string>();
if (loadedFishList != null && loadedFishList.Length > 0)
{
fishList.AddRange(loadedFishList);
}
else if (!string.IsNullOrEmpty(manualInput))
{
fishList.AddRange(manualInput
.Split(new[] { ',', '\n', '\r' }, System.StringSplitOptions.RemoveEmptyEntries)
.Select(f => f.Trim()));
}
else
{
Debug.LogError("❌ 未提供鱼类名单,请手动输入或加载文件。");
return;
}
string basePath = "Assets/AssetsPackage/art/fishsetting/mesh/";
int modifiedCount = 0;
foreach (string fishName in fishList)
{
string cleanName = new string(fishName
.Where(c => !Path.GetInvalidFileNameChars().Contains(c))
.ToArray())
.Trim()
.Replace("\r", "")
.Replace("\n", "")
.Replace("\"", "");
string fishPath = Path.Combine(basePath, cleanName);
if (!Directory.Exists(fishPath))
{
Debug.LogWarning($"⚠️ 未找到路径: {fishPath}");
continue;
}
foreach (string anim in loopAnimations)
{
string fbxPath = Path.Combine(fishPath, $"{fishName}@{anim}.fbx");
if (!File.Exists(fbxPath))
{
continue;
}
ModelImporter importer = AssetImporter.GetAtPath(fbxPath) as ModelImporter;
if (importer != null)
{
var clips = importer.clipAnimations.Length > 0 ? importer.clipAnimations : importer.defaultClipAnimations;
foreach (var clip in clips)
{
clip.loopTime = true;
}
importer.clipAnimations = clips;
importer.SaveAndReimport();
modifiedCount++;
Debug.Log($"✅ 设置循环动画: {fishName}@{anim}");
}
}
}
Debug.Log($"🎯 完成设置,共修改 {modifiedCount} 个动画文件。");
}
}