-
大小: 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 < m_BufferedState[i+1].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离线安装包
相关资源
- 第一行代码第二版源代码.rar
- 基于QT的网络音乐播放器
- 最新SSC喜虎完整源码.zip
- 电脑报十年珍藏版(1992-2001)
- Unity3D官方地形包,TerrainAsset.unitypac
- XSS搭建教程以及源码,免费分享给大
- 超高仿京东商城最新版源码(非常好
- 基于H5开发仿蜻蜓FM的app源码
- 学习OpenCV(中文版)pdf文档+源码
- 23种设计模式项目包括源码和ppt
- ArcGIS Server开发指南基于Flex和.Net
- 学习opencv 中文版及源码
- 30天学通C#项目案例开发_源码(全)
- 最新仿百度文库源码仿豆丁文档源码
- Unity3D 坦克射击游戏完整工程文件
- STM32数字示波器源码+数字信号处理教
- 机器学习实战所有源码以及数据集
- 超好用的公路创建插件RoadBuilder.zip
- 树木与草地
- 小说网站源码
- unity3d鸟与家禽动画模型
- MegaFiers_Mesh V3.36
- 房屋销售管理系统源码
- 拾柴项目源码
- .net RBAC通用权限设计与实现完整源码
- 深入浅出Spring Boot 2.x 图书配套源码
- Windows高级调试[书+源码+符号文件
- OpenCPN-4.2.0源码
- onvif协议源码rtsp,rtp,gb28181等等协议
-
ob
jectARX开发教程+源码 张帆
评论
共有 条评论