copy_scripts.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import argparse
  2. import sys
  3. import shutil
  4. from pathlib import Path
  5. # Add the utils directory to the Python path
  6. utils_path = Path(__file__).parent.parent / 'utils'
  7. sys.path.append(str(utils_path))
  8. from file_utils import find_files_by_extension
  9. def main():
  10. parser = argparse.ArgumentParser(description="Copies all C# scripts (.cs) to the target directory.")
  11. parser.add_argument("--input", type=str, required=True, help="The root directory of the target Unity project.")
  12. parser.add_argument("--output", type=str, required=True, help="The directory where the output will be saved.")
  13. args = parser.parse_args()
  14. input_dir = Path(args.input).resolve()
  15. output_dir = Path(args.output).resolve()
  16. assets_dir = input_dir / "Assets"
  17. output_assets_dir = output_dir / "Assets"
  18. if not assets_dir.is_dir():
  19. return
  20. cs_files = find_files_by_extension(str(assets_dir), '.cs')
  21. if not cs_files:
  22. print("No C# scripts found to copy.")
  23. return
  24. print(f"\n--- Starting Script Handling ---")
  25. print(f"Found {len(cs_files)} C# script files to copy.")
  26. for script_path_str in cs_files:
  27. script_path = Path(script_path_str)
  28. relative_path = script_path.relative_to(assets_dir)
  29. destination_path = output_assets_dir / relative_path
  30. destination_path.parent.mkdir(parents=True, exist_ok=True)
  31. try:
  32. shutil.copy(script_path, destination_path)
  33. except IOError as e:
  34. print(f"Error copying {script_path} to {destination_path}: {e}", file=sys.stderr)
  35. print("Script copying complete.")
  36. if __name__ == "__main__":
  37. main()