internal static SceneInfo GetSceneInfo(string nameSpace, string name) { // Try and fetch from cache. if (Cache.Scenes.TryGetValue(new ValueTuple <string, string>(nameSpace, name), out SceneInfo result)) { return(result); } result = new SceneInfo(); IEnumerable <SceneScript> enumerable = GetTypes <SceneScript>(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(SceneScript))); foreach (SceneScript script in enumerable) { if (script.LevelNamespace != nameSpace || script.LevelName != name) { continue; } result.SceneScript = script; ExecuteInEditorAttribute attribute = script?.GetType() .GetCustomAttributes(typeof(ExecuteInEditorAttribute), true) .FirstOrDefault() as ExecuteInEditorAttribute; if (attribute != null) { result.RunInEditor = true; } } Cache.Scenes.Add((nameSpace, name), result); return(result); }
internal static ComponentInfo GetComponentInfo(Type component) { // Try and fetch from cache. if (Cache.Components.TryGetValue(component, out ComponentInfo result)) { return(result); } // Throw exception if the Type isn't a component. if (component != typeof(Component) && !component.IsSubclassOf(typeof(Component))) { throw new Exception(nameof(component) + " is not a Component."); } // If an entry isn't found, create one. result = new ComponentInfo(); // Execute in editor attribute. ExecuteInEditorAttribute attribute = component .GetCustomAttributes(typeof(ExecuteInEditorAttribute), true) .FirstOrDefault() as ExecuteInEditorAttribute; if (attribute != null) { result.RunInEditor = true; } // Headless attribute. HeadlessModeAttribute headlessAttribute = component .GetCustomAttributes(typeof(HeadlessModeAttribute), true) .FirstOrDefault() as HeadlessModeAttribute; if (headlessAttribute != null) { result.HeadlessSupportMode = headlessAttribute.SupportMode; } // Add to cache and return. result.Update(); Cache.Components.Add(component, result); return(result); }