win shell和macos shell脚本实例

前端之家收集整理的这篇文章主要介绍了win shell和macos shell脚本实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本实例的功能是命令行输入的Excels文件名和sheet名,输出符合protobuf格式的data数据文件和.cs存取类,分别提供了win和mac版本的脚本代码

第一步,将xls经过python的xls_deploy_tool.py转成data和proto

第二步:用proto.protobin把proto翻译成cs

第三步:将data和cs拷到Assets里

win shell脚本:

@echo off
set XLS_NAME=%1
set SHEET_NAME=%2

echo.
echo =========Compilation of %XLS_NAME%.xls=========

::---------------------------------------------------
::第一步,将xls经过xls_deploy_tool转成data和proto
::---------------------------------------------------
set STEP1_XLS2PROTO_PATH=.\step1_xls2proto
@echo on
cd tool\%STEP1_XLS2PROTO_PATH%

@echo off
echo TRY TO DELETE TEMP FILES:
del *_pb2.py
del *_pb2.pyc
del *.proto
del *.data
del *.log
del *.txt

@echo on
python xls_deploy_tool.py %SHEET_NAME% ..\..\..\..\Excels\%XLS_NAME%.xls

::---------------------------------------------------
::第二步:把proto翻译成cs
::---------------------------------------------------
cd ..

set STEP2_PROTO2CS_PATH=.\step2_proto2cs
set PROTO_DESC=proto.protobin

cd %STEP2_PROTO2CS_PATH%

@echo off
echo TRY TO DELETE TEMP FILES:
del *.cs
del *.protobin
del *.txt


@echo on
dir ..\%STEP1_XLS2PROTO_PATH%\*.proto /b  > protolist.txt

@echo on
for /f "delims=." %%i in (protolist.txt) do protoc ..\%STEP1_XLS2PROTO_PATH%\*.proto --descriptor_set_out=%PROTO_DESC% --proto_path=..\%STEP1_XLS2PROTO_PATH% 
for /f "delims=." %%i in (protolist.txt) do ProtoGen\protogen -i:%PROTO_DESC% -o:%%i.cs


cd ..

::---------------------------------------------------
::第三步:将data和cs拷到Assets里
::---------------------------------------------------

@echo off
set OUT_PATH=..\..\..\client\Assets\StreamingAssets
set DATA_DEST=DataConfig
set CS_DEST=Scripts\Server\DataConfig\ProtoGen


@echo on
copy %STEP1_XLS2PROTO_PATH%\*.data %OUT_PATH%\%DATA_DEST%
copy %STEP2_PROTO2CS_PATH%\*.cs %OUT_PATH%\%CS_DEST%

::---------------------------------------------------
::第四步:清除中间文件
::---------------------------------------------------
@echo off
echo TRY TO DELETE TEMP FILES:
cd %STEP1_XLS2PROTO_PATH%
del *_pb2.py
del *_pb2.pyc
del *.proto
del *.data
del *.log
del *.txt
cd ..
cd %STEP2_PROTO2CS_PATH%
del *.cs
del *.protobin
del *.txt
cd ..

::---------------------------------------------------
::第五步:结束
::---------------------------------------------------
cd ..
pause
@echo on

macos shell:

#!/bin/sh  
#.xls to .data and .proto
XLS_NAME=$1
SHEET_NAME=$2
XLS_SOURCE_PATH=../../../../../Excels/${XLS_NAME}.xls
#.proto to cs
cd ./protogen-master
STEP1_XLS2PROTO_PATH=step1_xls2proto
STEP2_PROTO2CS_PATH=step2_proto2cs
#1 .excel to .data and .proto
# delete cur file and copy to dir
cd ${STEP1_XLS2PROTO_PATH}
rm *.txt
rm *.proto
rm *.data
rm *.log
rm *_pb2.py
rm *_pb2.pyc
echo ${SHEET_NAME}
echo ${XLS_SOURCE_PATH}
python xls_deploy_tool.py ${SHEET_NAME} ${XLS_SOURCE_PATH}
#2 .proto to .protobin and .protobin to .cs
cd ../${STEP2_PROTO2CS_PATH}
rm *.protobin
rm *.proto
rm *.txt
rm *.cs
PRODESC=proto.protobin
ls ../${STEP1_XLS2PROTO_PATH}/*.proto > protolist.txt
for filePath in $(cat protolist.txt) 
do
	fileName=$(basename $filePath .proto)
    protoc ../${STEP1_XLS2PROTO_PATH}/*.proto --descriptor_set_out=${fileName}.protobin --proto_path=../${STEP1_XLS2PROTO_PATH} 
	mono protogen.exe -i:${fileName}.protobin -o:${fileName}.cs
	echo ${fileName}
done
# echo ../${STEP1_XLS2PROTO_PATH}/*.proto echo $(basename $filePath .protobin)
#protoc ../${STEP1_XLS2PROTO_PATH}/*.proto --descriptor_set_out=${PRODESC}
#for filePath in 'cat $protolist.txt' do mono protogen.exe -i:${PRODESC} -o:$(basename $filePath .protobin).cs
#3. copy to work space
OUT_PATH=../../../../client/Assets/StreamingAssets
DATA_DEST=${OUT_PATH}/DataConfig
CS_DEST=${OUT_PATH}/Scripts/Server/DataConfig/ProtoGen
cd ../
cp ${STEP1_XLS2PROTO_PATH}/*.data ${DATA_DEST}
cp ${STEP2_PROTO2CS_PATH}/*.cs ${CS_DEST}
echo 'successful!'

在unity3d游戏开发中,将策划Excels表转换为.data和.cs的详细实现过程为:

一、windows下构建Excel表: 1、安装环境: 1).先按照python2.7.7,cmd下执行python成功即可。 2).安装第三方插件protobuf-2.5.0和xlrd-1.0.0.tar,安装方法是解压文件,均到解压文件的setup.py下(protobuf-2.5.0在python子目录下)执行: python setup.py install 2、执行转表: 1)建表 在项目的c1\Excels建表,建立表的格式参考:goods_info_template.xls,详细格式见Excels下的:xls_deploy_tool.py内的注释。 Sheet名要求大写,名字最好和表名一样,或者以表名为前缀。 保存为.xls格式(97-2004版本)。 2)转表 cmd 到c1\tools\ExcelToProto目录下,执行命令: build Scenes SCENE_INFO PS:参数Scenes是表明,参数SCENE_INFO是Sheet名字(大写)。 二、MacOS下构建Excel表: 1、安装环境 1)安装Excels http://bbs.feng.com/read-htm-tid-9704285.html 2).安装protobuffer http://www.cnblogs.com/yanghuahui/p/4448728.html 3).安装mono 参考:http://blog.csdn.net/zhuangyou123/article/details/51482029 mono地址:http://www.mono-project.com/download/ 2、执行转表 1)建表 和windows下一样。 2)转表 cd到c1/tools/ExcelToProto/mactool目录下,执行命令: 若第一次执行,获取执行权限:chmod x+u build.sh 转表: ./build Scenes SCENE_INFO PS:参数Scenes是表明,参数SCENE_INFO是Sheet名字(大写)。

原文链接:https://www.f2er.com/bash/392744.html

猜你在找的Bash相关文章