Demigiant

Paste DOTweenPath waypoints

Aug 25th, 2020 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1.         static readonly Regex _CopyWpsFromClipboardRegex = new Regex(@"(\(|\,)([-+]?[0-9]*\.?[0-9]+)");
  2.  
  3.         void CopyWaypointsToClipboard()
  4.         {
  5.             StringBuilder sBuilder = new StringBuilder();
  6.             sBuilder.Append("Vector3[] waypoints = new[] { ");
  7.             for (int i = 0; i < _src.wps.Count; ++i) {
  8.                 Vector3 wp = _src.wps[i];
  9.                 if (i > 0) sBuilder.Append(", ");
  10.                 sBuilder.Append(string.Format(
  11.                     "new Vector3({0}f,{1}f,{2}f)",
  12.                     wp.x.ToString(CultureInfo.InvariantCulture), wp.y.ToString(CultureInfo.InvariantCulture), wp.z.ToString(CultureInfo.InvariantCulture)
  13.                 ));
  14.             }
  15.             sBuilder.Append(" };");
  16.             EditorGUIUtility.systemCopyBuffer = sBuilder.ToString();
  17.         }
  18.  
  19.         void PasteWaypointsFromClipboard()
  20.         {
  21.             string s = EditorGUIUtility.systemCopyBuffer;
  22.             MatchCollection matches = _CopyWpsFromClipboardRegex.Matches(s);
  23.             if (matches.Count == 0) return;
  24.  
  25.             List<Vector3> wps = new List<Vector3>();
  26.             for (int i = 0; i < matches.Count; i += 3) {
  27.                 wps.Add(new Vector3(
  28.                      float.Parse(matches[i].Groups[2].Value, CultureInfo.InvariantCulture),
  29.                      float.Parse(matches[i+1].Groups[2].Value, CultureInfo.InvariantCulture),
  30.                      float.Parse(matches[i+2].Groups[2].Value, CultureInfo.InvariantCulture)
  31.                 ));
  32.             }
  33.             // DOTweenPath methods, you should use your own code to fill your own waypoints here
  34.             _src.wps = wps;
  35.             _wpsList.list = _src.wps;
  36.         }
Add Comment
Please, Sign In to add comment