private void FillLayout() { SongMeta songMeta = sceneData.SongMeta; string titleText = (String.IsNullOrEmpty(songMeta.Title)) ? "" : songMeta.Title; string artistText = (String.IsNullOrEmpty(songMeta.Artist)) ? "" : " - " + songMeta.Artist; songLabel.text = titleText + artistText; int i = 0; GameObject selectedLayout = GetSelectedLayout(); foreach (PlayerProfile playerProfile in sceneData.PlayerProfiles) { sceneData.PlayerProfileToMicProfileMap.TryGetValue(playerProfile, out MicProfile micProfile); PlayerScoreControllerData playerScoreData = sceneData.GetPlayerScores(playerProfile); SongRating songRating = GetSongRating(playerScoreData.TotalScore); Injector childInjector = UniInjectUtils.CreateInjector(injector); childInjector.AddBindingForInstance(playerProfile); childInjector.AddBindingForInstance(micProfile); childInjector.AddBindingForInstance(playerScoreData); childInjector.AddBindingForInstance(songRating); childInjector.AddBinding(new Binding("playerProfileIndex", new ExistingInstanceProvider <int>(i))); SingingResultsPlayerUiController[] uiControllers = selectedLayout.GetComponentsInChildren <SingingResultsPlayerUiController>(); if (i < uiControllers.Length) { childInjector.InjectAllComponentsInChildren(uiControllers[i]); } i++; } }
private Injector CreateChildrenInjectorWithAdditionalBindings() { Injector newInjector = UniInjectUtils.CreateInjector(injector); newInjector.AddBindingForInstance(PlayerProfile); newInjector.AddBindingForInstance(MicProfile); newInjector.AddBindingForInstance(Voice); newInjector.AddBindingForInstance(MicSampleRecorder); newInjector.AddBindingForInstance(PlayerPitchTracker); newInjector.AddBindingForInstance(PlayerNoteRecorder); newInjector.AddBindingForInstance(PlayerScoreController); newInjector.AddBindingForInstance(playerUiController); newInjector.AddBindingForInstance(newInjector); newInjector.AddBindingForInstance(this); return(newInjector); }
public static Injector WithBindingForInstance <T>(this Injector injector, T existingInstance) { Injector childInjector = injector.CreateChildInjector(); childInjector.AddBindingForInstance(existingInstance); return(childInjector); }
public void ChildrenInjectorBindingsAreNotVisibleToParents() { Injector parentInjector = UniInjectUtils.CreateInjector(); Injector childInjector = UniInjectUtils.CreateInjector(parentInjector); childInjector.AddBindingForInstance("abc"); // The string is bound in the child and the parent can not use this binding. Assert.Throws <MissingBindingException>(delegate { parentInjector.GetValueForInjectionKey(typeof(string)); }); }
public void ParentInjectorBindingsAreVisibleToChildren() { Injector parentInjector = UniInjectUtils.CreateInjector(); Injector childInjector = UniInjectUtils.CreateInjector(parentInjector); parentInjector.AddBindingForInstance("abc"); // The string is bound in the parent and the child can use this binding. object valueForString = childInjector.GetValueForInjectionKey(typeof(string)); Assert.AreEqual("abc", valueForString); }