暫無描述
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.

BlackboardUtils.cs 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.ShaderGraph.Drawing
  6. {
  7. static class BlackboardUtils
  8. {
  9. internal static int GetInsertionIndex(VisualElement owner, Vector2 position, IEnumerable<VisualElement> children)
  10. {
  11. var index = -1;
  12. if (owner.ContainsPoint(position))
  13. {
  14. index = 0;
  15. foreach (VisualElement child in children)
  16. {
  17. Rect rect = child.layout;
  18. if (position.y > (rect.y + rect.height / 2))
  19. {
  20. ++index;
  21. }
  22. else
  23. {
  24. break;
  25. }
  26. }
  27. }
  28. return index;
  29. }
  30. internal static string FormatPath(string path)
  31. {
  32. if (string.IsNullOrEmpty(path))
  33. return "—";
  34. return path;
  35. }
  36. internal static string SanitizePath(string path)
  37. {
  38. var splitString = path.Split('/');
  39. List<string> newStrings = new List<string>();
  40. foreach (string s in splitString)
  41. {
  42. var str = s.Trim();
  43. if (!string.IsNullOrEmpty(str))
  44. {
  45. newStrings.Add(str);
  46. }
  47. }
  48. return string.Join("/", newStrings.ToArray());
  49. }
  50. }
  51. }