gpvigano / AsImpL

Asynchronous Importer and run-time Loader for Unity
MIT License
212 stars 37 forks source link

Ability to Attach Custom Script and custom Material on Import #18

Closed deltamish closed 6 years ago

deltamish commented 6 years ago

Hey,

Loved the asset. I was wondering If theres a method to attach a script or a material when loading async.

and also if there's going to be any optimization done using Unity Job system in the up coming releases

Thanks

gpvigano commented 6 years ago

In ObjectImporter you have some events you can register on. From documentation:

// handle the ImportedModel event
protected void OnModelImported(GameObject loadedObj, string absolutePath)
{
// Here you can get the Renderer components in the object children and change or replace materials
  MeshRenderer[] meshRend = loadedObj.GetComponentsInChildren<MeshRenderer>();
  foreach (var rend in meshRend)
  {
    Material mtl = rend.material; // or rend.sharedMaterial to change the material itself
    //...
  }
}
gpvigano commented 6 years ago

@deltamish About your second question: unfortunately I never thought about it, I suggest to create a new issue, sharing your knowledge about Unity job system, maybe with references, so everyone can understand your proposal. I will mark it as enhancement (and I'll think about it...).

deltamish commented 6 years ago

Hey Thanks a lot for the solution. Its even easier and faster this way than having a for loop and regularly check for Meshes .

and sure Ill create a new issue, But I have little knowledge on the topic