Main/Assets/Launcher/ExternalLibs/PrefabAssetData/PrefabAssetEditorUtil.cs

91 lines
2.9 KiB
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Thousandto.Launcher.ExternalLibs
{
/// <summary>
/// 这个类只工作在编辑器状态下,因为在运行时,好像暂时没有方法获取Shader的一些属性信息
/// </summary>
public static class PrefabAssetEditorUtil
{
//获取属性数量
private static Func<Shader, int> _getCountFunc;
//获取属性类型
private static Func<Shader, int, int> _getTypeFunc;
//获取属性名字
private static Func<Shader, int, string> _getNameFunc;
//获取资源路径的处理函数
private static Func<UnityEngine.Object, string> _getAssetPathFunc;
//设置材质--这里用于编辑器
public static void SetHandler(Func<Shader,int> getCountFunc,
Func<Shader, int, int> getTypeFunc,
Func<Shader, int, string> getNameFunc,
Func<UnityEngine.Object, string> getAssetPathFunc
)
{
_getCountFunc = getCountFunc;
_getTypeFunc = getTypeFunc;
_getNameFunc = getNameFunc;
_getAssetPathFunc = getAssetPathFunc;
}
//获取属性数量
public static int GetShaderPropertyCount(Shader s)
{
if (_getCountFunc != null)
{
return _getCountFunc(s);
}
else
{
throw new Exception("请使用PrefabAssetEditorUtil.SetHandler来设置这个Shader的处理函数.参考类:UnityEditor.ShaderUtil");
}
}
//获取属性类型
public static int GetShaderPropertyType(Shader s, int idx)
{
if (_getTypeFunc!=null)
{
return _getTypeFunc(s, idx);
}
else
{
throw new Exception("请使用PrefabAssetEditorUtil.SetHandler来设置这个Shader的处理函数.参考类:UnityEditor.ShaderUtil");
}
}
//获取属性名字
public static string GetShaderPropertyName(Shader s, int idx)
{
if (_getNameFunc != null)
{
return _getNameFunc(s, idx);
}
else
{
throw new Exception("请使用PrefabAssetEditorUtil.SetHandler来设置这个Shader的处理函数.参考类:UnityEditor.ShaderUtil");
}
}
//获取属性名字
public static string GetAssetPath(UnityEngine.Object asset)
{
if (_getAssetPathFunc != null)
{
return _getAssetPathFunc(asset);
}
else
{
throw new Exception("请使用PrefabAssetEditorUtil.SetHandler来设置这个获取对象路径的处理函数.参考类:UnityEditor.AssetDatabase.GetAssetPath");
}
}
}
}