SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.9 KiB

4 years ago
  1. /*
  2. ------------------- Code Monkey -------------------
  3. Thank you for downloading the Code Monkey Utilities
  4. I hope you find them useful in your projects
  5. If you have any questions use the contact form
  6. Cheers!
  7. unitycodemonkey.com
  8. --------------------------------------------------
  9. */
  10. using System;
  11. using UnityEngine;
  12. using CodeMonkey.Utils;
  13. namespace CodeMonkey {
  14. /*
  15. * Debug Class with various helper functions to quickly create buttons, text, etc
  16. * */
  17. public static class CMDebug {
  18. // Creates a Button in the World
  19. public static World_Sprite Button(Transform parent, Vector3 localPosition, string text, System.Action ClickFunc, int fontSize = 30, float paddingX = 5, float paddingY = 5) {
  20. return World_Sprite.CreateDebugButton(parent, localPosition, text, ClickFunc, fontSize, paddingX, paddingY);
  21. }
  22. // Creates a Button in the UI
  23. public static UI_Sprite ButtonUI(Vector2 anchoredPosition, string text, Action ClickFunc) {
  24. return UI_Sprite.CreateDebugButton(anchoredPosition, text, ClickFunc);
  25. }
  26. // Creates a World Text object at the world position
  27. public static void Text(string text, Vector3 localPosition = default(Vector3), Transform parent = null, int fontSize = 40, Color? color = null, TextAnchor textAnchor = TextAnchor.UpperLeft, TextAlignment textAlignment = TextAlignment.Left, int sortingOrder = UtilsClass.sortingOrderDefault) {
  28. UtilsClass.CreateWorldText(text, parent, localPosition, fontSize, color, textAnchor, textAlignment, sortingOrder);
  29. }
  30. // World text pop up at mouse position
  31. public static void TextPopupMouse(string text) {
  32. UtilsClass.CreateWorldTextPopup(text, UtilsClass.GetMouseWorldPosition());
  33. }
  34. // Creates a Text pop up at the world position
  35. public static void TextPopup(string text, Vector3 position) {
  36. UtilsClass.CreateWorldTextPopup(text, position);
  37. }
  38. // Text Updater in World, (parent == null) = world position
  39. public static FunctionUpdater TextUpdater(Func<string> GetTextFunc, Vector3 localPosition, Transform parent = null) {
  40. return UtilsClass.CreateWorldTextUpdater(GetTextFunc, localPosition, parent);
  41. }
  42. // Text Updater in UI
  43. public static FunctionUpdater TextUpdaterUI(Func<string> GetTextFunc, Vector2 anchoredPosition) {
  44. return UtilsClass.CreateUITextUpdater(GetTextFunc, anchoredPosition);
  45. }
  46. // Text Updater always following mouse
  47. public static void MouseTextUpdater(Func<string> GetTextFunc, Vector3 positionOffset = default(Vector3)) {
  48. GameObject gameObject = new GameObject();
  49. FunctionUpdater.Create(() => {
  50. gameObject.transform.position = UtilsClass.GetMouseWorldPosition() + positionOffset;
  51. return false;
  52. });
  53. TextUpdater(GetTextFunc, Vector3.zero, gameObject.transform);
  54. }
  55. // Trigger Action on Key
  56. public static FunctionUpdater KeyCodeAction(KeyCode keyCode, Action onKeyDown) {
  57. return UtilsClass.CreateKeyCodeAction(keyCode, onKeyDown);
  58. }
  59. // Debug DrawLine to draw a projectile, turn Gizmos On
  60. public static void DebugProjectile(Vector3 from, Vector3 to, float speed, float projectileSize) {
  61. Vector3 dir = (to - from).normalized;
  62. Vector3 pos = from;
  63. FunctionUpdater.Create(() => {
  64. Debug.DrawLine(pos, pos + dir * projectileSize);
  65. float distanceBefore = Vector3.Distance(pos, to);
  66. pos += dir * speed * Time.deltaTime;
  67. float distanceAfter = Vector3.Distance(pos, to);
  68. if (distanceBefore < distanceAfter) {
  69. return true;
  70. }
  71. return false;
  72. });
  73. }
  74. }
  75. }