代码拉取完成,页面将自动刷新
同步操作将从 liyonghelpme/rongYaoDaLuCode 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using System;
using TNet;
using UnityEngine;
[AddComponentMenu("TNet/Sync Rigidbody"), RequireComponent(typeof(Rigidbody))]
public class TNSyncRigidbody : TNBehaviour
{
public bool isImportant;
private Vector3 mLastPos;
private Vector3 mLastRot;
private float mNext;
private Rigidbody mRb;
private Transform mTrans;
private bool mWasSleeping;
public float updatesPerSecond = 10f;
private void Awake()
{
this.mTrans = base.transform;
this.mRb = base.GetComponent<Rigidbody>();
this.mLastPos = this.mTrans.position;
this.mLastRot = this.mTrans.rotation.eulerAngles;
this.UpdateInterval();
}
private void FixedUpdate()
{
if ((this.updatesPerSecond >= 0.001f) && (base.tno.isMine && TNManager.isInChannel))
{
bool flag = this.mRb.IsSleeping();
if (!flag || !this.mWasSleeping)
{
this.mNext -= Time.deltaTime;
if (this.mNext <= 0f)
{
this.UpdateInterval();
Vector3 position = this.mTrans.position;
Vector3 eulerAngles = this.mTrans.rotation.eulerAngles;
if ((this.mWasSleeping || (position != this.mLastPos)) || (eulerAngles != this.mLastRot))
{
this.mLastPos = position;
this.mLastRot = eulerAngles;
if (this.isImportant)
{
object[] objs = new object[] { position, eulerAngles, this.mRb.velocity, this.mRb.angularVelocity };
base.tno.Send((byte) 1, Target.OthersSaved, objs);
}
else
{
object[] objArray2 = new object[] { position, eulerAngles, this.mRb.velocity, this.mRb.angularVelocity };
base.tno.SendQuickly((byte) 1, Target.OthersSaved, objArray2);
}
}
this.mWasSleeping = flag;
}
}
}
}
private void OnCollisionEnter()
{
if (TNManager.isHosting)
{
this.Sync();
}
}
[TNet.RFC(1)]
private void OnSync(Vector3 pos, Vector3 rot, Vector3 vel, Vector3 ang)
{
this.mTrans.position = pos;
this.mTrans.rotation = Quaternion.Euler(rot);
this.mRb.velocity = vel;
this.mRb.angularVelocity = ang;
this.UpdateInterval();
}
public void Sync()
{
if (TNManager.isInChannel)
{
this.UpdateInterval();
this.mWasSleeping = false;
this.mLastPos = this.mTrans.position;
this.mLastRot = this.mTrans.rotation.eulerAngles;
object[] objs = new object[] { this.mLastPos, this.mLastRot, this.mRb.velocity, this.mRb.angularVelocity };
base.tno.Send((byte) 1, Target.OthersSaved, objs);
}
}
private void UpdateInterval()
{
this.mNext = UnityEngine.Random.Range((float) 0.85f, (float) 1.15f) * ((this.updatesPerSecond <= 0f) ? 0f : (1f / this.updatesPerSecond));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。