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();
    }
}
相关推荐
不伤欣1 小时前
游戏设计模式 - 子类沙箱
游戏·unity·设计模式
zhuyasen6 小时前
深度定制 protoc-gen-go:实现结构体字段命名风格控制
后端·go·protobuf
快乐觉主吖7 小时前
Unity的日志管理类
android·unity·游戏引擎
WarPigs15 小时前
Unity性能优化笔记
笔记·unity·游戏引擎
T.D.C21 小时前
【业务框架】3C-相机-Cinemachine
unity
Clank的游戏栈1 天前
Unity基于GraphView的可视化关卡编辑器开发指南
unity·编辑器·游戏引擎
海尔辛2 天前
Unity UI 性能优化--Sprite 篇
ui·unity·性能优化
喵个咪2 天前
开箱即用的GO后台管理系统 Kratos Admin - 代码生成工具集
微服务·orm·protobuf
XR-AI-JK2 天前
Unity VR/MR开发-VR设备与适用场景分析
unity·vr·mr
ChiLi_Lin2 天前
Unity异常上报飞书工具
unity·游戏引擎·飞书