Skip to content

Instantly share code, notes, and snippets.

@adammyhre
Created August 12, 2025 14:25
Show Gist options
  • Save adammyhre/b7b7cda45097114a118a547a3ddb7afb to your computer and use it in GitHub Desktop.
Save adammyhre/b7b7cda45097114a118a547a3ddb7afb to your computer and use it in GitHub Desktop.

Revisions

  1. adammyhre created this gist Aug 12, 2025.
    68 changes: 68 additions & 0 deletions make-package.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    #!/usr/bin/env bash
    set -euo pipefail

    ##############################################
    # make-template.sh
    #
    # This script packages a Unity template for local use
    # in Unity Hub's ProjectTemplates folder.
    #
    # How it works:
    # 1. Prompts for the full Unity version (e.g., 6000.1.15f1 or 6000.1.0b12).
    # 2. Deletes ProjectVersion.txt from the package folder if it exists.
    # 3. Creates a .tgz archive from the 'package' folder.
    # 4. Moves the archive into the correct Unity ProjectTemplates folder
    # under C:\Program Files\Unity\Hub\Editor\<version>\Editor\Data\Resources\PackageManager\ProjectTemplates
    #
    # Requirements:
    # - Run this script in Git Bash with Administrator privileges.
    # - 'tar' command must be available (included with Git Bash).
    ##############################################

    TEMPLATE_NAME="com.unity.template.malevolent.tgz"
    SRC_DIR="package"

    require() { command -v "$1" >/dev/null 2>&1 || { echo "Error: $1 not found in PATH"; exit 1; }; }
    require tar

    if [[ ! -d "$SRC_DIR" ]]; then
    echo "Error: '$SRC_DIR' directory not found in $(pwd)"
    exit 1
    fi

    read -rp "Enter full Unity version (e.g., 6000.1.15f1): " UNITY_VERSION
    if [[ ! "$UNITY_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+[a-z][0-9]+$ ]]; then
    echo "Error: version must look like '6000.1.15f1' or '6000.1.0b12'"
    exit 1
    fi

    # Path to Unity's ProjectTemplates folder (Git Bash/MSYS format)
    TARGET_DIR="/c/Program Files/Unity/Hub/Editor/${UNITY_VERSION}/Editor/Data/Resources/PackageManager/ProjectTemplates"

    if [[ ! -d "$TARGET_DIR" ]]; then
    echo "Could not find: $TARGET_DIR"
    echo "Available Editors under /c/Program Files/Unity/Hub/Editor:"
    ls -1d "/c/Program Files/Unity/Hub/Editor"/* 2>/dev/null || true
    exit 1
    fi

    # Remove ProjectVersion.txt if present
    PROJECT_VERSION_FILE="${SRC_DIR}/ProjectData~/ProjectSettings/ProjectVersion.txt"
    if [[ -f "$PROJECT_VERSION_FILE" ]]; then
    echo "Removing $PROJECT_VERSION_FILE..."
    rm -f "$PROJECT_VERSION_FILE"
    else
    echo "No ProjectVersion.txt found, skipping removal."
    fi

    # Create the .tgz
    echo "Creating archive: $TEMPLATE_NAME from '$SRC_DIR'..."
    tar -czf "$TEMPLATE_NAME" "$SRC_DIR"

    # Move to Unity's ProjectTemplates folder
    echo "Moving $TEMPLATE_NAME to:"
    echo " $TARGET_DIR"
    mv -f "$TEMPLATE_NAME" "$TARGET_DIR/"

    echo "Done."
    echo "Template installed to: $TARGET_DIR/$TEMPLATE_NAME"