why
Unity uses Protobuf to do network transmission and data configuration, and has been using bat to call and generate data, but it cannot be used on MAC, which is very inconvenient. Cross-platform tool languages make it easier to operate on different platforms. Using BAT method, the code is difficult to write, and difficult to reuse. But Windows does not provide a Python environment. The Mac platform already has a Python environment, so you just need to integrate Python into the Windows environment.
plan
Install winpython-64bit -2.7.13.1 zero. exe and copy the folder to the project directory. Note that Python is called with the argument -e to avoid confusion with the Python installed on the system.
Using an example
Install the module command line, for example:
The tools > \ WinPython \ python Scripts \ PIP exe install protobuf = = 2.6.1
– Protobuf generation is modified to Python, note that calls vary from platform to platform:
#! /usr/bin/env python
#coding=utf-8
import sys
import os
import traceback
import subprocess
class ProtogenOperator:
def __init__(self) :
self.isWin = False
toolPath = ".. /.. /tools/Protobuf/"
self.monoPath = "/Library/Frameworks/Mono.framework/Versions/Current/bin/mono"
if sys.platform == "win32" :
toolPath= ".. \ \.. \\tools\\Protobuf\\"
self.isWin = True
self.protogenPath = toolPath
def DoProtogen(self, argValue) :
try :
if self.isWin:
command = self.protogenPath + "protogen " + argValue
os.system(command)
else:
p = subprocess.Popen(self.monoPath + "" + toolPath + "protogen.exe " + argValue, shell = False)
p.wait()
except BaseException, e :
print "protogen failed!"
return False
return True
Copy the code