MegaVertColSelectEditor.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using UnityEngine;
  2. using UnityEditor;
  3. [CanEditMultipleObjects, CustomEditor(typeof(MegaVertColSelect))]
  4. public class MegaVertColSelectEditor : MegaModifierEditor
  5. {
  6. public override string GetHelpString() { return "Vertex Color Select Modifier by Chris West"; }
  7. //public override Texture LoadImage() { return (Texture)EditorGUIUtility.LoadRequired("MegaFiers\\bend_help.png"); }
  8. public override bool DisplayCommon() { return false; }
  9. public override bool Inspector()
  10. {
  11. MegaVertColSelect mod = (MegaVertColSelect)target;
  12. #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019 && !UNITY_2020
  13. EditorGUIUtility.LookLikeControls();
  14. #endif
  15. mod.Label = EditorGUILayout.TextField("Label", mod.Label);
  16. mod.MaxLOD = EditorGUILayout.IntField("MaxLOD", mod.MaxLOD);
  17. mod.ModEnabled = EditorGUILayout.Toggle("Enabled", mod.ModEnabled);
  18. mod.Order = EditorGUILayout.IntField("Order", mod.Order);
  19. mod.weight = EditorGUILayout.FloatField("Weight", mod.weight);
  20. mod.threshold = EditorGUILayout.Slider("Threshold", mod.threshold, 0.0f, 1.0f);
  21. mod.channel = (MegaChannel)EditorGUILayout.EnumPopup("Channel", mod.channel);
  22. mod.displayWeights = EditorGUILayout.Toggle("Show Weights", mod.displayWeights);
  23. //mod.gizCol = EditorGUILayout.ColorField("Gizmo Col", mod.gizCol);
  24. mod.gizSize = EditorGUILayout.FloatField("Gizmo Size", mod.gizSize);
  25. if ( GUI.changed )
  26. {
  27. mod.update = true;
  28. }
  29. return false;
  30. }
  31. public override void DrawSceneGUI()
  32. {
  33. MegaVertColSelect mod = (MegaVertColSelect)target;
  34. MegaModifiers mc = mod.gameObject.GetComponent<MegaModifiers>();
  35. float[] sel = mod.GetSel();
  36. if ( mc != null && sel != null )
  37. {
  38. Color col = Color.black;
  39. Matrix4x4 tm = mod.gameObject.transform.localToWorldMatrix;
  40. Handles.matrix = Matrix4x4.identity;
  41. if ( mod.displayWeights )
  42. {
  43. for ( int i = 0; i < sel.Length; i++ )
  44. {
  45. float w = sel[i];
  46. if ( w > 0.5f )
  47. col = Color.Lerp(Color.green, Color.red, (w - 0.5f) * 2.0f);
  48. else
  49. col = Color.Lerp(Color.blue, Color.green, w * 2.0f);
  50. Handles.color = col;
  51. Vector3 p = tm.MultiplyPoint(mc.sverts[i]);
  52. if ( w > 0.001f )
  53. MegaHandles.DotCap(i, p, Quaternion.identity, mod.gizSize);
  54. }
  55. }
  56. }
  57. }
  58. }