|
|
?/???-27
????????????????????????????????Unity???????????????????????????????????????-27?????????????????????
???Unity???????
1.?Unity?????
???Unity????????GameObject??Network?????????????????????????????C#??????????Unity??????????UnityEngine.Networking ?????
1.1 ?????
???????Server????
??????????????????????????????true????????????????????????????????????????,?????????
1.2 ?????
???????????????Server??????????
?????Connect??????????????????????????OnClientConnected?????????OnConnectedServer???
?????????????????NetworkMessage??NetworkConnection?????????? ?????????????????????/??????????
1.3 ???
????Unity??????????????????????????????????????????
?????????????????????????
????????
?????????Unity?????????
?????????????
??????Unity????????????????????????????????????????????????????????
1.???????(CustomMsgTypes)
??????????????????????????RegisterHandler?????????????short????????????NetworkMessageDelegate???????????????????????MsgType????????????????
????????????UnityEngine.Networking????MsgType?????????????Unity???MsgType??????CustomMsgTypes?????????????
2.???????
????????????????????????????????UnityEngine.Networking???????Message????MessageBase???????? Deserialize ? Serialize ?????????????????????????
?????? Serialize ???msg?????????????Deserialize??????????????????
3. ???????
????????????????????????????????????????????NetworkConnection.Send???????????
????????????????Deserialize??????????
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?
?????????????????????????????????????
????????????????????????????
?????????????????????????????????????
????????????????????????????????????????????????????
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???
???????????FixedUpdate??????????????????????(Simulate)???????
2.????? + ??????? = ??????
???????????????????????????????????????????????????????????????????????????????????????????????????????????(Command)?
Simulate????????????????CommandInput????????CommandResult?
CollectCommandInput?ExecuteCommand?????????????????????
???????,???Command?????result???????????Command????????????????sequence(????)?????????????
???????
3.??
???????Command?????????Simulate?????????????????????Command?
??????????????
?????????????????????????????????????????????????????????????????????????
1.?????????????(Entity)??
?????????????(SendRate)????????10???????????60??????????????????6????????????????Entity??????????
??????
????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)?
?????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????
?????
????????,?????????????????????????????????????????????????????A?????B???????????(????)??A???????B???????????????????B????????????????????????B????????????????????????????????????
???????????????????????????????
?delay = 10(??????10????)????????????????????????????
?????????????????????????????(???????,????????)?
3.??
?????????????????????????????????????????????????????????????????????
>???????????????????2????3(?????????1)????
????????????????????????????????????????
?????????????????????????????????????????????????????
???????????????????????????
??????????
?????????????????????????????????????????????????????????????????
1.???????????????????
?????(????)???????????????????????????
????????FPS?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
2.???????????????????????????
??????????????????????????(CommandInput)??????????????????????????????
?????????????????????????????????????????????????????????(ClientSendRate)??????????????????????????????
??????????60?/??????????60?Command???????ClientSendRate???????????????Command??????
????????????????????????????????????
3.????????????????????????????????
????????????????????????????????
???????????????????????????commandQueue??(??Command????Input?Result)?????????????????????Result?????????
4.????????????????
??????????????????????(commandQueue)?????????????????????????????????????????????????????????????????????????????????????????Command?????sequence???????????
?????????????(commandQueue)???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????(?????????)???????
??????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????
?????????????????OnSimulateBefore()???????????????????????????????????????????????????????????????????????????????
??????????
5.??
???????????????????????????? + N??? = ????????????????????????????????????
????????????????????????????????????????????????????????????????
???????????
???GDC2018????????????????(??????)???Rocket League?(????RT)????????????????????????Unreal Engine 3?????????Bullet???????????????????????????????????????Unity?????????????????????????
1.??????,??????
????????Cube?????Rigidbody??????????????????????
??????W?S?A?D????????Cube???????????
?????????????????????
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)???????.???????????????????
3.??????????????
?????,?????????position?rotation????rigidbody?velocity?angularVelocity???
??????????????????????????(6packet/second )?
4.?????????????????????
????????????????????????Physics.Simulate(Time.fixedDeltaTime)?????????????????????????????????????????????Physics.Simulate(Time.fixedDeltaTime)???????????(6packet/second )?
5.??
?????????Unity?????????????????????????????????
>????????Physics.Simulate()?????????????????????????????????????????????????????????????????????????
???????????????????????Physics.Simulate()????????????????
????????Unity???????????????????????????????????????????????????????????Bullet Physics For Unity(???Unity?????????????????)???
??? ????by??????
????https://mp.weixin.qq.com/s/qgAncRzisA3H47_PGZGuBg
|
|