游戏开发论坛

 找回密码
 立即注册
搜索
查看: 9830|回复: 0

???????Unity????

[复制链接]

8717

主题

8783

帖子

1万

积分

版主

Rank: 7Rank: 7Rank: 7

积分
11952
发表于 2018-11-22 12:01:56 | 显示全部楼层 |阅读模式
?/???-27

????????????????????????????????Unity???????????????????????????????????????-27?????????????????????

???Unity???????

1.?Unity?????

???Unity????????GameObject??Network?????????????????????????????C#??????????Unity??????????UnityEngine.Networking ?????

1.1 ?????

???????Server????

1.jpg


??????????????????????????????true????????????????????????????????????????,?????????

1.2 ?????

???????????????Server??????????

2.jpg


?????Connect??????????????????????????OnClientConnected?????????OnConnectedServer???

?????????????????NetworkMessage??NetworkConnection?????????? ?????????????????????/??????????

3.jpg


1.3 ???

????Unity??????????????????????????????????????????

4.jpg


?????????????????????????

5.jpg


????????

6.jpg


?????????Unity?????????

?????????????

??????Unity????????????????????????????????????????????????????????

1.???????(CustomMsgTypes)

??????????????????????????RegisterHandler?????????????short????????????NetworkMessageDelegate???????????????????????MsgType????????????????

7.jpg


????????????UnityEngine.Networking????MsgType?????????????Unity???MsgType??????CustomMsgTypes?????????????

8.jpg


2.???????

????????????????????????????????UnityEngine.Networking???????Message????MessageBase???????? Deserialize ? Serialize ?????????????????????????

9.jpg


?????? Serialize ???msg?????????????Deserialize??????????????????

10.jpg


3. ???????

????????????????????????????????????????????NetworkConnection.Send???????????

11.jpg


????????????????Deserialize??????????

12.png


4.??

?????????? ?????????? => ?????????? => ????????????????????????????????????

???????????Packet?

1.??

????UnityEngine.Networking??????????????MessageBase??MessageBase??????????(?)NetworkReader?(?)NetworkWriter??????????????????????????????????????????????????int????4??????????int???10?????????1010,?????4??(????)????????????????(??????~)?????????????????????????????????????????????????????????

2.??

???????????????0?1???0?1??1??(bit)??8????1???(byte)?????????????

>bool = 1?
float = 32?
double = 64?
short, ushort = 16?
int, uint = 32?
long, ulong = 64?
string = 1?ASCII???8???????16?

?????????(?????)???(????1)0????????????????????????

??????????????????????????????(??)????????????????????????

3.??

Packet?

13.jpg


?????????????????????????????????????

14.jpg


????????????????????????????

15.jpg


?????????????????????????????????????

16.jpg


????????????????????????????????????????????????????

4.??

???????????????????????????????????????????????????????????????????????????

??????????????

1.?????????????(Simulate)

?Unity??????????Update?LateUpdate?FixedUpdate?

Update?LateUpdate???????????????????????????(LateUpdate?????Update?????????)????????????????????????60??????????????????30?????????1???????

FixedUpdate??????????????Unity???????????????????????????????

????????????????????????Unity?????FixedUpdate????Unity????Edit->roject Setting->time???Fixed timestep??????????????Time.fixedDeltaTime???

17.jpg


???????????FixedUpdate??????????????????????(Simulate)???????

2.????? + ??????? = ??????

???????????????????????????????????????????????????????????????????????????????????????????????????????????(Command)?

18.jpg


Simulate????????????????CommandInput????????CommandResult?

19.jpg


CollectCommandInput?ExecuteCommand?????????????????????

???????,???Command?????result???????????Command????????????????sequence(????)?????????????

???????

????_20181122114758.gif


3.??

???????Command?????????Simulate?????????????????????Command?

??????????????

?????????????????????????????????????????????????????????????????????????

1.?????????????(Entity)??

?????????????(SendRate)????????10???????????60??????????????????6????????????????Entity??????????

20.jpg


??????

21.jpg


????Entity???????????????

2.?????????????

