Protogen.cs 967 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using ProtoBuf;
  6. using Google.Protobuf.Reflection;
  7. using ProtoBuf.Reflection;
  8. using System.IO;
  9. public class Protogen {
  10. [MenuItem("Bundle/Generate Protocs")]
  11. public static void GenerateProtobufCS(){
  12. Generate(Application.dataPath + "/../Proto/",new string[] { "mmopb.proto" }, Application.dataPath + "/../HotFix/");
  13. }
  14. static void Generate(string inpath,string[] inprotos,string outpath)
  15. {
  16. var set = new FileDescriptorSet();
  17. set.AddImportPath(inpath);
  18. foreach (var inproto in inprotos) {
  19. set.Add (inproto, true);
  20. }
  21. set.Process();
  22. var errors = set.GetErrors();
  23. CSharpCodeGenerator.ClearTypeNames ();
  24. var files = CSharpCodeGenerator.Default.Generate(set);
  25. foreach (var file in files)
  26. {
  27. var path = Path.Combine(outpath, file.Name);
  28. File.WriteAllText(path, file.Text);
  29. Debug.Log($"generated: {path}");
  30. }
  31. }
  32. }