ObjectGrabSettings.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System;
  5. namespace O3DWB
  6. {
  7. [Serializable]
  8. public class ObjectGrabSettings : ScriptableObject
  9. {
  10. [SerializeField]
  11. private bool _alignAxis = true;
  12. [SerializeField]
  13. private CoordinateSystemAxis _alignmentAxis = CoordinateSystemAxis.PositiveUp;
  14. [SerializeField]
  15. private float _rotationSensitivity = 1.0f;
  16. [SerializeField]
  17. private float _scaleSensitivity = 0.02f;
  18. [SerializeField]
  19. private float _offsetFromSurface = 0.0f;
  20. [SerializeField]
  21. private bool _embedInSurfaceWhenNoAlign = true;
  22. [SerializeField]
  23. private bool _showGrabLines = true;
  24. [SerializeField]
  25. private Color _grabLineColor = Color.green;
  26. private static readonly float _minSensitivity = 1e-2f;
  27. public bool AlignAxis { get { return _alignAxis; } set { _alignAxis = value; } }
  28. public CoordinateSystemAxis AlignmentAxis { get { return _alignmentAxis; } set { _alignmentAxis = value; } }
  29. public float RotationSensitivity { get { return _rotationSensitivity; } set { _rotationSensitivity = Mathf.Clamp(value, _minSensitivity, 1.0f); } }
  30. public float ScaleSensitivity { get { return _scaleSensitivity; } set { _scaleSensitivity = Mathf.Clamp(value, _minSensitivity, 1.0f); } }
  31. public float OffsetFromSurface { get { return _offsetFromSurface; } set { _offsetFromSurface = value; } }
  32. public bool EmbedInSurfaceWhenNoAlign { get { return _embedInSurfaceWhenNoAlign; } set { _embedInSurfaceWhenNoAlign = value; } }
  33. public bool ShowGrabLines { get { return _showGrabLines; } set { _showGrabLines = value; } }
  34. public Color GrabLineColor { get { return _grabLineColor; } set { _grabLineColor = value; } }
  35. public void RenderView()
  36. {
  37. bool newBool; float newFloat;
  38. var content = new GUIContent();
  39. content.text = "Align axis";
  40. content.tooltip = "If this is checked, the obejcts' axes will be aligned with the hovered surface. Use the \'Alignment axis\' property to " +
  41. "specify the alignment axis.";
  42. newBool = EditorGUILayout.ToggleLeft(content, AlignAxis);
  43. if(newBool != AlignAxis)
  44. {
  45. UndoEx.RecordForToolAction(this);
  46. AlignAxis = newBool;
  47. }
  48. if(_alignAxis)
  49. {
  50. content.text = "Alignment axis";
  51. content.tooltip = "Allows you to specify the alignment axis for the grabbed objects.";
  52. CoordinateSystemAxis newAxis = (CoordinateSystemAxis)EditorGUILayout.EnumPopup(content, AlignmentAxis);
  53. if(newAxis != AlignmentAxis)
  54. {
  55. UndoEx.RecordForToolAction(this);
  56. AlignmentAxis = newAxis;
  57. }
  58. }
  59. content.text = "Rotation sensitivity";
  60. content.tooltip = "Allows you to control how sensitive the rotation is to mouse movements. Only horizontal movements count.";
  61. newFloat = EditorGUILayout.Slider(content, RotationSensitivity, _minSensitivity, 1.0f);
  62. if(newFloat != RotationSensitivity)
  63. {
  64. UndoEx.RecordForToolAction(this);
  65. RotationSensitivity = newFloat;
  66. }
  67. content.text = "Scale sensitivity";
  68. content.tooltip = "Allows you to control how sensitive the scale is to mouse movements. Only horizontal movements count.";
  69. newFloat = EditorGUILayout.Slider(content, ScaleSensitivity, _minSensitivity, 1.0f);
  70. if (newFloat != ScaleSensitivity)
  71. {
  72. UndoEx.RecordForToolAction(this);
  73. ScaleSensitivity = newFloat;
  74. }
  75. Octave3DWorldBuilder.ActiveInstance.ShowGUIHint("Offset from surface only works when axis alignment is on OR when embedding is off.");
  76. content.text = "Offset from surface";
  77. content.tooltip = "Allows you to control how much objects are offset from the surface on which they're sitting.";
  78. newFloat = EditorGUILayout.FloatField(content, OffsetFromSurface);
  79. if (newFloat != OffsetFromSurface)
  80. {
  81. UndoEx.RecordForToolAction(this);
  82. OffsetFromSurface = newFloat;
  83. }
  84. content.text = "Embed in surface (no align)";
  85. content.tooltip = "If this is checked, the objects will be embedded inside the surface on which they reside by a specified percentage of their size. " +
  86. "This is useful for example when grabbing tress along a terrain surface with bumps/hills when axis alignment is turned off. In this case " +
  87. "embedding the tree will ensure the trunk of the tree will not float above the terrain.";
  88. newBool = EditorGUILayout.ToggleLeft(content, EmbedInSurfaceWhenNoAlign);
  89. if (newBool != EmbedInSurfaceWhenNoAlign)
  90. {
  91. UndoEx.RecordForToolAction(this);
  92. EmbedInSurfaceWhenNoAlign = newBool;
  93. }
  94. EditorGUILayout.Separator();
  95. content.text = "Show grab lines";
  96. content.tooltip = "Should the grab lines be drawn during a grab sesson. These are the lines that go from the objects' centers to the grab pivot.";
  97. newBool = EditorGUILayout.ToggleLeft(content, ShowGrabLines);
  98. if(newBool != ShowGrabLines)
  99. {
  100. UndoEx.RecordForToolAction(this);
  101. ShowGrabLines = newBool;
  102. }
  103. content.text = "Grab line color";
  104. content.tooltip = "During a grab session, a line will be drawn from each object's center to the grab pivot point. This field allows you to control the color of those lines.";
  105. Color newColor = EditorGUILayout.ColorField(content, GrabLineColor);
  106. if(newColor != GrabLineColor)
  107. {
  108. UndoEx.RecordForToolAction(this);
  109. GrabLineColor = newColor;
  110. SceneView.RepaintAll();
  111. }
  112. }
  113. }
  114. }
  115. #endif