using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace Thousandto.Launcher.ExternalLibs { /// /// 这个类只工作在编辑器状态下,因为在运行时,好像暂时没有方法获取Shader的一些属性信息 /// public static class PrefabAssetEditorUtil { //获取属性数量 private static Func _getCountFunc; //获取属性类型 private static Func _getTypeFunc; //获取属性名字 private static Func _getNameFunc; //获取资源路径的处理函数 private static Func _getAssetPathFunc; //设置材质--这里用于编辑器 public static void SetHandler(Func getCountFunc, Func getTypeFunc, Func getNameFunc, Func 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"); } } } }