This commit is contained in:
2025-09-04 11:43:35 +08:00
parent 8872c20cf2
commit 60e4ef39ed
707 changed files with 1498 additions and 29309 deletions

View File

@@ -0,0 +1,88 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class BezierCurve
{
// 新增路径生成方法
public static Vector3[] GenerateBezierPath(Vector3[] controlPoints, int segments = 20)
{
Vector3[] path = new Vector3[segments + 1];
for (int i = 0; i <= segments; i++)
{
float t = i / (float)segments;
switch (controlPoints.Length)
{
case 2:
path[i] = LineBezier(controlPoints[0], controlPoints[1], t);
break;
case 3:
path[i] = QuadraticBezier(controlPoints, t);
break;
case 4:
path[i] = CubicBezier(controlPoints, t);
break;
default: // 处理n阶情况
path[i] = BezierInterpolation(controlPoints, t);
break;
}
}
return path;
}
// 一阶贝塞尔(线性插值)
public static Vector3 LineBezier(Vector3 p0, Vector3 p1, float t)
{
return Vector3.Lerp(p0, p1, t);
}
// 二阶贝塞尔曲线
public static Vector3 QuadraticBezier(Vector3[] points, float t)
{
if (points.Length != 3) Debug.LogError("需要3个控制点");
float u = 1 - t;
return
u * u * points[0] +
2 * u * t * points[1] +
t * t * points[2];
}
// 三阶贝塞尔曲线
public static Vector3 CubicBezier(Vector3[] points, float t)
{
if (points.Length != 4) Debug.LogError("需要4个控制点");
float u = 1 - t;
return
u * u * u * points[0] +
3 * u * u * t * points[1] +
3 * u * t * t * points[2] +
t * t * t * points[3];
}
// n阶贝塞尔曲线通用实现
public static Vector3 BezierInterpolation(Vector3[] points, float t)
{
if (points.Length < 2)
{
Debug.LogError("至少需要2个控制点");
return Vector3.zero;
}
Vector3[] temp = new Vector3[points.Length];
points.CopyTo(temp, 0);
// 德卡斯特里奥算法递推
for (int k = 1; k < points.Length; k++)
{
for (int i = 0; i < points.Length - k; i++)
{
temp[i] = Vector3.Lerp(temp[i], temp[i + 1], t);
}
}
return temp[0];
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d0f6bf90b6c476e4eb75f7a6dae5c45d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,66 @@
using System;
using UnityEngine;
namespace Stary.Evo
{
public static class VectorExtension {
public static Vector3Ctor GetVector3Ctor(this Vector3 vector)
{
return new Vector3Ctor(vector);
}
public static Vector3 SetVector3Ctor(this Vector3Ctor vector3Ctor)
{
return new Vector3(vector3Ctor.x, vector3Ctor.y, vector3Ctor.z);
}
public static Vector2Ctor GetVector2Ctor( this Vector2 vector)
{
return new Vector2Ctor(vector);
}
public static Vector2 SetVector2Data(this Vector2Ctor vector3Ctor)
{
return new Vector2(vector3Ctor.x, vector3Ctor.y);
}
}
[Serializable]
public class Vector3Ctor
{
public float x;
public float y;
public float z;
public Vector3Ctor()
{
}
public Vector3Ctor(Vector3 vector)
{
x = vector.x;
y = vector.y;
z = vector.z;
}
public Vector3Ctor(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
[Serializable]
public class Vector2Ctor
{
public float x;
public float y;
public Vector2Ctor(Vector2 vector)
{
x = vector.x;
y = vector.y;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1077acf7c628ea24586d2c243ab718b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
using UnityEngine;
using YooAsset;
namespace Stary.Evo
{
public class YooAssetFileSystem
{
public static InitializeParameters OfflineInitializeParameter()
{
var buildinFileSystemParams = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
var initParameters = new OfflinePlayModeParameters();
initParameters.BuildinFileSystemParameters = buildinFileSystemParams;
return initParameters;
}
public static InitializeParameters hostInitializeParameter()
{
var initParameters = new OfflinePlayModeParameters();
var buildinFileSystemParams = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(null,
$"{Application.persistentDataPath}/DownloadedContent/{AppConfig.PackageDomainName}");
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
initParameters.BuildinFileSystemParameters = buildinFileSystemParams;
return initParameters;
}
public static InitializeParameters EditorSimulateInitializeParameter()
{
var buildResult = EditorSimulateModeHelper.SimulateBuild(AppConfig.PackageDomainName);
var packageRoot = buildResult.PackageRootDirectory;
var editorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(packageRoot);
var initParams = new EditorSimulateModeParameters();
initParams.EditorFileSystemParameters = editorFileSystemParameters;
return initParams;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c6f288f9aa65416baf25a50a4056fcae
timeCreated: 1749695458

View File

@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
namespace Stary.Evo
{
public class ZipTool
{
// 新增:带进度回调的下载解压方法
public static async UniTask DownloadAndUnzipAsync(string fildId, string extractPath,
Action<float> downloadProgress = null, Action<float> unzipProgress = null)
{
string tempPath = Path.Combine(Application.persistentDataPath, "temp.zip");
try
{
string url = $"{AppConfig.IpConfig}/FileLoad/Download/{fildId}";
await WebRequestSystem.GetFile(url, tempPath,downloadProgress);
// 解压下载的文件
await UnzipAsync(tempPath, extractPath, unzipProgress);
File.Delete(tempPath);
}
finally
{
// 清理临时文件
if (File.Exists(tempPath))
{
File.Delete(tempPath);
}
}
}
// 修改:添加进度回调参数
public static async UniTask UnzipAsync(string zipPath, string extractPath,
Action<float> progressCallback = null)
{
try
{
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
float totalEntries = archive.Entries.Count;
float processed = 0;
foreach (ZipArchiveEntry entry in archive.Entries)
{
string filePath = Path.Combine(extractPath, entry.FullName);
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
if (!string.IsNullOrEmpty(entry.Name))
{
using (Stream inputStream = entry.Open())
using (FileStream outputStream = File.Create(filePath))
{
await inputStream.CopyToAsync(outputStream);
}
}
processed++;
float progress = processed / totalEntries;
progressCallback?.Invoke(progress);
}
}
Debug.Log($"解压完成: {extractPath}");
}
catch (Exception ex)
{
Debug.LogError($"解压失败: {ex.Message}");
throw;
}
}
/// <summary>
/// 自定义网络请求器需要登录
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
private static UnityWebRequest WebRequester(string url)
{
var request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET);
var authorization = GetAuthorization(AppConfig.UserName, AppConfig.PassWord);
request.SetRequestHeader("AUTHORIZATION", authorization);
return request;
}
private static string GetAuthorization(string userName, string password)
{
string auth = userName + ":" + password;
var bytes = System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(auth);
return "Basic " + System.Convert.ToBase64String(bytes);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2f5ebd73225744188b38cf307e565ff2
timeCreated: 1747988495