15 private Func<string, Stream> _streamReceivingCallback;
16 private Func<string, string> _finalPathReceivingCallback;
18 public void Setup(Func<string, Stream> streamReceivingCallback, Func<string, string> finalPathReceivingCallback)
20 if (streamReceivingCallback ==
null)
throw new Exception(
"Callback parameter is missing.");
21 _streamReceivingCallback = streamReceivingCallback;
22 _finalPathReceivingCallback = finalPathReceivingCallback;
25 public override Stream
Map(AssetLoaderContext assetLoaderContext,
string originalFilename, out
string finalPath)
27 finalPath = _finalPathReceivingCallback !=
null
28 ? _finalPathReceivingCallback(originalFilename)
30 return _streamReceivingCallback(originalFilename);
39 private Func<ITexture, Stream> _streamReceivingCallback;
41 public void Setup(Func<ITexture, Stream> streamReceivingCallback)
43 if (streamReceivingCallback ==
null)
throw new Exception(
"Callback parameter is missing.");
44 _streamReceivingCallback = streamReceivingCallback;
47 public override TextureLoadingContext
Map(AssetLoaderContext assetLoaderContext, ITexture texture)
49 var stream = _streamReceivingCallback(texture);
50 return new TextureLoadingContext
52 Context = assetLoaderContext,
88 string modelExtension,
89 Action<IContextualizedError> onError,
90 Action<AssetLoaderContext, float> onProgress,
91 Action<AssetLoaderContext> onModelFullyLoad,
92 Func<string, Stream> customDataReceivingCallback,
93 Func<string, string> customFilenameReceivingCallback,
94 Func<ITexture, Stream> customTextureReceivingCallback,
95 string modelFilename =
null,
96 GameObject wrapperGameObject =
null,
98 object customData =
null)
100 if (data ==
null || data.Length == 0)
throw new Exception(
"Missing model file byte data.");
101 return LoadModelFromStream(
new MemoryStream(data), modelExtension, onError, onProgress, onModelFullyLoad,
102 customDataReceivingCallback, customFilenameReceivingCallback, customTextureReceivingCallback,
103 modelFilename, wrapperGameObject, assetLoaderOptions, customData);
130 string modelExtension,
131 Action<IContextualizedError> onError,
132 Action<AssetLoaderContext, float> onProgress,
133 Action<AssetLoaderContext> onModelFullyLoad,
134 Func<string, Stream> customDataReceivingCallback,
135 Func<string, string> customFilenameReceivingCallback,
136 Func<ITexture, Stream> customTextureReceivingCallback,
137 string modelFilename =
null,
138 GameObject wrapperGameObject =
null,
140 object customData =
null)
142 if (stream ==
null)
throw new Exception(
"Missing model file byte data.");
143 if (
string.IsNullOrWhiteSpace(modelExtension) && !
string.IsNullOrWhiteSpace(modelFilename))
144 modelExtension = FileUtils.GetFileExtension(modelFilename);
145 if (
string.IsNullOrWhiteSpace(modelExtension))
throw new Exception(
"Missing model extension parameter");
147 simpleExternalDataMapper.
Setup(customDataReceivingCallback, customFilenameReceivingCallback);
149 simpleTextureMapper.
Setup(customTextureReceivingCallback);
150 assetLoaderOptions = assetLoaderOptions ?? AssetLoader.CreateDefaultLoaderOptions();
151 assetLoaderOptions.ExternalDataMapper = simpleExternalDataMapper;
152 assetLoaderOptions.TextureMapper = simpleTextureMapper;
153 return AssetLoader.LoadModelFromStream(stream, modelFilename, modelExtension,
null, onModelFullyLoad,
154 onProgress, onError, wrapperGameObject, assetLoaderOptions, customData);
TriLibCore.AssetLoaderOptions AssetLoaderOptions
Represents a class used to load models from Byte Arrays using callbacks to map External Data and Text...
static AssetLoaderContext LoadModelFromByteData(byte[] data, string modelExtension, Action< IContextualizedError > onError, Action< AssetLoaderContext, float > onProgress, Action< AssetLoaderContext > onModelFullyLoad, Func< string, Stream > customDataReceivingCallback, Func< string, string > customFilenameReceivingCallback, Func< ITexture, Stream > customTextureReceivingCallback, string modelFilename=null, GameObject wrapperGameObject=null, AssetLoaderOptions assetLoaderOptions=null, object customData=null)
Loads a model from the given Byte Array data using the given callbacks to handle events/external data...
static AssetLoaderContext LoadModelFromStream(Stream stream, string modelExtension, Action< IContextualizedError > onError, Action< AssetLoaderContext, float > onProgress, Action< AssetLoaderContext > onModelFullyLoad, Func< string, Stream > customDataReceivingCallback, Func< string, string > customFilenameReceivingCallback, Func< ITexture, Stream > customTextureReceivingCallback, string modelFilename=null, GameObject wrapperGameObject=null, AssetLoaderOptions assetLoaderOptions=null, object customData=null)
Loads a model from the given Byte Array data using the given callbacks to handle events/external data...
Custom external data mapper which works with callbacks.
override Stream Map(AssetLoaderContext assetLoaderContext, string originalFilename, out string finalPath)
void Setup(Func< string, Stream > streamReceivingCallback, Func< string, string > finalPathReceivingCallback)
Custom texture mapper which works with callbacks.
override TextureLoadingContext Map(AssetLoaderContext assetLoaderContext, ITexture texture)
void Setup(Func< ITexture, Stream > streamReceivingCallback)