MegaMultiVolSelectEditor.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using UnityEngine;
  2. using UnityEditor;
  3. [CanEditMultipleObjects, CustomEditor(typeof(MegaMultiVolSelect))]
  4. public class MegaMultiVolSelectEditor : MegaModifierEditor
  5. {
  6. public override string GetHelpString() { return "Multi Vol 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. MegaMultiVolSelect mod = (MegaMultiVolSelect)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. int order = EditorGUILayout.IntField("Order", mod.Order);
  19. if ( order != mod.Order )
  20. {
  21. mod.Order = order;
  22. MegaModifiers context = mod.GetComponent<MegaModifiers>();
  23. if ( context != null )
  24. context.BuildList();
  25. }
  26. mod.freezeSelection = EditorGUILayout.Toggle("Freeze Selection", mod.freezeSelection);
  27. mod.useCurrentVerts = EditorGUILayout.Toggle("Use Stack Verts", mod.useCurrentVerts);
  28. mod.displayWeights = EditorGUILayout.Toggle("Show Weights", mod.displayWeights);
  29. mod.gizCol = EditorGUILayout.ColorField("Gizmo Col", mod.gizCol);
  30. mod.gizSize = EditorGUILayout.FloatField("Gizmo Size", mod.gizSize);
  31. if ( GUILayout.Button("Add Volume") )
  32. {
  33. mod.volumes.Add(MegaVolume.Create());
  34. EditorUtility.SetDirty(target);
  35. }
  36. for ( int v = 0; v < mod.volumes.Count; v++ )
  37. {
  38. MegaVolume vol = mod.volumes[v];
  39. vol.enabled = EditorGUILayout.BeginToggleGroup("Enabled", vol.enabled);
  40. vol.volType = (MegaVolumeType)EditorGUILayout.EnumPopup("Type", vol.volType);
  41. if ( vol.volType == MegaVolumeType.Sphere )
  42. {
  43. vol.radius = EditorGUILayout.FloatField("Radius", vol.radius);
  44. }
  45. else
  46. {
  47. vol.boxsize = EditorGUILayout.Vector3Field("Size", vol.boxsize);
  48. }
  49. vol.weight = EditorGUILayout.Slider("Weight", vol.weight, 0.0f, 1.0f);
  50. vol.falloff = EditorGUILayout.FloatField("Falloff", vol.falloff);
  51. vol.origin = EditorGUILayout.Vector3Field("Origin", vol.origin);
  52. vol.target = (Transform)EditorGUILayout.ObjectField("Target", vol.target, typeof(Transform), true);
  53. vol.inverse = EditorGUILayout.Toggle("Inverse", vol.inverse);
  54. EditorGUILayout.EndToggleGroup();
  55. if ( GUILayout.Button("Delete Volume") )
  56. {
  57. mod.volumes.RemoveAt(v);
  58. v--;
  59. EditorUtility.SetDirty(target);
  60. }
  61. }
  62. return false;
  63. }
  64. // option to use base verts or current stack verts for distance calc
  65. // flag to display weights
  66. // size of weights and color of gizmo
  67. public override void DrawSceneGUI()
  68. {
  69. MegaMultiVolSelect mod = (MegaMultiVolSelect)target;
  70. if ( !mod.ModEnabled )
  71. return;
  72. MegaModifiers mc = mod.gameObject.GetComponent<MegaModifiers>();
  73. float[] sel = mod.GetSel();
  74. if ( mc != null && sel != null )
  75. {
  76. //Color col = Color.black;
  77. Matrix4x4 tm = mod.gameObject.transform.localToWorldMatrix;
  78. Handles.matrix = tm; //Matrix4x4.identity;
  79. if ( mod.displayWeights )
  80. {
  81. for ( int i = 0; i < sel.Length; i++ )
  82. {
  83. float w = sel[i];
  84. if ( w > 0.001f )
  85. {
  86. if ( w > 0.5f )
  87. Handles.color = Color.Lerp(Color.green, Color.red, (w - 0.5f) * 2.0f);
  88. else
  89. Handles.color = Color.Lerp(Color.blue, Color.green, w * 2.0f);
  90. MegaHandles.DotCap(i, mc.sverts[i], Quaternion.identity, mod.gizSize);
  91. }
  92. }
  93. }
  94. Vector3 origin = Vector3.zero;
  95. for ( int v = 0; v < mod.volumes.Count; v++ )
  96. {
  97. MegaVolume vol = mod.volumes[v];
  98. if ( vol.enabled )
  99. {
  100. Handles.color = mod.gizCol; //new Color(0.5f, 0.5f, 0.5f, 0.2f);
  101. // Draw box if box type
  102. if ( vol.volType == MegaVolumeType.Sphere )
  103. {
  104. //Handles.SphereCap(0, tm.MultiplyPoint(vol.origin), Quaternion.identity, vol.radius * 2.0f);
  105. MegaHandles.SphereCap(0, vol.origin, Quaternion.identity, vol.radius * 2.0f);
  106. }
  107. //else
  108. // Handles.CubeCap(.DrawCube(0, tm.MultiplyPoint(vol.origin), Quaternion.identity, vol.radius * 2.0f);
  109. //Handles.matrix = tm;
  110. if ( vol.target == null )
  111. {
  112. origin = Handles.PositionHandle(vol.origin, Quaternion.identity);
  113. if ( origin != vol.origin )
  114. {
  115. vol.origin = origin;
  116. EditorUtility.SetDirty(target);
  117. }
  118. }
  119. }
  120. }
  121. Handles.matrix = Matrix4x4.identity;
  122. }
  123. }
  124. }
  125. // multi vol select missing position handle bug fixed
  126. // Selections now update automatically when you drag volumes around in multi volume select
  127. // Selection now update automatically when you drag volumes around in volume select
  128. // Adding a volume from multi volume select now updates selection automaitcally
  129. // Deleting a volume from multi vol select updates the selections
  130. // Changing order value in multi volume select works now
  131. // new waving modifier added
  132. // deleting all volumes from multi volume select now clears the selection
  133. // Enable value added to each volume in multi volume select
  134. // help page added for Multi Volume Select modifier