MegaMatSelect.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 
  2. using UnityEngine;
  3. [AddComponentMenu("Modifiers/Selection/Material")]
  4. public class MegaMatSelect : MegaSelectionMod
  5. {
  6. public override MegaModChannel ChannelsReq() { return MegaModChannel.Tris; }
  7. public override string ModName() { return "Material Select"; }
  8. public override string GetHelpURL() { return "?page_id=1305"; }
  9. public int matnum = 0;
  10. float[] modselection;
  11. public float[] GetSel() { return modselection; }
  12. public float gizSize = 0.01f;
  13. public bool displayWeights = true;
  14. public bool update = true;
  15. public float weight = 1.0f;
  16. public float otherweight = 0.0f;
  17. public override void GetSelection(MegaModifiers mc)
  18. {
  19. if ( ModEnabled )
  20. {
  21. if ( modselection == null || modselection.Length != mc.verts.Length )
  22. modselection = new float[mc.verts.Length];
  23. if ( update )
  24. {
  25. update = false;
  26. if ( matnum < 0 )
  27. matnum = 0;
  28. if ( matnum >= mc.mesh.subMeshCount )
  29. matnum = mc.mesh.subMeshCount - 1;
  30. int[] tris = mc.mesh.GetTriangles(matnum);
  31. for ( int i = 0; i < modselection.Length; i++ )
  32. modselection[i] = otherweight;
  33. for ( int i = 0; i < tris.Length; i++ )
  34. modselection[tris[i]] = weight;
  35. }
  36. mc.selection = modselection;
  37. }
  38. }
  39. }