https://github.com/blkie/unityprotobuftemplate
unity protobuf template
https://github.com/blkie/unityprotobuftemplate
protobuf protobuf-net unity
Last synced: 4 months ago
JSON representation
unity protobuf template
- Host: GitHub
- URL: https://github.com/blkie/unityprotobuftemplate
- Owner: blkie
- Created: 2019-08-20T04:27:14.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-20T04:33:33.000Z (almost 6 years ago)
- Last Synced: 2025-01-14T13:55:53.839Z (4 months ago)
- Topics: protobuf, protobuf-net, unity
- Language: C#
- Homepage:
- Size: 96.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Unity Protobuf 模板
开箱即用## 依赖库
### protobuf-net
[地址](https://github.com/DGHeroin/protobuf-net)## 例子
```c#
UserInfo user = new UserInfo() {
Id = 1,
Name = "MyName",
Address = new AddressInfo() {
Street = "MyStreet",
ZIP = 123456
}
};
try {
byte[] bytes = Proto.Encode(user);
UserInfo newUser = Proto.Decode(bytes);
Debug.Log(newUser);
} catch (Exception e) {
Debug.Log(e);
}```
```c#
[ProtoContract]
public class UserInfo {
[ProtoMember(1)]
public int Id;[ProtoMember(2)]
public string Name;[ProtoMember(3)]
public AddressInfo Address;
}[ProtoContract]
public class AddressInfo {
[ProtoMember(1)]
public string Street;[ProtoMember(2)]
public int ZIP;
}
```