腳本的使用方法:
1. 將腳本放到res目錄下(默認目錄名是res,當然你也可以手動替換為其他名字,修改path)
2. 修改輸出文件路徑和和資源文件夾的目錄名
3. 執行腳本,就能自動掃描當前目錄和子目錄的所有文件,自動判斷類型,產生出Cocos2d-html5支持的資源列表到js文件中。
# 1. Change the output file path by yourself
outputfile=/Users/linshun/work/FishingJoyH5/FishingJoyResource.js
# 2. Specify your resources directory name
path="res"
loopDir(){
for file in find *
do
if [ -d $file ]
then
echo "$file is directory"
cd ./$file
loopDir
cd ..
elif [ -f $file ]
then
echo "$file is file"
if [ ${file##*.} = "png" -o ${file##*.} = "jpg" ]
then
#echo "$extension"
echo "{type:\"image\", src:\"$path${PWD##*$path}/$file\"}," >> $outputfile
elif [ ${file##*.} = "plist" ]
then
echo "{type:\"plist\", src:\"$path${PWD##*$path}/$file\"}," >> $outputfile
elif [ ${file##*.} = "fnt" ]
then
echo "{type:\"fnt\", src:\"$path${PWD##*$path}/$file\"}," >> $outputfile
elif [ ${file##*.} = "tga" ]
then
echo "{type:\"tga\", src:\"$path${PWD##*$path}/$file\"}," >> $outputfile
elif [ ${file##*.} = "tmx" ]
then
echo "{type:\"tmx\", src:"$path${PWD##*$path}"/"$file"}," >> $outputfile
elif [ ${file##*.} = "mp3" -o ${file##*.} = "ogg" ]
then
#echo "$extension"
echo "{type:\"effect\", src:"$path${PWD##*$path}"/"$file"}," >> $outputfile
fi
fi
done
}
# Release the resource array to js file.
echo "var g_ressources = [" >> $outputfile
loopDir
#echo "{type:\"null\", src:\"null\"}" >> $outputfile
# remove the last comma
echo "];" >> $outputfile
echo "Finish."
轉載請注明:SeanLin,http://www.cnblogs.com/SeanLin/archive/2012/08/03/2621325.html