copy_shaders.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 shader files (.shader, .shadergraph) 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. shader_files = find_files_by_extension(str(assets_dir), '.shader')
  21. shader_graph_files = find_files_by_extension(str(assets_dir), '.shadergraph')
  22. files_to_copy = shader_files + shader_graph_files
  23. if not files_to_copy:
  24. print("No shader files found to copy.")
  25. return
  26. print(f"\n--- Starting Shader Handling ---")
  27. print(f"Found {len(files_to_copy)} shader files to copy.")
  28. for file_path_str in files_to_copy:
  29. file_path = Path(file_path_str)
  30. relative_path = file_path.relative_to(assets_dir)
  31. destination_path = output_assets_dir / relative_path
  32. destination_path.parent.mkdir(parents=True, exist_ok=True)
  33. try:
  34. shutil.copy(file_path, destination_path)
  35. except IOError as e:
  36. print(f"Error copying {file_path} to {destination_path}: {e}", file=sys.stderr)
  37. print("Shader copying complete.")
  38. if __name__ == "__main__":
  39. main()