-
Notifications
You must be signed in to change notification settings - Fork 62
/
create_unity_package.sh
executable file
·114 lines (98 loc) · 3.12 KB
/
create_unity_package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`
display_usage() {
echo "This script creates a temporary Unity project in '/tmp' directory, copy input asset and makes an unity package out of it. Valid Unity license is required."
echo ""
echo "Usage:"
echo "create_unity_package.sh -u <UNITY_PATH> -i [INPUT_ASSET] -p [PACKAGE_NAME] -o [OUTPUT_DIR]"
echo ""
echo "UNITY_PATH - Unity editor executable path"
echo "INPUT_ASSET - input asset to pack into unity package, default = 'install/asset/Ros2ForUnity'"
echo "PACKAGE_NAME - unity package name, default = 'Ros2ForUnity'"
echo "OUTPUT_DIR - output file directory, default = 'install/unity_package'"
}
UNITY_PATH=""
INPUT_ASSET="install/asset/Ros2ForUnity"
PACKAGE_NAME="Ros2ForUnity"
OUTPUT_DIR="$SCRIPTPATH/install/unity_package"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-u|--unity-path)
UNITY_PATH="$2"
shift # past argument
shift # past value
;;
-p|--package_name)
PACKAGE_NAME="$2"
shift # past argument
shift # past value
;;
-i|--input-directory)
INPUT_ASSET="$2"
shift # past argument
shift # past value
;;
-o|--output-directory)
OUTPUT_DIR="$2"
shift # past argument
shift # past value
;;
-h|--help)
display_usage
exit 0
shift # past argument
;;
*) # unknown option
shift # past argument
;;
esac
done
if [ -z "$UNITY_PATH" ] || [ -z "$PACKAGE_NAME" ] || [ -z "$INPUT_ASSET" ] || [ -z "$OUTPUT_DIR" ]; then
echo -e "\nMissing arguments!"
echo ""
display_usage
exit 1
fi
if [ ! -d "$INPUT_ASSET" ]; then
echo "Input asset '$INPUT_ASSET' doesn't exist! Use 'build.sh' to build project first."
exit 1
fi
UNITY_VERSION=`$UNITY_PATH -version`
# Test if unity editor is valid
if [[ $UNITY_VERSION =~ ^[0-9]{4}\.[0-9]*\.[0-9]*[f]?[0-9]*$ ]]; then
echo "Unity editor confirmed."
else
while true; do
read -p "Can't confirm Unity editor. Do you want to force \"$UNITY_PATH\" as an Unity editor executable? [y]es or [N]o: " yn
yn=${yn:-"n"}
case $yn in
[Yy]* ) break;;
[Nn]* ) exit 1;;
* ) echo "Please answer [y]es or [n]o.";;
esac
done
fi
echo "Using \"${UNITY_PATH}\" editor."
TMP_PROJECT_PATH=/tmp/ros2cs_unity_project/$UNITY_VERSION
# Create temp project
if [ -d "$TMP_PROJECT_PATH" ]; then
echo "Found existing temporary project for Unity $UNITY_VERSION."
rm -rf $TMP_PROJECT_PATH/Assets/*
else
rm -rf $TMP_PROJECT_PATH
echo "Creating Unity temporary project for Unity $UNITY_VERSION..."
$UNITY_PATH -createProject $TMP_PROJECT_PATH -batchmode -quit
fi
# Copy asset
echo "Copying asset to export..."
cp -r "$INPUT_ASSET" "$TMP_PROJECT_PATH/Assets/$PACKAGE_NAME"
# Creating asset
echo "Saving unitypackage '$OUTPUT_DIR/$PACKAGE_NAME.unitypackage'..."
mkdir -p $OUTPUT_DIR
$UNITY_PATH -projectPath "$TMP_PROJECT_PATH" -exportPackage "Assets/$PACKAGE_NAME" "$OUTPUT_DIR/$PACKAGE_NAME.unitypackage" -batchmode -quit
# Cleaning up
echo "Cleaning up temporary project..."
rm -rf $TMP_PROJECT_PATH/Assets/*
echo "Done!"