CinemachineImpulseSourceEditor.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace Cinemachine.Editor
  4. {
  5. [CustomEditor(typeof(CinemachineImpulseSource))]
  6. internal sealed class CinemachineImpulseSourceEditor : BaseEditor<CinemachineImpulseSource>
  7. {
  8. float m_TestForce = 1;
  9. GUIContent m_TestButton = new GUIContent(
  10. "Invoke", "Play-mode only: Generate an impulse with the default velocity scaled by this amount");
  11. GUIContent m_TestLabel = new GUIContent(
  12. "Test with Force", "Generate an impulse with the default velocity scaled by an amount");
  13. public override void OnInspectorGUI()
  14. {
  15. BeginInspector();
  16. EditorGUILayout.Separator();
  17. EditorGUILayout.HelpBox(
  18. "Connect your impulse-generating event "
  19. + "to one of the GenerateImpulse API methods defined in this script.",
  20. MessageType.Info);
  21. DrawRemainingPropertiesInInspector();
  22. GUI.enabled = EditorApplication.isPlaying;
  23. {
  24. var r1 = EditorGUILayout.GetControlRect();
  25. r1 = EditorGUI.PrefixLabel(r1, m_TestLabel);
  26. var testButtonWidth = GUI.skin.button.CalcSize(m_TestButton).x;
  27. var r2 = r1;
  28. r1.width = testButtonWidth;
  29. r2.x += testButtonWidth + 3; r2.width -= testButtonWidth + 3;
  30. m_TestForce = EditorGUI.Slider(r2, m_TestForce, 0.1f, 20f);
  31. if (GUI.Button(r1, m_TestButton))
  32. Target.GenerateImpulseWithForce(m_TestForce);
  33. }
  34. GUI.enabled = true;
  35. }
  36. }
  37. }