ShaderUtilInterface

来源:互联网 发布:java反射调用泛型方法 编辑:程序博客网 时间:2024/06/07 18:01
using System.Collections;using System.Collections.Generic;using UnityEngine;using System.Reflection;using System.Linq;using System;public static class ShaderUtilInterface{    public static Dictionary<string, MethodInfo> methods = new Dictionary<string, MethodInfo>();    static ShaderUtilInterface() {        var asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetTypes().Any(t => t.Name == "ShaderUtil"));        if (asm != null)        {            var tp = asm.GetTypes().FirstOrDefault(t => t.Name == "ShaderUtil");            foreach (var method in tp.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static))            {                methods[method.Name] = method;            }        }    }    public static int GetPropertyCount(this Material shader)    {        return Call<int>("GetPropertyCount", shader.shader);    }    public static string GetPropertyName(this Material shader, int index)    {        return Call<string>("GetPropertyName", shader.shader, index);    }    public static int GetPropertyType(this Material shader, int index)    {        return Call<int>("GetPropertyType", shader.shader, index);    }    public static T Call<T>(string name, params object[] parameters)    {        return (T)methods[name].Invoke(null, parameters);    }}

原创粉丝点击