private static void EnsureLookup(bool init) { if (AIManager._aiLookup != null) { return; } lock (AIManager.initLock) { if (AIManager._aiLookup == null) { AIManager._aiLookup = new Dictionary <Guid, AIManager.AIData>(); } else { return; } } AIStorage[] aIStorageArray = Resources.LoadAll <AIStorage>("ApexAIStorage"); for (int i = 0; i < (int)aIStorageArray.Length; i++) { AIManager.AIData aIDatum = new AIManager.AIData() { storedData = aIStorageArray[i] }; AIManager._aiLookup.Add(new Guid(aIDatum.storedData.aiId), aIDatum); if (init) { AIManager.ReadAndInit(aIDatum); } } }
public static IUtilityAI GetAI(Guid id) { AIManager.AIData aIDatum; AIManager.EnsureLookup(false); if (!AIManager._aiLookup.TryGetValue(id, out aIDatum)) { return(null); } if (aIDatum.ai == null) { lock (AIManager.initLock) { if (aIDatum.ai == null) { AIManager.ReadAndInit(aIDatum); } } } return(aIDatum.ai); }