MegaMatSelectEditor.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using UnityEngine;
  2. using UnityEditor;
  3. public class MegaHandles
  4. {
  5. public static void DotCap(int id, Vector3 pos, Quaternion rot, float size)
  6. {
  7. #if UNITY_5_6 || UNITY_2017 || UNITY_2018 || UNITY_2019 || UNITY_2020
  8. Handles.DotHandleCap(id, pos, rot, size, EventType.Repaint);
  9. #else
  10. Handles.DotCap(id, pos, rot, size);
  11. #endif
  12. }
  13. public static void SphereCap(int id, Vector3 pos, Quaternion rot, float size)
  14. {
  15. #if UNITY_5_6 || UNITY_2017 || UNITY_2018 || UNITY_2019 || UNITY_2020
  16. Handles.SphereHandleCap(id, pos, rot, size, EventType.Repaint);
  17. #else
  18. Handles.SphereCap(id, pos, rot, size);
  19. #endif
  20. }
  21. public static void ArrowCap(int id, Vector3 pos, Quaternion rot, float size)
  22. {
  23. #if UNITY_5_6 || UNITY_2017 || UNITY_2018 || UNITY_2019 || UNITY_2020
  24. Handles.ArrowHandleCap(id, pos, rot, size, EventType.Repaint);
  25. #else
  26. Handles.ArrowCap(id, pos, rot, size);
  27. #endif
  28. }
  29. }
  30. [CanEditMultipleObjects, CustomEditor(typeof(MegaMatSelect))]
  31. public class MegaMatSelectEditor : MegaModifierEditor
  32. {
  33. public override string GetHelpString() { return "Material Select Modifier by Chris West"; }
  34. //public override Texture LoadImage() { return (Texture)EditorGUIUtility.LoadRequired("MegaFiers\\bend_help.png"); }
  35. public override bool DisplayCommon() { return false; }
  36. public override bool Inspector()
  37. {
  38. MegaMatSelect mod = (MegaMatSelect)target;
  39. #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019 && !UNITY_2020
  40. EditorGUIUtility.LookLikeControls();
  41. #endif
  42. mod.Label = EditorGUILayout.TextField("Label", mod.Label);
  43. mod.MaxLOD = EditorGUILayout.IntField("MaxLOD", mod.MaxLOD);
  44. mod.ModEnabled = EditorGUILayout.Toggle("Enabled", mod.ModEnabled);
  45. mod.Order = EditorGUILayout.IntField("Order", mod.Order);
  46. mod.weight = EditorGUILayout.FloatField("Weight", mod.weight);
  47. mod.otherweight = EditorGUILayout.FloatField("Other Weight", mod.otherweight);
  48. mod.matnum = EditorGUILayout.IntField("Material Num", mod.matnum);
  49. mod.displayWeights = EditorGUILayout.Toggle("Show Weights", mod.displayWeights);
  50. //mod.gizCol = EditorGUILayout.ColorField("Gizmo Col", mod.gizCol);
  51. mod.gizSize = EditorGUILayout.FloatField("Gizmo Size", mod.gizSize);
  52. if ( GUI.changed )
  53. {
  54. mod.update = true;
  55. }
  56. return false;
  57. }
  58. public override void DrawSceneGUI()
  59. {
  60. MegaMatSelect mod = (MegaMatSelect)target;
  61. MegaModifiers mc = mod.gameObject.GetComponent<MegaModifiers>();
  62. float[] sel = mod.GetSel();
  63. if ( mc != null && sel != null )
  64. {
  65. Color col = Color.black;
  66. Matrix4x4 tm = mod.gameObject.transform.localToWorldMatrix;
  67. Handles.matrix = Matrix4x4.identity;
  68. if ( mod.displayWeights )
  69. {
  70. for ( int i = 0; i < sel.Length; i++ )
  71. {
  72. float w = sel[i];
  73. if ( w > 0.5f )
  74. col = Color.Lerp(Color.green, Color.red, (w - 0.5f) * 2.0f);
  75. else
  76. col = Color.Lerp(Color.blue, Color.green, w * 2.0f);
  77. Handles.color = col;
  78. Vector3 p = tm.MultiplyPoint(mc.sverts[i]);
  79. if ( w > 0.001f )
  80. MegaHandles.DotCap(i, p, Quaternion.identity, mod.gizSize);
  81. }
  82. }
  83. }
  84. }
  85. }