?????????????????????????Entity????????????????????????????????Entity???????????????????????????????????????????10?????????????????????10????????????????????????????????????????????????(StateBuffer)?????(StateInterpolation)?

???????????????

??????????????(Frame)????????????????????????????????????????????????????????State_A?State_B????????????????????

> Current = MathUtils.Interpolate(State_A, State_B, ???? / (State_B.frame -State_A.frame ))

?????,?????????????????????????????????????

???????????????????????????????????????????????????????????????????????????????????????????????????(RemoteEstimatedFrame)?

?????????????????????????????????????????????????

22.jpg


????????????????????????????????????????????????????????????????????????????????????

23.jpg


?????

????_20181122115353.gif


????????,?????????????????????????????????????????????????????A?????B???????????(????)??A???????B???????????????????B????????????????????????B????????????????????????????????????

???????????????????????????????

24.jpg


?delay = 10(??????10????)????????????????????????????

????_20181122115358.gif


?????????????????????????????(???????,????????)?

3.??

?????????????????????????????????????????????????????????????????????

>???????????????????2????3(?????????1)????

????????????????????????????????????????

?????????????????????????????????????????????????????

???????????????????????????

??????????

?????????????????????????????????????????????????????????????????

1.???????????????????

?????(????)???????????????????????????

????????FPS?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

2.???????????????????????????

??????????????????????????(CommandInput)??????????????????????????????

25.jpg


?????????????????????????????????????????????????????????(ClientSendRate)??????????????????????????????

??????????60?/??????????60?Command???????ClientSendRate???????????????Command??????

26.jpg


????????????????????????????????????

27.jpg


3.????????????????????????????????

28.jpg


????????????????????????????????

29.jpg


???????????????????????????commandQueue??(??Command????Input?Result)?????????????????????Result?????????

30.jpg


4.????????????????

31.jpg


??????????????????????(commandQueue)?????????????????????????????????????????????????????????????????????????????????????????Command?????sequence???????????

32.jpg


?????????????(commandQueue)???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????(?????????)???????

??????????????????????????????????????

???????????????????????????????????????????????????????????????????????????????

33.jpg


?????????????????OnSimulateBefore()???????????????????????????????????????????????????????????????????????????????

????_20181122115403.gif


??????????

34.jpg


5.??

???????????????????????????? + N??? = ????????????????????????????????????

????????????????????????????????????????????????????????????????

???????????

???GDC2018????????????????(??????)???Rocket League?(????RT)????????????????????????Unreal Engine 3?????????Bullet???????????????????????????????????????Unity?????????????????????????

1.??????,??????

????????Cube?????Rigidbody??????????????????????

??????W?S?A?D????????Cube???????????

35.jpg


?????????????????????

2.Unity?????????

?Unity??????????PhysX??????????????PhysX?????????????????????????????????????????PhysX??????????????????(??Deterministic physics options)???????PhysX???????????????????????????????????????????????(??PhysX??????Unity????????????)?

Any way?????Unity???????????(????????????????????)???????????????????????Unity?????API-Physics.Simulate?????Physics.autoSimulation = false??Unity????????????????Physics.Simulate(fixedDeltaTime)???????.???????????????????

36.jpg


3.??????????????

?????,?????????position?rotation????rigidbody?velocity?angularVelocity???

37.jpg


??????????????????????????(6packet/second )?

????_20181122115408.gif


4.?????????????????????

????????????????????????Physics.Simulate(Time.fixedDeltaTime)?????????????????????????????????????????????Physics.Simulate(Time.fixedDeltaTime)???????????(6packet/second )?

????_20181122115410.gif


5.??

?????????Unity?????????????????????????????????

>????????Physics.Simulate()?????????????????????????????????????????????????????????????????????????

???????????????????????Physics.Simulate()????????????????

????????Unity???????????????????????????????????????????????????????????Bullet Physics For Unity(???Unity?????????????????)???


??? ????by??????
????https://mp.weixin.qq.com/s/qgAncRzisA3H47_PGZGuBg

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-17 23:59

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表