copy_shaders.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import argparse
  2. import sys
  3. import shutil
  4. import json
  5. from pathlib import Path
  6. # Add the utils directory to the Python path
  7. utils_path = Path(__file__).parent.parent / 'utils'
  8. sys.path.append(str(utils_path))
  9. from file_utils import find_files_by_extension
  10. def main():
  11. parser = argparse.ArgumentParser(description="Copies all shader files (.shader, .shadergraph) to the target directory.")
  12. parser.add_argument("--input", type=str, required=True, help="The root directory of the target Unity project.")
  13. parser.add_argument("--output", type=str, required=True, help="The directory where the output will be saved.")
  14. # Add arguments that are passed by the orchestrator but not used by this script
  15. parser.add_argument("--indent", type=int, default=None)
  16. parser.add_argument("--shrink-json", action='store_true')
  17. parser.add_argument("--ignored-folders", type=str, default='[]', help='JSON string of folders to ignore.')
  18. args = parser.parse_args()
  19. try:
  20. ignored_folders = json.loads(args.ignored_folders)
  21. except json.JSONDecodeError:
  22. print("Warning: Could not parse ignored-folders JSON string. Defaulting to empty list.", file=sys.stderr)
  23. ignored_folders = []
  24. input_dir = Path(args.input).resolve()
  25. output_dir = Path(args.output).resolve()
  26. assets_dir = input_dir / "Assets"
  27. output_assets_dir = output_dir / "Assets"
  28. if not assets_dir.is_dir():
  29. return
  30. shader_files = find_files_by_extension(str(assets_dir), '.shader', ignored_folders=ignored_folders, project_root=input_dir)
  31. shader_graph_files = find_files_by_extension(str(assets_dir), '.shadergraph', ignored_folders=ignored_folders, project_root=input_dir)
  32. files_to_copy = shader_files + shader_graph_files
  33. if not files_to_copy:
  34. print("No shader files found to copy.")
  35. return
  36. print(f"\n--- Starting Shader Handling ---")
  37. print(f"Found {len(files_to_copy)} shader files to copy.")
  38. for file_path_str in files_to_copy:
  39. file_path = Path(file_path_str)
  40. relative_path = file_path.relative_to(assets_dir)
  41. destination_path = output_assets_dir / relative_path
  42. destination_path.parent.mkdir(parents=True, exist_ok=True)
  43. try:
  44. shutil.copy(file_path, destination_path)
  45. except IOError as e:
  46. print(f"Error copying {file_path} to {destination_path}: {e}", file=sys.stderr)
  47. print("Shader copying complete.")
  48. if __name__ == "__main__":
  49. main()