private object GetVariable <T>(T value, string varNameInShader)
{
Type t = value.GetType();
Type varType;
if (variableDict == null)
{
variableDict = new Dictionary <Type, Type>();
var types = AssemblyHelper.GetAllDerivedTypes(
typeof(UniformSingleVariableBase), x => !x.IsAbstract);
foreach (var item in types)
{
try
{
// example: variableDict.Add(typeof(int), typeof(UniformInt32));
variableDict.Add(item.GetProperty("Value").PropertyType, item);
}
catch (Exception)
{
}
}
}
if (variableDict.TryGetValue(t, out varType))
{
return(Activator.CreateInstance(varType, varNameInShader));
}
else
{
throw new Exception(string.Format(
"UniformVariable type [{0}] doesn't exists or not included in the variableDict!",
t));
}
}