-
大小: 44.96MB文件類型: .zip金幣: 1下載: 0 次發布日期: 2023-07-24
- 語言: 其他
- 標簽: Unity3D??StarTrooper??源碼??
資源簡介
Unity3D StarTrooper多人游戲源碼(可運行)
代碼片段和文件信息
using?UnityEngine;
using?System.Collections;
public?class?NetworkRigidbody?:?MonoBehaviour?{
public?double?m_InterpolationBackTime?=?0.1;
public?double?m_ExtrapolationLimit?=?0.5;
internal?struct??State
{
internal?double?timestamp;
internal?Vector3?pos;
internal?Vector3?velocity;
internal?Quaternion?rot;
internal?Vector3?angularVelocity;
}
//?We?store?twenty?states?with?“playback“?information
State[]?m_BufferedState?=?new?State[20];
//?Keep?track?of?what?slots?are?used
int?m_TimestampCount;
void?OnSerializeNetworkView(BitStream?stream?NetworkMessageInfo?info)?{
//?Send?data?to?server
if?(stream.isWriting)
{
Vector3?pos?=?rigidbody.position;
Quaternion?rot?=?rigidbody.rotation;
Vector3?velocity?=?rigidbody.velocity;
Vector3?angularVelocity?=?rigidbody.angularVelocity;
stream.Serialize(ref?pos);
stream.Serialize(ref?velocity);
stream.Serialize(ref?rot);
stream.Serialize(ref?angularVelocity);
}
//?Read?data?from?remote?client
else
{
Vector3?pos?=?Vector3.zero;
Vector3?velocity?=?Vector3.zero;
Quaternion?rot?=?Quaternion.identity;
Vector3?angularVelocity?=?Vector3.zero;
stream.Serialize(ref?pos);
stream.Serialize(ref?velocity);
stream.Serialize(ref?rot);
stream.Serialize(ref?angularVelocity);
//?Shift?the?buffer?sideways?deleting?state?20
for?(int?i=m_BufferedState.Length-1;i>=1;i--)
{
m_BufferedState[i]?=?m_BufferedState[i-1];
}
//?Record?current?state?in?slot?0
State?state;
state.timestamp?=?info.timestamp;
state.pos?=?pos;
state.velocity?=?velocity;
state.rot?=?rot;
state.angularVelocity?=?angularVelocity;
m_BufferedState[0]?=?state;
//?Update?used?slot?count?however?never?exceed?the?buffer?size
//?Slots?aren‘t?actually?freed?so?this?just?makes?sure?the?buffer?is
//?filled?up?and?that?uninitalized?slots?aren‘t?used.
m_TimestampCount?=?Mathf.Min(m_TimestampCount?+?1?m_BufferedState.Length);
//?Check?if?states?are?in?order?if?it?is?inconsistent?you?could?reshuffel?or?
//?drop?the?out-of-order?state.?Nothing?is?done?here
for?(int?i=0;i {
if?(m_BufferedState[i].timestamp? Debug.Log(“State?inconsistent“);
}
}
}
//?We?have?a?window?of?interpolationBackTime?where?we?basically?play?
//?By?having?interpolationBackTime?the?average?ping?you?will?usually?use?interpolation.
//?And?only?if?no?more?data?arrives?we?will?use?extra?polation
void?Update?()?{
//?This?is?the?target?playback?time?of?the?rigid?body
double?interpolationTime?=?Network.time?-?m_InterpolationBackTime;
//?Use?interpolation?if?the?target?playback?time?is?present?in?the?buffer
if?(m_BufferedState[0].timestamp?>?interpolationTime)
{
//?Go?through?buffer?and?find?correct?state?to?play?back
for?(int?i=0;i {
if?(m_BufferedState[i].timestamp?<=?interpolationTime?||?i?==?m_TimestampCount-1)
{
/
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2010-03-22?21:25??Assets\
?????目錄???????????0??2010-03-22?21:33??Assets\_ob
?????文件??????171120??2009-01-13?16:11??Assets\_ob
?????目錄???????????0??2010-03-22?22:27??__MACOSX\
?????目錄???????????0??2010-03-22?22:27??__MACOSX\Assets\
?????目錄???????????0??2010-03-22?22:27??__MACOSX\Assets\_ob
?????文件?????????193??2009-01-13?16:11??__MACOSX\Assets\_ob
?????文件??????553200??2009-01-13?16:11??Assets\_ob
?????文件?????????193??2009-01-13?16:11??__MACOSX\Assets\_ob
?????文件???????71104??2009-01-13?16:11??Assets\_ob
?????文件?????????193??2009-01-13?16:11??__MACOSX\Assets\_ob
?????目錄???????????0??2010-03-22?20:37??Assets\_ob
?????文件????????3413??2009-11-18?13:17??Assets\_ob
?????目錄???????????0??2010-03-22?22:27??__MACOSX\Assets\_ob
?????文件?????????193??2009-11-18?13:17??__MACOSX\Assets\_ob
?????文件????????3269??2009-11-18?13:17??Assets\_ob
?????文件?????????193??2009-11-18?13:17??__MACOSX\Assets\_ob
?????文件????????3413??2009-11-18?13:17??Assets\_ob
?????文件?????????193??2009-11-18?13:17??__MACOSX\Assets\_ob
?????文件????????3269??2009-11-18?13:17??Assets\_ob
?????文件?????????193??2009-11-18?13:17??__MACOSX\Assets\_ob
?????文件????????3413??2009-11-18?13:17??Assets\_ob
?????文件?????????193??2009-11-18?13:17??__MACOSX\Assets\_ob
?????文件????????3413??2009-11-18?13:17??Assets\_ob
?????文件?????????193??2009-11-18?13:17??__MACOSX\Assets\_ob
?????文件????????3696??2009-11-18?13:17??Assets\_ob
?????文件?????????193??2009-11-18?13:17??__MACOSX\Assets\_ob
?????文件????????3502??2009-11-18?13:17??Assets\_ob
?????文件?????????193??2009-11-18?13:17??__MACOSX\Assets\_ob
?????文件????????3436??2009-11-18?13:17??Assets\_ob
?????文件?????????193??2009-11-18?13:17??__MACOSX\Assets\_ob
............此處省略933個文件信息
- 上一篇:海康平臺Http接口幫助文檔+
- 下一篇:MinGW64離線安裝包
評論
共有 條評論