88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
namespace BFEditor.Resource
|
|
{
|
|
public class CharacterTools
|
|
{
|
|
public const string FRAME_CONFIG = "帧数表.txt";
|
|
public const string UNITY_FBX_PATH = "Assets/arts/models/characters";
|
|
public const string UNITY_ANIMATION_PATH = "Assets/arts/animations/models/characters";
|
|
public const string UNITY_PREFAB_PATH = "Assets/prefabs/models/characters";
|
|
|
|
public static string importRootPath;
|
|
public static string importFbxPath;
|
|
public static string importTexturePath;
|
|
|
|
public static string GetDirNameByPath(string path)
|
|
{
|
|
var index = path.Replace("\\", "/").LastIndexOf("/");
|
|
var result = path.Replace("\\", "/");
|
|
if (index >= 0)
|
|
{
|
|
result = path.Replace("\\", "/").Substring(index + 1);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取帧数表
|
|
/// </summary>
|
|
public static List<ClipInfo> ReadFrameConfig(string path)
|
|
{
|
|
if (!File.Exists(path))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var list = new List<ClipInfo>();
|
|
var sr = File.OpenText(path);
|
|
var sLine = sr.ReadLine();
|
|
while (!string.IsNullOrEmpty(sLine))
|
|
{
|
|
var sz = sLine.Replace('\t', ' ').Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
|
if (sz.Length != 2)
|
|
{
|
|
Debug.LogWarning("帧数配置异常 " + path + " " + sLine);
|
|
continue;
|
|
}
|
|
|
|
var szFrame = sz[1].Split('-');
|
|
int.TryParse(szFrame[0].Trim(), out int start);
|
|
int.TryParse(szFrame[1].Trim(), out int end);
|
|
|
|
var isLoop = sz[0] == "idle" || sz[0] == "stun";
|
|
|
|
Debug.Log(sz[0]);
|
|
Debug.Log(isLoop);
|
|
var clipInfo = new ClipInfo(sz[0], start, end, isLoop);
|
|
list.Add(clipInfo);
|
|
|
|
sLine = sr.ReadLine();
|
|
}
|
|
sr.Close();
|
|
|
|
return list;
|
|
}
|
|
|
|
public class ClipInfo
|
|
{
|
|
public string name;
|
|
public int startFrame;
|
|
public int endFrame;
|
|
public bool isLoop;
|
|
|
|
public ClipInfo(string name, int startFrame, int endFrame, bool isLoop)
|
|
{
|
|
this.name = name;
|
|
this.startFrame = startFrame;
|
|
this.endFrame = endFrame;
|
|
this.isLoop = isLoop;
|
|
}
|
|
}
|
|
}
|
|
}
|