示例#1
0
        public void Add <T>(string name, T value)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(name);
            }
            if (MethodRef <T> .Method == null)
            {
                throw new Exception("Unsupported property type: " + typeof(T));
            }

            // Any property set globally once needs to always be done the same way, or it'll just get ignored
            // When Unity introduces a 'clear global' function, we can change this
            // Also, *all* ComputeBuffer values need to be set globally if a CommandBuffer is being used - MaterialPropertyBlock.SetBuffer doesn't work
            if (CmdBuf != null &&
                CmdBuf != this &&                 // Should never happen, but just in case to prevent recursion
                (typeof(T) == typeof(ComputeBuffer) || globalPropertyNames.Contains(name)))
            {
                globalPropertyNames.Add(name);
                CmdBuf.Add(name, value);
            }
            else
            {
                if (globalPropertyNames.Contains(name))
                {
                    Debug.LogWarning("The shader property " + name + " is being set globally, and will probably be overridden");
                }
                MethodRef <T> .Method(PropertyBlock, name, value);
            }
        }
示例#2
0
 public void Add <T>(string name, T value)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(name);
     }
     if (MethodRef <T> .Method == null)
     {
         throw new Exception("Unsupported property type: " + typeof(T));
     }
     globalPropertyNames.Add(name);
     MethodRef <T> .Method(CmdBuf, name, value);
 }
示例#3
0
        public Type[] CallMethodDifferentWays()
        {
            var result = new Type[6];

            IL.Push(result);
            IL.Push(0);
            Ldtoken <int>();
            Call(new MethodRef(typeof(Type), nameof(Type.GetTypeFromHandle)));
            Stelem_Any <Type>();

            IL.Push(result);
            IL.Push(1);
            Ldtoken <int>();
            Call(new MethodRef(typeof(Type), nameof(Type.GetTypeFromHandle), typeof(RuntimeTypeHandle)));
            Stelem_Any <Type>();

            IL.Push(result);
            IL.Push(2);
            Ldtoken <int>();
            Call(new MethodRef(typeof(Type), nameof(Type.GetTypeFromHandle), 0, typeof(RuntimeTypeHandle)));
            Stelem_Any <Type>();

            IL.Push(result);
            IL.Push(3);
            Ldtoken <int>();
            Call(MethodRef.Method(typeof(Type), nameof(Type.GetTypeFromHandle)));
            Stelem_Any <Type>();

            IL.Push(result);
            IL.Push(4);
            Ldtoken <int>();
            Call(MethodRef.Method(typeof(Type), nameof(Type.GetTypeFromHandle), typeof(RuntimeTypeHandle)));
            Stelem_Any <Type>();

            IL.Push(result);
            IL.Push(5);
            Ldtoken <int>();
            Call(MethodRef.Method(typeof(Type), nameof(Type.GetTypeFromHandle), 0, typeof(RuntimeTypeHandle)));
            Stelem_Any <Type>();

            return(result);
        }