mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Compare commits
5 Commits
TEngine3.1
...
TEngine3.1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4c8c37ffd8 | ||
![]() |
5f694c2bed | ||
![]() |
7ff74bb747 | ||
![]() |
a5de63397a | ||
![]() |
13cc62f3f1 |
191
Assets/GameScripts/DotNet/Core/Helper/StringHelper.cs
Normal file
191
Assets/GameScripts/DotNet/Core/Helper/StringHelper.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public static class StringHelper
|
||||
{
|
||||
public static IEnumerable<byte> ToBytes(this string str)
|
||||
{
|
||||
byte[] byteArray = Encoding.Default.GetBytes(str);
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(this string str)
|
||||
{
|
||||
byte[] byteArray = Encoding.Default.GetBytes(str);
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
public static byte[] ToUtf8(this string str)
|
||||
{
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(str);
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
public static byte[] HexToBytes(this string hexString)
|
||||
{
|
||||
if (hexString.Length % 2 != 0)
|
||||
{
|
||||
throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The binary key cannot have an odd number of digits: {0}",
|
||||
hexString));
|
||||
}
|
||||
|
||||
var hexAsBytes = new byte[hexString.Length / 2];
|
||||
for (int index = 0; index < hexAsBytes.Length; index++)
|
||||
{
|
||||
string byteValue = "";
|
||||
byteValue += hexString[index * 2];
|
||||
byteValue += hexString[index * 2 + 1];
|
||||
hexAsBytes[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
return hexAsBytes;
|
||||
}
|
||||
|
||||
public static string Fmt(this string text, params object[] args)
|
||||
{
|
||||
return string.Format(text, args);
|
||||
}
|
||||
|
||||
public static string ListToString<T>(this List<T> list)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (T t in list)
|
||||
{
|
||||
sb.Append(t);
|
||||
sb.Append(",");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string ArrayToString<T>(this T[] args)
|
||||
{
|
||||
if (args == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string argStr = " [";
|
||||
for (int arrIndex = 0; arrIndex < args.Length; arrIndex++)
|
||||
{
|
||||
argStr += args[arrIndex];
|
||||
if (arrIndex != args.Length - 1)
|
||||
{
|
||||
argStr += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
argStr += "]";
|
||||
return argStr;
|
||||
}
|
||||
|
||||
public static string ArrayToString<T>(this T[] args, int index, int count)
|
||||
{
|
||||
if (args == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string argStr = " [";
|
||||
for (int arrIndex = index; arrIndex < count + index; arrIndex++)
|
||||
{
|
||||
argStr += args[arrIndex];
|
||||
if (arrIndex != args.Length - 1)
|
||||
{
|
||||
argStr += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
argStr += "]";
|
||||
return argStr;
|
||||
}
|
||||
|
||||
public static string PrintProto(this AProto proto, int stackIndex = 0, string propertyInfoName = "", bool isList = false, int listIndex = 0)
|
||||
{
|
||||
if (proto == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder _stringBuilder = new StringBuilder();
|
||||
_stringBuilder.Clear();
|
||||
|
||||
Type type = proto.GetType();
|
||||
_stringBuilder.Append($"\n");
|
||||
for (int i = 0; i < stackIndex; i++)
|
||||
{
|
||||
_stringBuilder.Append("\t");
|
||||
}
|
||||
|
||||
propertyInfoName = isList ? $"[{propertyInfoName}][{listIndex}]" : $"[{propertyInfoName}]";
|
||||
_stringBuilder.Append(stackIndex == 0? $"[{type.Name}]" : propertyInfoName);
|
||||
|
||||
var bindingFlags = BindingFlags.Public | BindingFlags.Instance;
|
||||
var propertyInfos = type.GetProperties(bindingFlags);
|
||||
for (var i = 0; i < propertyInfos.Length; ++i)
|
||||
{
|
||||
var propertyInfo = propertyInfos[i];
|
||||
|
||||
if (propertyInfo.PropertyType.BaseType == typeof (AProto))
|
||||
{
|
||||
_stringBuilder.Append(PrintProto((AProto)propertyInfo.GetValue(proto), stackIndex + 1, propertyInfo.Name));
|
||||
}
|
||||
else if (propertyInfo.PropertyType.IsList() && propertyInfo.PropertyType.IsGenericType)
|
||||
{
|
||||
object value = propertyInfo.GetValue(proto, null);
|
||||
if (value != null)
|
||||
{
|
||||
Type objType = value.GetType();
|
||||
int count = Convert.ToInt32(objType.GetProperty("Count").GetValue(value, null));
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
object item = objType.GetProperty("Item").GetValue(value, new object[] { j });
|
||||
_stringBuilder.Append(PrintProto((AProto)item, stackIndex + 1, propertyInfo.Name, isList: true, listIndex: j));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_stringBuilder.Append($"\n");
|
||||
for (int j = 0; j < stackIndex + 1; j++)
|
||||
{
|
||||
_stringBuilder.Append("\t");
|
||||
}
|
||||
|
||||
_stringBuilder.Append($"[{propertyInfo.Name}]");
|
||||
_stringBuilder.Append(": ");
|
||||
_stringBuilder.Append(propertyInfo.GetValue(proto));
|
||||
}
|
||||
}
|
||||
|
||||
return _stringBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断类型是否为可操作的列表类型
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsList(this Type type)
|
||||
{
|
||||
if (typeof (System.Collections.IList).IsAssignableFrom(type))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var it in type.GetInterfaces())
|
||||
{
|
||||
if (it.IsGenericType && typeof (IList<>) == it.GetGenericTypeDefinition())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/GameScripts/DotNet/Core/Helper/StringHelper.cs.meta
Normal file
11
Assets/GameScripts/DotNet/Core/Helper/StringHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c253fa0108e29234f9198e6b720bdbf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -104,7 +104,7 @@ namespace TEngine
|
||||
|
||||
int renderWidth = src.width >> DownSampleNum;
|
||||
int renderHeight = src.height >> DownSampleNum;
|
||||
m_renderTexture = RenderTexture.GetTemporary(renderWidth, renderHeight, 0, RenderTextureFormat.RGB111110Float);
|
||||
m_renderTexture = RenderTexture.GetTemporary(renderWidth, renderHeight, 0, RenderTextureFormat.Default);
|
||||
m_renderTexture.filterMode = FilterMode.Bilinear;
|
||||
|
||||
Graphics.Blit(src, m_renderTexture, material, 0);
|
||||
@@ -117,7 +117,7 @@ namespace TEngine
|
||||
material.SetFloat(DownSampleValue, BlurSpreadSize * widthMod + iterationOffs);
|
||||
// 【2.2】处理Shader的通道1,垂直方向模糊处理 || Pass1,for vertical blur
|
||||
// 定义一个临时渲染的缓存tempBuffer
|
||||
RenderTexture tempBuffer = RenderTexture.GetTemporary(renderWidth, renderHeight, 0, RenderTextureFormat.RGB111110Float);
|
||||
RenderTexture tempBuffer = RenderTexture.GetTemporary(renderWidth, renderHeight, 0, RenderTextureFormat.Default);
|
||||
// 拷贝rawTexture中的渲染数据到tempBuffer,并仅绘制指定的pass1的纹理数据
|
||||
Graphics.Blit(m_renderTexture, tempBuffer, material, 1);
|
||||
// 清空rawTexture
|
||||
@@ -126,7 +126,7 @@ namespace TEngine
|
||||
m_renderTexture = tempBuffer;
|
||||
// 【2.3】处理Shader的通道2,竖直方向模糊处理 || Pass2,for horizontal blur
|
||||
// 获取临时渲染纹理
|
||||
tempBuffer = RenderTexture.GetTemporary(renderWidth, renderHeight, 0, RenderTextureFormat.RGB111110Float);
|
||||
tempBuffer = RenderTexture.GetTemporary(renderWidth, renderHeight, 0, RenderTextureFormat.Default);
|
||||
// 拷贝rawTexture中的渲染数据到tempBuffer,并仅绘制指定的pass2的纹理数据
|
||||
Graphics.Blit(m_renderTexture, tempBuffer, m_material, 2);
|
||||
//【2.4】得到pass0、pass1和pass2的数据都已经准备好的rawTexture
|
||||
|
@@ -4,20 +4,38 @@ namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏时间。
|
||||
/// <remarks>统一封装调用。</remarks>
|
||||
/// <remarks>提供从Unity获取时间信息的接口。</remarks>
|
||||
/// </summary>
|
||||
public static class GameTime
|
||||
{
|
||||
/// <summary>
|
||||
/// 此帧开始时的时间(只读)。
|
||||
/// </summary>
|
||||
public static float time;
|
||||
|
||||
/// <summary>
|
||||
/// 从上一帧到当前帧的间隔(秒)(只读)。
|
||||
/// </summary>
|
||||
public static float deltaTime;
|
||||
|
||||
/// <summary>
|
||||
/// timeScale从上一帧到当前帧的独立时间间隔(以秒为单位)(只读)。
|
||||
/// </summary>
|
||||
public static float unscaledDeltaTime;
|
||||
|
||||
/// <summary>
|
||||
/// 执行物理和其他固定帧速率更新(如MonoBehavior的MonoBehaviour.FixedUpdate)的时间间隔(以秒为单位)。
|
||||
/// </summary>
|
||||
public static float fixedDeltaTime;
|
||||
|
||||
/// <summary>
|
||||
/// 自游戏开始以来的总帧数(只读)。
|
||||
/// </summary>
|
||||
public static float frameCount;
|
||||
|
||||
/// <summary>
|
||||
/// timeScale此帧的独立时间(只读)。这是自游戏开始以来的时间(以秒为单位)。
|
||||
/// </summary>
|
||||
public static float unscaledTime;
|
||||
|
||||
public static void StartFrame()
|
||||
|
@@ -587,14 +587,13 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>原生文件资源实例操作句柄。</returns>
|
||||
/// <remarks>需要自行释放资源句柄(RawFileOperationHandle)。</remarks>
|
||||
public async UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location, CancellationToken cancellationToken)
|
||||
{
|
||||
RawFileOperationHandle handle = YooAssets.LoadRawFileAsync(location);
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
|
||||
handle.Dispose();
|
||||
|
||||
return cancelOrFailed ? null : handle;
|
||||
}
|
||||
|
||||
|
@@ -13,6 +13,19 @@ public class Actor : ObjectBase
|
||||
/// </summary>
|
||||
/// <param name="isShutdown">是否是关闭对象池时触发。</param>
|
||||
protected override void Release(bool isShutdown){}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Actor对象。
|
||||
/// </summary>
|
||||
/// <param name="actorName">对象名称。</param>
|
||||
/// <param name="target">对象持有实例。</param>
|
||||
/// <returns></returns>
|
||||
public static Actor Create(string name, object target)
|
||||
{
|
||||
var actor = MemoryPool.Acquire<Actor>();
|
||||
actor.Initialize(name, target);
|
||||
return actor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,8 +42,10 @@ void Start()
|
||||
/// <summary>
|
||||
/// 创建Actor对象。
|
||||
/// </summary>
|
||||
/// <returns>Actor对象实例。</returns>
|
||||
public Actor CreateActor()
|
||||
/// <param name="actorName">对象名称。</param>
|
||||
/// <param name="target">对象持有实例。</param>
|
||||
/// <returns>Actor对象实例</returns>
|
||||
public Actor CreateActor(string actorName, GameObject target)
|
||||
{
|
||||
Actor ret = null;
|
||||
if (_actorPool.CanSpawn())
|
||||
@@ -39,7 +54,7 @@ public Actor CreateActor()
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = MemoryPool.Acquire<Actor>();
|
||||
ret = Actor.Create(actorName, target);
|
||||
_actorPool.Register(ret,true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user