public void TestInitializeComponentTypes() { FieldInfo field = typeof(ComponentTypeManager).GetField("ComponentTypes", BindingFlags.Static | BindingFlags.NonPublic); Assert.IsNotNull(field, "ComponentTypeManager.ComponentTypes field has not been found"); Assert.IsTrue(field.GetValue(null).GetType() == typeof(Dictionary <Type, ComponentType>), "ComponentTypes container is expected to be of type Dictionary<Type, ComponentType>"); // Debug.WriteLine("Resetting ComponentTypeManager.ComponentTypes..."); // field.SetValue(null, new Dictionary<Type, ComponentType>()); var componentTypes = (Dictionary <Type, ComponentType>)field.GetValue(null); Assert.IsNotNull(componentTypes, "Component Types dictionary must not be null"); // Assert.IsTrue(componentTypes.Count == 0, "Initial Component Types dictionary is expected to be empty."); // Debug.WriteLine("OK"); Debug.WriteLine("Initializing specific Component types..."); ComponentTypeManager.Initialize(new List <Type> { typeof(TestBaseComponent), typeof(TestDerivedComponent), typeof(TestHealthComponent), typeof(TestPowerComponent), typeof(TestPowerComponentPoolable), typeof(IComponent), // should be filtered out typeof(ComponentPoolable), // should be filtered out }); Debug.WriteLine("OK"); Assert.IsNotNull(componentTypes, "Initialized Component Types dictionary must not be null"); // NOTE: list of initialized types may change if you change existing Components var expectedTypes = new List <Type> { typeof(TestBaseComponent), typeof(TestDerivedComponent), typeof(TestHealthComponent), typeof(TestPowerComponent), typeof(TestPowerComponentPoolable) }; Debug.WriteLine("Checking initialized Component types..."); // Assert.AreEqual(expectedTypes.Count, componentTypes.Count, "Expected and actual Component Types count do not match."); foreach (var expectedType in expectedTypes) { Assert.IsTrue(componentTypes.ContainsKey(expectedType), "ComponentTypes is expected to contain {0}", expectedType); } Debug.WriteLine("OK"); }
public virtual void Start() { pixelCamera = Camera.main.gameObject.AddComponent <PixelCamera>(); pixelCamera.DesignWidth = _designWidth; pixelCamera.DesignHeight = _designHeight; var guiCamera = GameObject.Find("GUI Camera"); if (guiCamera != null) { PixelCamera pixelCameraGUI = guiCamera.AddComponent <PixelCamera>(); pixelCameraGUI.DesignWidth = _designWidth; pixelCameraGUI.DesignHeight = _designHeight; } ComponentTypeManager.Initialize(); }