internal IDef LoadResource(string relativePath, Type type, bool asProto) { IDef resource; if (!asProto) { if (LoadedDefs.GetExisting(DefIDFull.Parse(relativePath), type, out resource)) { return(resource); } } resource = LoadFromDisk(relativePath); return(!type.IsInstanceOfType(resource) ? null : resource); }
private IDef LoadResource(DefIDFull id, Type type) { lock (_loadLock) { IDef resource; if (LoadedDefs.GetExisting(id, type, out resource)) { return(resource); } var relativePath = id.Root; if (!relativePath.StartsWith("/")) { throw new ArgumentException($"Path does not start with forward slash / {relativePath}", nameof(relativePath)); } try { //ProfileSampleBegin("LoadRes", id.Root); LoadFromDisk(relativePath); //ProfileSampleEnd(); } catch (Exception e) { Context = new LoadingContext(); Logger.LogError?.Invoke(e.ToString()); throw; } finally { } if (LoadedDefs.GetExisting(id, type, out resource)) { return(resource); } Logger.LogError?.Invoke($"Resource {id} not found"); return(null); } }