unityprotobuf自动生成C#

Release Protocol Buffers v3.19.4 · protocolbuffers/protobuf · GitHub

导入Source code 里面的 csharp/src/Google.Protobuf 进入Unity

拷贝其他版本的 System.Runtime.CompilerServices.Unsafe进入工程

使用protoc-3.19.4-win32 里面的exe去编译proto文件为C#

cs 复制代码
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using UnityEditor;
using UnityEngine;


//F:
//cd F:\TUANJIEProject\client\Common\NetProto\GenCSharp\Proto
//protoc.exe --csharp_out=./ --proto_path =./ Common.proto
//PAUSE

public static class ProtobufToCSharp
{
    //F:
    //cd F:\TUANJIEProject\client\Common\NetProto\GenCSharp\Proto
    //protoc.exe --csharp_out=./ --proto_path=./ Common.proto 
    //protoc.exe --csharp_out=F:\TUANJIEProject\client\Common\NetProto\GenCSharp\Proto --proto_path=./ Common.proto
    //protoc.exe -I=F:\TUANJIEProject\client\Common\NetProto\GenCSharp\Proto --csharp_out=F:\TUANJIEProject\client\Common\NetProto\GenCSharp\Proto Common.proto
    //protoc.exe -I=F:\TUANJIEProject\client\Common\NetProto\GenCSharp\Proto --csharp_out=F:\TUANJIEProject\client\Common\NetProto\GenCSharp\Proto Common.proto

    private static string ProtocPathExe = Application.dataPath.Replace("client/Assets", "Common/NetProto/GenCSharp/Proto/protoc.exe");
    private static string ProtoPath = Application.dataPath.Replace("client/Assets", "Common/NetProto/Source");
    private static string OutPath = Application.dataPath + "/HotUpdate/Game/ProtobufCSharp";
    [MenuItem("Protobuf/GenerateCSharp")]
    private static void GenerateCSharp()
    {
        UnityEngine.Debug.Log(ProtocPathExe);
        UnityEngine.Debug.Log(ProtoPath);
        UnityEngine.Debug.Log(OutPath);
        DirectoryInfo directoryInfo = new DirectoryInfo(ProtoPath);
        FileInfo[] fileInfos = directoryInfo.GetFiles();
        Process cmd = new Process();
        String proArgs = "";
        foreach (var fileInfo in fileInfos)
        {
            if (fileInfo.Extension != ".proto")
                continue;
            UnityEngine.Debug.Log(fileInfo.FullName);

            proArgs += $"{fileInfo.Name} ";
        }
        cmd.StartInfo.FileName = ProtocPathExe;
        Debug.Log
        cmd.StartInfo.Arguments = $"--proto_path={ProtoPath}/ --csharp_out={OutPath} {proArgs}";
        cmd.StartInfo.UseShellExecute = false;
        cmd.Start();
        AssetDatabase.Refresh();
    }
}
相关推荐
Hello.Reader6 小时前
一文吃透 Protobuf “Editions” 模式从概念、语法到迁移与实战
linux·服务器·网络·protobuf·editions
2301_7931169412 小时前
Unity 解决天空盒中间出现一条线
unity
佩京科技VR12 小时前
禁毒教育展厅互动设备-禁毒教育基地-禁毒体验馆方案-VR禁毒教育软件
unity·vr·禁毒展厅·vr禁毒学习机
平行云1 天前
Paraverse平行云实时云渲染助力第82届威尼斯电影节XR沉浸式体验
unity·云原生·ue5·xr·实时云渲染
Xeon_CC1 天前
Unity中,软遮罩SoftMaskForUGUI的使用
unity·游戏引擎
DanmF--1 天前
NGUI--三大基础组件
unity·游戏引擎
SmalBox1 天前
【URP】Unity3D物体遮罩的多种方案实现
unity·渲染
Xeon_CC1 天前
Unity中,软遮罩SoftMaskForUGUI可移动遮罩形状实现方法
unity·游戏引擎
Yasin Chen1 天前
Unity Standard Shader 解析(五)之ShadowCaster
unity·游戏引擎
我想_iwant2 天前
android集成unity后动态导入 assetsBundle
android·unity·游戏引擎