ExampleHelpWindow.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. namespace Cinemachine.Examples
  3. {
  4. [AddComponentMenu("")] // Don't display in add component menu
  5. public class ExampleHelpWindow : MonoBehaviour
  6. {
  7. public string m_Title;
  8. [TextArea(minLines: 10, maxLines: 50)]
  9. public string m_Description;
  10. private bool mShowingHelpWindow = true;
  11. private const float kPadding = 40f;
  12. private void OnGUI()
  13. {
  14. if (mShowingHelpWindow)
  15. {
  16. Vector2 size = GUI.skin.label.CalcSize(new GUIContent(m_Description));
  17. Vector2 halfSize = size * 0.5f;
  18. float maxWidth = Mathf.Min(Screen.width - kPadding, size.x);
  19. float left = Screen.width * 0.5f - maxWidth * 0.5f;
  20. float top = Screen.height * 0.4f - halfSize.y;
  21. Rect windowRect = new Rect(left, top, maxWidth, size.y);
  22. GUILayout.Window(400, windowRect, (id) => DrawWindow(id, maxWidth), m_Title);
  23. }
  24. }
  25. private void DrawWindow(int id, float maxWidth)
  26. {
  27. GUILayout.BeginVertical(GUI.skin.box);
  28. GUILayout.Label(m_Description);
  29. GUILayout.EndVertical();
  30. if (GUILayout.Button("Got it!"))
  31. {
  32. mShowingHelpWindow = false;
  33. }
  34. }
  35. }
  36. }