- Home /
Check if a class as been defined
Hi,
I am working on a script that changes the fog based on various properties. Now, I want to support the standard render fog, which is working fine, but I also want it to work with the GlobalFog Camera Effect (imageeffect of unity pro).
Basically, this all works fine. The problem is, that the GlobalFog script has to exist somewhere in the assetdirectory so that unity knows of the GlobalFog class, even if I don't want to use the GlobalFog. This is logical, since in my script I declare a variable of type GlobalFog.
But if I create a new project which does not have the GlobalFog script included at all, my script won't even compile because it could not find the GlobalFog definition.
So is it somehow possible to check if the class GlobalFog has been defined, and if not, skip my declarations? Something like the preprocessor defines?
#if GlobalFog
var myGlobalFog : GlobalFog
#endif
Cheers, Andre
PS: Working with javascript..
through reflection you can check the assemblies that were loaded into the domain.
import System;
import System.Reflection;
function getAssemblies()
{
return AppDomain.CurrentDomain.GetAssemblies(); // returns an array of Assembly.
}
function DoesTypeExist(typeName: String)
{
var asms: Assembly[];
asms = getAssemblies();
for(var asm:Assembly in asms)
{
for(var t:Type in asm.GetTypes())
{
if (t.Name == typeName)
return true;
}
}
}
i have no clue if this will work in UnityScript, untested. The theory is call DoesTypeExist with the type name you're looking for, though it may have a namespace in it, you will need to mess around if it even works.
Your answer
Follow this Question
Related Questions
one class (File) with different definitions in different projects 1 Answer
[CLOSED] When I use this code that I made, it adds to the item catalogue too? [CLOSED] 1 Answer
C# 2D Array of Class : why Class variables can't be changed? 2 Answers
How to get the class from a DragAndDrop.objectReferences? 0 Answers