public void generatePrefab(string savePath, string prefabFileName, string dataFileName, string parentFolder) { string prefabName = prefabFileName.Substring(0, prefabFileName.Length - ".prefab".Length); GameObject prefab = new GameObject(prefabFileName); // 组件 MeshFilter meshFilter = prefab.AddComponent <MeshFilter>(); meshFilter.sharedMesh = instMesh; MeshRenderer renderer = prefab.AddComponent <MeshRenderer>(); renderer.sharedMaterial = instMaterial; if (this.genType == GenerateType.ModifyModelMatrix) { GPUSkinningAnimator animator = prefab.AddComponent <GPUSkinningAnimator>(); animator.mat = instMaterial; animator.lowMesh = instMesh; animator.textAsset = AssetDatabase.LoadAssetAtPath <GpuSkinningAnimData>(Path.Combine(savePath, dataFileName)); } else { GpuSkinningInstance instance = prefab.AddComponent <GpuSkinningInstance>(); instance.textAsset = AssetDatabase.LoadAssetAtPath <GpuSkinningAnimData>(Path.Combine(savePath, dataFileName)); } string prefabPath = Path.Combine(savePath, prefabFileName); PrefabUtility.CreatePrefab(prefabPath, prefab); GameObject.DestroyImmediate(prefab); }
public void generatePrefab(string savePath, string prefabFileName, string dataFileName, string parentFolder) { string prefabName = prefabFileName.Substring(0, prefabFileName.Length - ".prefab".Length); GameObject prefab = new GameObject(prefabFileName); // 组件 MeshFilter meshFilter = prefab.AddComponent <MeshFilter>(); meshFilter.sharedMesh = instMesh; MeshRenderer renderer = prefab.AddComponent <MeshRenderer>(); renderer.sharedMaterial = instMaterial; GpuSkinningInstance instance = prefab.AddComponent <GpuSkinningInstance>(); instance.textAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(Path.Combine(savePath, dataFileName)); string prefabPath = Path.Combine(savePath, prefabFileName); PrefabUtility.CreatePrefab(prefabPath, prefab); GameObject.DestroyImmediate(prefab); }