void GenerateDependencyDicts() { if (dependentScripts.Count != scriptDependencies.list.Count) { Debug.LogError("There should be a list of script dependencies for every dependent script in Dependent Scripts. Found " + dependentScripts.Count + " dependent scripts but only " + scriptDependencies.list.Count + " lists of script dependencies."); return; } for (int i = 0; i < dependentScripts.Count; i++) { List <MonoBehaviour> D = dependentScripts[i].list; for (int j = 0; j < D.Count; j++) { if (!(D[j] is IDependentScript)) { Debug.LogError(D[j].GetType().Name + " is not an IDependentScript."); continue; } IDependentScript currScript = (IDependentScript)D[j]; List <ILoadableScript> currScriptDependencies = new List <ILoadableScript>(); foreach (MonoBehaviour dependency in scriptDependencies.list[i].list) { if (!(dependency is ILoadableScript)) { Debug.LogError(dependency.GetType().Name + " is not an ILoadableScript."); continue; } currScriptDependencies.Add((ILoadableScript)dependency); } UpdateDependencyDicts(currScript, currScriptDependencies); } } }
public void UpdateDependencyDicts(IDependentScript newDependentScript, List <ILoadableScript> newDependencies) { if (dependencyDictionary.ContainsKey(newDependentScript)) { Debug.Log("Already stated dependencies for " + newDependentScript.GetType().Name); return; } List <ILoadableScript> waitableDependencies = new List <ILoadableScript>(); foreach (ILoadableScript currDependency in newDependencies) { //only wait on dependencies that haven't initialized yet if (!currDependency.IsInitialized()) { waitableDependencies.Add(currDependency); //Also update reverseDependencyDict if (reverseDependencyDict.ContainsKey(currDependency)) { reverseDependencyDict[currDependency].Add(newDependentScript); } else { //first time that the dependency is added to reverseDict currDependency.OnScriptInitialized += OnDependencyIntialized; //subscribe to initialization event of this dependency List <IDependentScript> newDependentScripts = new List <IDependentScript>(); newDependentScripts.Add(newDependentScript); reverseDependencyDict[currDependency] = newDependentScripts; } if (verbose) { Debug.Log(newDependentScript.GetType().Name + " has dependency " + currDependency.GetType().Name); } } else if (verbose) { Debug.Log(currDependency.GetType().Name + " is already loaded for dependent " + newDependentScript.GetType().Name); } } if (waitableDependencies.Count <= 0) { newDependentScript.OnAllDependenciesLoaded(); } else { dependencyDictionary[newDependentScript] = waitableDependencies; } }