This commit is contained in:
2026-07-15 16:19:07 +08:00
parent 64bad7c077
commit 544f4b2d01
7963 changed files with 447731 additions and 972637 deletions
@@ -0,0 +1,51 @@
using System.Collections.Generic;
using DG.Tweening;
namespace Roy
{
public class AnimationPipeline : BaseManager<AnimationPipeline>
{
private Queue<Tween> _tweenQueue = new Queue<Tween>(); // 动画队列
private Sequence _currentSequence; // 当前的动画Sequence
private bool _isPlaying = false; // 管线是否正在播放
// 向管线添加一个新的动画
public void AddToPipeline(Tween newTween)
{
_tweenQueue.Enqueue(newTween); // 将新的动画放入队列
if (!_isPlaying)
{
StartNextSequence(); // 如果没有播放中的动画,启动队列中的下一个动画
}
}
// 启动下一个动画序列
private void StartNextSequence()
{
if (_tweenQueue.Count == 0)
{
_isPlaying = false; // 队列为空,停止播放
return;
}
_isPlaying = true;
_currentSequence = DOTween.Sequence(); // 创建一个新的Sequence
while (_tweenQueue.Count > 0)
{
Tween nextTween = _tweenQueue.Dequeue();
_currentSequence.Append(nextTween); // 将每个Tween按顺序加入到Sequence
}
// 当Sequence完成时,检查队列中是否还有新的动画
_currentSequence.OnComplete(() =>
{
_isPlaying = false;
StartNextSequence(); // 如果还有新动画,继续播放
});
_currentSequence.Play(); // 播放当前Sequence
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a5e50fdce1d843d891c5bb1f55668145
timeCreated: 1728459955
@@ -0,0 +1,261 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ScrewsMaster;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
namespace Roy
{
public class FileNetworkManager : BaseManager<FileNetworkManager>
{
private readonly string _copyFolderPath;
private readonly string _configFolderPath;
public const string FolderName = "Configs";
public const string FolderLabel = "config";
public FileNetworkManager()
{
_copyFolderPath = Path.Combine(Application.streamingAssetsPath, FolderName);
_configFolderPath = Path.Combine(Application.persistentDataPath, FolderName);
}
public string GetConfigFOlderPath()
{
return _configFolderPath;
}
// 示例解析文件列表方法(你可以根据实际需求实现)
List<string> ParseFileList(string data)
{
// 假设 data 是文件列表的文本,解析文件名
// 根据实际情况解析,例如通过换行符分割
return data.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
public void CopyStreamingAssetsToPersistentDataPath(Action<bool> onComplete = null)
{
// 如果目标文件夹不存在,创建它
if (!Directory.Exists(_configFolderPath))
{
Directory.CreateDirectory(_configFolderPath);
}
CrazyAsyKit.StartCoroutine(CopyFile(onComplete));
// // 获取StreamingAssets中的文件,排除后缀为.meta的文件
// var files = Directory.GetFiles(_copyFolderPath)
// .Where(file => !file.EndsWith(".meta")) // 过滤 .meta 文件
// .ToList(); // 转换为列表以方便使用
//
// if (files.Count == 0)
// {
// onComplete?.Invoke(true); // 如果没有文件,直接回调成功
// return;
// }
//
// // 使用计数器来跟踪完成的文件复制
// int completedCount = 0;
//
// foreach (var file in files)
// {
// string fileName = Path.GetFileName(file);
// string sourceFilePath = file; // 原始文件路径
// string destFilePath = Path.Combine(_configFolderPath, fileName);
//
// // 读取并写入文件
// CrazyAsyKit.StartCoroutine(CopyFile(sourceFilePath, destFilePath,
// (result) =>
// {
// completedCount++;
// // 如果所有文件都已复制完成,调用回调
// if (completedCount == files.Count)
// {
// onComplete?.Invoke(true);
// }
// }));
// }
}
private IEnumerator CopyFile(Action<bool> onComplete = null)
{
var handle = Addressables.LoadResourceLocationsAsync(FolderLabel);
yield return handle;
if (handle.Status == AsyncOperationStatus.Succeeded)
{
// 查找以 ".json" 结尾的文件
var jsonLocation = handle.Result.FirstOrDefault(loc => loc.PrimaryKey.EndsWith(".json"));
if (jsonLocation != null)
{
var jsonFileName = Path.GetFileName(jsonLocation.PrimaryKey);
// 加载 JSON 文件
var textAssetAsync = Addressables.LoadAssetAsync<TextAsset>(jsonLocation);
yield return textAssetAsync;
if (textAssetAsync.Status == AsyncOperationStatus.Succeeded)
{
TextAsset jsonFile = textAssetAsync.Result;
Debug.Log("Loaded JSON content: " + jsonFile.text);
string destFilePath = Path.Combine(_configFolderPath, jsonFileName);
File.WriteAllBytes(destFilePath, jsonFile.bytes);
onComplete?.Invoke(true);
}
else
{
Debug.LogError("Failed to load JSON file");
onComplete?.Invoke(false);
}
}
else
{
Debug.LogError("No JSON file found in folder");
onComplete?.Invoke(false);
}
}
else
{
Debug.LogError("Failed to load folder resources");
onComplete?.Invoke(false);
}
}
private IEnumerator CopyFile(string sourceFile, string destFile, Action<bool> onComplete = null)
{
string filePath = "file://" + sourceFile;
using (UnityWebRequest www = UnityWebRequest.Get(filePath))
{
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.Success)
{
File.WriteAllBytes(destFile, www.downloadHandler.data);
Debug.Log($"File copied to {destFile}");
onComplete?.Invoke(true);
}
else
{
Debug.LogError("Failed to copy file: " + www.error);
onComplete?.Invoke(false);
}
}
}
/// <summary>
/// 读取或下载
/// </summary>
/// <param name="path"></param>
/// <param name="callback"></param>
public void ReadData(string path, Action<string> callback)
{
CrazyAsyKit.StartCoroutine(ReadDataEnumerator(path, callback));
}
/// <summary>
/// 读取或下载
/// </summary>
/// <param name="path"></param>
/// <param name="callback"></param>
/// <returns></returns>
private IEnumerator ReadDataEnumerator(string path, Action<string> callback)
{
string fullPath;
// 判断是网络URL还是本地文件路径
if (path.StartsWith("http://") || path.StartsWith("https://"))
{
fullPath = path; // 网络URL
}
else
{
// 本地文件路径
fullPath = "file://" + path;
}
// 使用UnityWebRequest读取数据
using (UnityWebRequest webRequest = UnityWebRequest.Get(fullPath))
{
yield return webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.ConnectionError || webRequest.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogError($"Error while reading file: {webRequest.error} path: {fullPath}");
callback?.Invoke(null); // 返回null表示出错
}
else
{
string data = webRequest.downloadHandler.text;
Debug.Log($"Data read successfully: {data}");
callback?.Invoke(data); // 通过回调传出数据
}
}
}
/// <summary>
/// 将内容写入指定文件,并删除原有文件。
/// </summary>
/// <param name="folderName">文件夹名称</param>
/// <param name="fileName">文件名称</param>
/// <param name="content">要写入的内容</param>
public void WriteToPersistentData(string folderName, string fileName, string content)
{
// 获取持久化数据路径
string folderPath = Path.Combine(Application.persistentDataPath, folderName);
// 如果文件夹不存在,则创建它
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
// 删除原有文件
var existingFiles = Directory.GetFiles(folderPath);
foreach (var file in existingFiles)
{
File.Delete(file);
}
// 完整文件路径
string filePath = Path.Combine(folderPath, fileName);
// 写入新文件
File.WriteAllText(filePath, content);
Debug.Log($"File written to: {filePath}");
}
/// <summary>
/// 提取指定目录下所有文件文件名
/// </summary>
/// <param name="subdirectory"></param>
/// <returns></returns>
public string[] GetFileNamesFromPersistentDataPath(string subdirectory)
{
string directoryPath = Path.Combine(Application.persistentDataPath, subdirectory);
if (Directory.Exists(directoryPath))
{
// 获取目录中的所有文件名
return Directory.GetFiles(directoryPath)
.Select(Path.GetFileName) // 只提取文件名
.ToArray();
}
else
{
Debug.LogWarning($"Directory does not exist: {directoryPath}");
return new string[0]; // 返回空数组
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2d7ee718e2a1471fa1d948628a66d1aa
timeCreated: 1727164004