Created
September 23, 2019 02:05
-
-
Save neptaco/d37968d98664932d38015c04fea01847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModelProcessor : AssetPostprocessor | |
{ | |
public void OnPostprocessMeshHierarchy(GameObject root) { | |
var importer = (ModelImporter) assetImporter; | |
var exposePaths = FindTransformPaths(root.transform, (path, name) => | |
{ | |
var includes = new[] {"Neck", "Head"}; | |
return includes.Any(name.Contains); | |
}); | |
importer.optimizeGameObjects = true; | |
importer.extraExposedTransformPaths = exposePaths.ToArray(); | |
} | |
private List<string> FindTransformPaths(Transform transform, System.Func<string, string, bool> isExpose, List<string> paths = null, string parent = null) | |
{ | |
paths = paths ?? new List<string>(); | |
var path = parent == null ? transform.name : parent + "/" + transform.name; | |
if (isExpose(path, transform.name)) | |
{ | |
paths.Add(path); | |
} | |
foreach (Transform child in transform) { | |
FindTransformPaths(child, isExpose, paths, path); | |
} | |
return paths; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment