DependencyInjector.ReplaceComponent C# (CSharp) Method

ReplaceComponent() public static method

public static ReplaceComponent ( newComponent ) : void
return void
    public static void ReplaceComponent<T>(T newComponent)
    {
        components[typeof(T)] = newComponent;
        foreach (var c in components.Values) {
            foreach (var f in GetFields(c.GetType())) {
                if (f.FieldType == typeof(T)) f.SetValue(c, newComponent);
            }
        }
    }

Usage Example

Example #1
0
    public IEnumerable Init()
    {
        mockNetworkClient = new MockNetworkClient();
        // Replace the real networkClient with mock object, it will be injected later into FirstScreen component
        DependencyInjector.ReplaceComponent <NetworkClient>(mockNetworkClient);

        #if UNITY_EDITOR
        yield return(LoadSceneByPath("Assets/UITest/Examples/TestableGameScene.unity"));

        //yield return LoadScene("TestableGameScene"); //Build issue -KLD
        #endif
    }
All Usage Examples Of DependencyInjector::ReplaceComponent