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();
    }
}
相关推荐
地狱为王6 小时前
Unity使用AnimeGANv3实现动漫风格化效果(二)
unity·游戏引擎
fcm196 小时前
unity之线框模式
unity·游戏引擎
unity工具人6 小时前
unity DoTween DoPath设置物体按照指定轨迹运动
unity·游戏引擎
程序猿阿伟6 小时前
《风格锚点+动态适配:Unity跨设备渲染的核心逻辑》
unity·游戏引擎
倚剑仙15 小时前
Unity-WebGL开发——用IIS(Internet Information Services)部署webGL工程
unity·游戏引擎·webgl
baldr_43961 天前
关于光照探针的实验和疑问
unity
作孽就得先起床1 天前
c#调Lua返回个字符串
unity·c#·lua·xlua
井队Tell1 天前
打造高清3D虚拟世界|零基础学习Unity HDRP高清渲染管线(第十天)
学习·3d·unity
Python私教2 天前
Unity 游戏开发「工业化级」学习路线 2025 版
学习·unity·游戏引擎
于小汐在咯2 天前
【Unity每日一记】Unity物理引擎:刚体与碰撞体详解
unity·游戏引擎