VertexAnimationToolsAssetBase.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. namespace VertexAnimationTools_30 {
  4. #if UNITY_5_5_OR_NEWER
  5. [PreferBinarySerialization]
  6. #endif
  7. public class VertexAnimationToolsAssetBase : ScriptableObject {
  8. public List<MaterialInfo> Materials = new List<MaterialInfo>();
  9. public void SetMaterialsUnused() {
  10. for (int e = 0; e < Materials.Count; e++) {
  11. Materials[e].Used = false;
  12. }
  13. }
  14. public Material[] GetPolygonalMeshMaterials(string[] submeshesNames) {
  15. List<MaterialInfo> newMaterialsList = new List<MaterialInfo>();
  16. for (int i = 0; i < submeshesNames.Length; i++) {
  17. MaterialInfo info = null;
  18. for (int e = 0; e < Materials.Count; e++) {
  19. if (Materials[e].Name == submeshesNames[i]) {
  20. info = Materials[e];
  21. }
  22. }
  23. if (info == null) {
  24. info = new MaterialInfo(submeshesNames[i], Extension.GetRandomMaterial(submeshesNames[i]));
  25. Materials.Add(info);
  26. }
  27. info.Used = true;
  28. newMaterialsList.Add(info);
  29. }
  30. Material[] result = new Material[newMaterialsList.Count];
  31. for (int m = 0; m < result.Length; m++) {
  32. result[m] = newMaterialsList[m].Mat;
  33. }
  34. return result;
  35. }
  36. public void ClearUnusedMaterials() {
  37. List<MaterialInfo> unused = new List<MaterialInfo>();
  38. for (int i = 0; i < Materials.Count; i++) {
  39. if (Materials[i].Used == false) {
  40. unused.Add(Materials[i]);
  41. }
  42. }
  43. for (int i = 0; i < unused.Count; i++) {
  44. Materials.Remove(unused[i]);
  45. }
  46. }
  47. }
  48. }