Archived
添加了更多的材质函数,部分与引擎新特性重合,这是为了能够脱离引擎在多个版本中更具可移植性。
添加了多种对程序流程控制与保全的脚本,而且现在可以更快速的构建一个具有线性关系的协程了。 添加了一个支持多种模式的单维梯度控制器,类似unity的颜色梯度类型。 添加了一个用于看向某个物体的旋转控制器。 添加了一个加载宏。 完善了批处理脚本流程。
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
#define _DEBUG_
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericLibrary.Runtime.MacroLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载宏
|
||||
/// </summary>
|
||||
public static class MacroResources
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
public static readonly Dictionary<string, string> FilePathName = new ()
|
||||
{
|
||||
// 图片
|
||||
{ "Sprite","Sprite" },
|
||||
{ "Texture2D","Sprite" },
|
||||
// 声音
|
||||
{ "Audio","Audio"},
|
||||
// 字体
|
||||
{ "Font","Font"},
|
||||
// 脚本
|
||||
{ "MonoBehaviour","Script"},
|
||||
// 脚本
|
||||
{ "RuntimeAnimatorController","Animation"},
|
||||
// 材质
|
||||
{ "PhysicMaterial","Material"},
|
||||
{ "Material","Material"},
|
||||
{ "Shader","Material"},
|
||||
// 模型
|
||||
{ "Mesh","Mesh"},
|
||||
// 预制体
|
||||
{ "GameObject","Prefab"},
|
||||
// 场景
|
||||
{ "Scene","Scene"},
|
||||
};
|
||||
|
||||
private static System.Type CacheType;
|
||||
|
||||
private static UnityEngine.Object[] ResourceCache;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 加载方法
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个类型应该存在的根路径
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetFileRootPath(System.Type type, out string path)
|
||||
{
|
||||
var name = type.Name;
|
||||
|
||||
if(FilePathName.TryGetValue(name, out path))
|
||||
return true;
|
||||
#if _DEBUG_
|
||||
Debug.LogError($"在Resources中加载{name}时并未找到一个有效的根路径");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个类型应该存在的根路径
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetFileRootPath<T>(out string path)
|
||||
{
|
||||
return GetFileRootPath(typeof(T), out path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个给定名称的特定文件类型的文件
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public static bool LoadFile<T>(this string fileName, out T result)
|
||||
where T : UnityEngine.Object
|
||||
{
|
||||
var type = typeof(T);
|
||||
if(!GetFileRootPath(type, out var path))
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
if(CacheType != type)
|
||||
{
|
||||
CacheType = type;
|
||||
ResourceCache = Resources.LoadAll<T>(path);
|
||||
}
|
||||
result = ResourceCache.FirstOrDefault(a => a.name == fileName) as T;
|
||||
return result != null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user