- Home /
Question by
Steffen Franz · Jan 14, 2013 at 04:08 PM ·
system.typetypeof
JS typeof() as System.Type, not a literal string
I have a JS class making a call
UIController.Instance.CurrentMenu.SwitchPanel(UIROOTDEF.NONE, typeof(SplashPanel));
that is trying to retrieve an object from a C# class
public void GetPanelObject(Type panelType, System.Action<UnityEngine.Object> callback)
{
Type panel = UIController.Instance.GetGUIType(panelType);
if(panel == typeof(SplashPanel))
{
......
}
.....
}
but since JS treats typeof() as a literal string, the if-statement will never catch it unless I would write something like
if(panel == typeof(SplashPanel) || panelType == "SplashPanel")
but the whole idea is to get objects by their actual type, avoid typo's as well as prevent slow string comparison.
Is there any syntactical sugar for JS that would let the JS function actually request the actual System.Type rather than a string representation of it?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613090930im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
If I let shift go restore fov 1 Answer
Touch Scrolling momentum 1 Answer
Static functions and lists not co-operating. 0 Answers
Randomizing Audio 1 Answer
How to read "mp3" or "other Audio" file from SDcard in runtime 0 Answers