| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| . | public class ZSyncTransform : MonoBehaviour |
| public class ZSyncTransform : MonoBehaviour, IMonoUpdater |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_projectile = base.GetComponent<Projectile>(); |
| this.m_projectile = base.GetComponent<Projectile>(); |
| this.m_character = base.GetComponent<Character>(); |
| this.m_character = base.GetComponent<Character>(); |
| if (this.m_nview.GetZDO() == null) |
| if (this.m_nview.GetZDO() == null) |
| { |
| { |
| base.enabled = false; |
| base.enabled = false; |
| return; |
| return; |
| } |
| } |
| if (this.m_body) |
| if (this.m_body) |
| { |
| { |
| this.m_isKinematicBody = this.m_body.isKinematic; |
| this.m_isKinematicBody = this.m_body.isKinematic; |
| this.m_useGravity = this.m_body.useGravity; |
| this.m_useGravity = this.m_body.useGravity; |
| } |
| } |
| this.m_wasOwner = this.m_nview.GetZDO().IsOwner(); |
| this.m_wasOwner = this.m_nview.GetZDO().IsOwner(); |
| } |
| } |
| |
| |
| private void OnEnable() |
| private void OnEnable() |
| { |
| { |
| ZSyncTransform.Instances.Add(this); |
| ZSyncTransform.Instances.Add(this); |
| } |
| } |
| |
| |
| private void OnDisable() |
| private void OnDisable() |
| { |
| { |
| ZSyncTransform.Instances.Remove(this); |
| ZSyncTransform.Instances.Remove(this); |
| } |
| } |
| |
| |
| private Vector3 GetVelocity() |
| private Vector3 GetVelocity() |
| { |
| { |
| if (this.m_body != null) |
| if (this.m_body != null) |
| { |
| { |
| return this.m_body.velocity; |
| return this.m_body.velocity; |
| } |
| } |
| if (this.m_projectile != null) |
| if (this.m_projectile != null) |
| { |
| { |
| return this.m_projectile.GetVelocity(); |
| return this.m_projectile.GetVelocity(); |
| } |
| } |
| return Vector3.zero; |
| return Vector3.zero; |
| } |
| } |
| |
| |
| private Vector3 GetPosition() |
| private Vector3 GetPosition() |
| { |
| { |
| if (!this.m_body) |
| if (!this.m_body) |
| { |
| { |
| return base.transform.position; |
| return base.transform.position; |
| } |
| } |
| return this.m_body.position; |
| return this.m_body.position; |
| } |
| } |
| |
| |
| private void OwnerSync() |
| private void OwnerSync() |
| { |
| { |
| ZDO zdo = this.m_nview.GetZDO(); |
| ZDO zdo = this.m_nview.GetZDO(); |
| bool flag = zdo.IsOwner(); |
| bool flag = zdo.IsOwner(); |
| bool flag2 = !this.m_wasOwner && flag; |
| bool flag2 = !this.m_wasOwner && flag; |
| this.m_wasOwner = flag; |
| this.m_wasOwner = flag; |
| if (!flag) |
| if (!flag) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (flag2) |
| if (flag2) |
| { |
| { |
| bool flag3 = false; |
| bool flag3 = false; |
| if (this.m_syncPosition) |
| if (this.m_syncPosition) |
| { |
| { |
| base.transform.position = zdo.GetPosition(); |
| base.transform.position = zdo.GetPosition(); |
| flag3 = true; |
| flag3 = true; |
| } |
| } |
| if (this.m_syncRotation) |
| if (this.m_syncRotation) |
| { |
| { |
| base.transform.rotation = zdo.GetRotation(); |
| base.transform.rotation = zdo.GetRotation(); |
| flag3 = true; |
| flag3 = true; |
| } |
| } |
| if (this.m_syncBodyVelocity && this.m_body) |
| if (this.m_syncBodyVelocity && this.m_body) |
| { |
| { |
| this.m_body.velocity = zdo.GetVec3(ZDOVars.s_bodyVelHash, Vector3.zero); |
| this.m_body.velocity = zdo.GetVec3(ZDOVars.s_bodyVelHash, Vector3.zero); |
| this.m_body.angularVelocity = zdo.GetVec3(ZDOVars.s_bodyAVelHash, Vector3.zero); |
| this.m_body.angularVelocity = zdo.GetVec3(ZDOVars.s_bodyAVelHash, Vector3.zero); |
| } |
| } |
| if (flag3 && this.m_body) |
| if (flag3 && this.m_body) |
| { |
| { |
| Physics.SyncTransforms(); |
| Physics.SyncTransforms(); |
| } |
| } |
| } |
| } |
| if (base.transform.position.y < -5000f) |
| if (base.transform.position.y < -5000f) |
| { |
| { |
| if (this.m_body) |
| if (this.m_body) |
| { |
| { |
| this.m_body.velocity = Vector3.zero; |
| this.m_body.velocity = Vector3.zero; |
| } |
| } |
| ZLog.Log("Object fell out of world:" + base.gameObject.name); |
| ZLog.Log("Object fell out of world:" + base.gameObject.name); |
| float groundHeight = ZoneSystem.instance.GetGroundHeight(base.transform.position); |
| float groundHeight = ZoneSystem.instance.GetGroundHeight(base.transform.position); |
| Vector3 position = base.transform.position; |
| Vector3 position = base.transform.position; |
| position.y = groundHeight + 1f; |
| position.y = groundHeight + 1f; |
| base.transform.position = position; |
| base.transform.position = position; |
| if (this.m_body) |
| if (this.m_body) |
| { |
| { |
| Physics.SyncTransforms(); |
| Physics.SyncTransforms(); |
| } |
| } |
| return; |
| return; |
| } |
| } |
| if (this.m_syncPosition) |
| if (this.m_syncPosition) |
| { |
| { |
| zdo.SetPosition(this.GetPosition()); |
| zdo.SetPosition(this.GetPosition()); |
| zdo.Set(ZDOVars.s_velHash, this.GetVelocity()); |
| zdo.Set(ZDOVars.s_velHash, this.GetVelocity()); |
| if (this.m_characterParentSync) |
| if (this.m_characterParentSync) |
| { |
| { |
| if (this.GetRelativePosition(zdo, out this.m_tempParent, out this.m_tempAttachJoint, out this.m_tempRelativePos, out this.m_tempRelativeRot, out this.m_tempRelativeVel)) |
| if (this.GetRelativePosition(zdo, out this.m_tempParent, out this.m_tempAttachJoint, out this.m_tempRelativePos, out this.m_tempRelativeRot, out this.m_tempRelativeVel)) |
| { |
| { |
| zdo.SetConnection(ZDOExtraData.ConnectionType.SyncTransform, this.m_tempParent); |
| zdo.SetConnection(ZDOExtraData.ConnectionType.SyncTransform, this.m_tempParent); |
| zdo.Set(ZDOVars.s_attachJointHash, this.m_tempAttachJoint); |
| zdo.Set(ZDOVars.s_attachJointHash, this.m_tempAttachJoint); |
| zdo.Set(ZDOVars.s_relPosHash, this.m_tempRelativePos); |
| zdo.Set(ZDOVars.s_relPosHash, this.m_tempRelativePos); |
| zdo.Set(ZDOVars.s_relRotHash, this.m_tempRelativeRot); |
| zdo.Set(ZDOVars.s_relRotHash, this.m_tempRelativeRot); |
| zdo.Set(ZDOVars.s_velHash, this.m_tempRelativeVel); |
| zdo.Set(ZDOVars.s_velHash, this.m_tempRelativeVel); |
| } |
| } |
| else |
| else |
| { |
| { |
| zdo.UpdateConnection(ZDOExtraData.ConnectionType.SyncTransform, ZDOID.None); |
| zdo.UpdateConnection(ZDOExtraData.ConnectionType.SyncTransform, ZDOID.None); |
| zdo.Set(ZDOVars.s_attachJointHash, ""); |
| zdo.Set(ZDOVars.s_attachJointHash, ""); |
| } |
| } |
| } |
| } |
| } |
| } |
| if (this.m_syncRotation && base.transform.hasChanged) |
| if (this.m_syncRotation && base.transform.hasChanged) |
| { |
| { |
| Quaternion quaternion = (this.m_body ? this.m_body.rotation : base.transform.rotation); |
| Quaternion quaternion = (this.m_body ? this.m_body.rotation : base.transform.rotation); |
| zdo.SetRotation(quaternion); |
| zdo.SetRotation(quaternion); |
| } |
| } |
| if (this.m_syncScale && base.transform.hasChanged) |
| if (this.m_syncScale && base.transform.hasChanged) |
| { |
| { |
| if (Mathf.Approximately(base.transform.localScale.x, base.transform.localScale.y) && Mathf.Approximately(base.transform.localScale.x, base.transform.localScale.z)) |
| if (Mathf.Approximately(base.transform.localScale.x, base.transform.localScale.y) && Mathf.Approximately(base.transform.localScale.x, base.transform.localScale.z)) |
| { |
| { |
| zdo.RemoveVec3(ZDOVars.s_scaleHash); |
| zdo.RemoveVec3(ZDOVars.s_scaleHash); |
| zdo.Set(ZDOVars.s_scaleScalarHash, base.transform.localScale.x); |
| zdo.Set(ZDOVars.s_scaleScalarHash, base.transform.localScale.x); |
| } |
| } |
| else |
| else |
| { |
| { |
| zdo.RemoveFloat(ZDOVars.s_scaleScalarHash); |
| zdo.RemoveFloat(ZDOVars.s_scaleScalarHash); |
| zdo.Set(ZDOVars.s_scaleHash, base.transform.localScale); |
| zdo.Set(ZDOVars.s_scaleHash, base.transform.localScale); |
| } |
| } |
| } |
| } |
| if (this.m_body) |
| if (this.m_body) |
| { |
| { |
| if (this.m_syncBodyVelocity) |
| if (this.m_syncBodyVelocity) |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_bodyVelHash, this.m_body.velocity); |
| this.m_nview.GetZDO().Set(ZDOVars.s_bodyVelHash, this.m_body.velocity); |
| this.m_nview.GetZDO().Set(ZDOVars.s_bodyAVelHash, this.m_body.angularVelocity); |
| this.m_nview.GetZDO().Set(ZDOVars.s_bodyAVelHash, this.m_body.angularVelocity); |
| } |
| } |
| this.m_body.useGravity = this.m_useGravity; |
| this.m_body.useGravity = this.m_useGravity; |
| } |
| } |
| base.transform.hasChanged = false; |
| base.transform.hasChanged = false; |
| } |
| } |
| |
| |
| private bool GetRelativePosition(ZDO zdo, out ZDOID parent, out string attachJoint, out Vector3 relativePos, out Quaternion relativeRot, out Vector3 relativeVel) |
| private bool GetRelativePosition(ZDO zdo, out ZDOID parent, out string attachJoint, out Vector3 relativePos, out Quaternion relativeRot, out Vector3 relativeVel) |
| { |
| { |
| if (this.m_character) |
| if (this.m_character) |
| { |
| { |
| return this.m_character.GetRelativePosition(out parent, out attachJoint, out relativePos, out relativeRot, out relativeVel); |
| return this.m_character.GetRelativePosition(out parent, out attachJoint, out relativePos, out relativeRot, out relativeVel); |
| } |
| } |
| if (base.transform.parent) |
| if (base.transform.parent) |
| { |
| { |
| ZNetView znetView = (base.transform.parent ? base.transform.parent.GetComponent<ZNetView>() : null); |
| ZNetView znetView = (base.transform.parent ? base.transform.parent.GetComponent<ZNetView>() : null); |
| if (znetView && znetView.IsValid()) |
| if (znetView && znetView.IsValid()) |
| { |
| { |
| parent = znetView.GetZDO().m_uid; |
| parent = znetView.GetZDO().m_uid; |
| attachJoint = ""; |
| attachJoint = ""; |
| relativePos = base.transform.localPosition; |
| relativePos = base.transform.localPosition; |
| relativeRot = base.transform.localRotation; |
| relativeRot = base.transform.localRotation; |
| relativeVel = Vector3.zero; |
| relativeVel = Vector3.zero; |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| parent = ZDOID.None; |
| parent = ZDOID.None; |
| attachJoint = ""; |
| attachJoint = ""; |
| relativePos = Vector3.zero; |
| relativePos = Vector3.zero; |
| relativeRot = Quaternion.identity; |
| relativeRot = Quaternion.identity; |
| relativeVel = Vector3.zero; |
| relativeVel = Vector3.zero; |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private void SyncPosition(ZDO zdo, float dt, out bool usedLocalRotation) |
| private void SyncPosition(ZDO zdo, float dt, out bool usedLocalRotation) |
| { |
| { |
| usedLocalRotation = false; |
| usedLocalRotation = false; |
| if (this.m_characterParentSync && zdo.HasOwner()) |
| if (this.m_characterParentSync && zdo.HasOwner()) |
| { |
| { |
| ZDOID connectionZDOID = zdo.GetConnectionZDOID(ZDOExtraData.ConnectionType.SyncTransform); |
| ZDOID connectionZDOID = zdo.GetConnectionZDOID(ZDOExtraData.ConnectionType.SyncTransform); |
| if (!connectionZDOID.IsNone()) |
| if (!connectionZDOID.IsNone()) |
| { |
| { |
| GameObject gameObject = ZNetScene.instance.FindInstance(connectionZDOID); |
| GameObject gameObject = ZNetScene.instance.FindInstance(connectionZDOID); |
| if (gameObject) |
| if (gameObject) |
| { |
| { |
| ZSyncTransform component = gameObject.GetComponent<ZSyncTransform>(); |
| ZSyncTransform component = gameObject.GetComponent<ZSyncTransform>(); |
| if (component) |
| if (component) |
| { |
| { |
| component.ClientSync(dt); |
| component.ClientSync(dt); |
| } |
| } |
| string @string = zdo.GetString(ZDOVars.s_attachJointHash, ""); |
| string @string = zdo.GetString(ZDOVars.s_attachJointHash, ""); |
| Vector3 vector = zdo.GetVec3(ZDOVars.s_relPosHash, Vector3.zero); |
| Vector3 vector = zdo.GetVec3(ZDOVars.s_relPosHash, Vector3.zero); |
| Quaternion quaternion = zdo.GetQuaternion(ZDOVars.s_relRotHash, Quaternion.identity); |
| Quaternion quaternion = zdo.GetQuaternion(ZDOVars.s_relRotHash, Quaternion.identity); |
| Vector3 vec = zdo.GetVec3(ZDOVars.s_velHash, Vector3.zero); |
| Vector3 vec = zdo.GetVec3(ZDOVars.s_velHash, Vector3.zero); |
| bool flag = false; |
| bool flag = false; |
| if (zdo.DataRevision != this.m_posRevision) |
| if (zdo.DataRevision != this.m_posRevision) |
| { |
| { |
| this.m_posRevision = zdo.DataRevision; |
| this.m_posRevision = zdo.DataRevision; |
| this.m_targetPosTimer = 0f; |
| this.m_targetPosTimer = 0f; |
| } |
| } |
| if (@string.Length > 0) |
| if (@string.Length > 0) |
| { |
| { |
| Transform transform = Utils.FindChild(gameObject.transform, @string, Utils.IterativeSearchType.DepthFirst); |
| Transform transform = Utils.FindChild(gameObject.transform, @string, Utils.IterativeSearchType.DepthFirst); |
| if (transform) |
| if (transform) |
| { |
| { |
| base.transform.position = transform.position; |
| base.transform.position = transform.position; |
| flag = true; |
| flag = true; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_targetPosTimer += dt; |
| this.m_targetPosTimer += dt; |
| this.m_targetPosTimer = Mathf.Min(this.m_targetPosTimer, 2f); |
| this.m_targetPosTimer = Mathf.Min(this.m_targetPosTimer, 2f); |
| vector += vec * this.m_targetPosTimer; |
| vector += vec * this.m_targetPosTimer; |
| if (!this.m_haveTempRelPos) |
| if (!this.m_haveTempRelPos) |
| { |
| { |
| this.m_haveTempRelPos = true; |
| this.m_haveTempRelPos = true; |
| this.m_tempRelPos = vector; |
| this.m_tempRelPos = vector; |
| } |
| } |
| if (Vector3.Distance(this.m_tempRelPos, vector) > 0.001f) |
| if (Vector3.Distance(this.m_tempRelPos, vector) > 0.001f) |
| { |
| { |
| this.m_tempRelPos = Vector3.Lerp(this.m_tempRelPos, vector, 0.2f); |
| this.m_tempRelPos = Vector3.Lerp(this.m_tempRelPos, vector, 0.2f); |
| vector = this.m_tempRelPos; |
| vector = this.m_tempRelPos; |
| } |
| } |
| Vector3 vector2 = gameObject.transform.TransformPoint(vector); |
| Vector3 vector2 = gameObject.transform.TransformPoint(vector); |
| if (Vector3.Distance(base.transform.position, vector2) > 0.001f) |
| if (Vector3.Distance(base.transform.position, vector2) > 0.001f) |
| { |
| { |
| base.transform.position = vector2; |
| base.transform.position = vector2; |
| flag = true; |
| flag = true; |
| } |
| } |
| } |
| } |
| Quaternion quaternion2 = Quaternion.Inverse(gameObject.transform.rotation) * base.transform.rotation; |
| Quaternion quaternion2 = Quaternion.Inverse(gameObject.transform.rotation) * base.transform.rotation; |
| if (Quaternion.Angle(quaternion2, quaternion) > 0.001f) |
| if (Quaternion.Angle(quaternion2, quaternion) > 0.001f) |
| { |
| { |
| Quaternion quaternion3 = Quaternion.Slerp(quaternion2, quaternion, 0.5f); |
| Quaternion quaternion3 = Quaternion.Slerp(quaternion2, quaternion, 0.5f); |
| base.transform.rotation = gameObject.transform.rotation * quaternion3; |
| base.transform.rotation = gameObject.transform.rotation * quaternion3; |
| flag = true; |
| flag = true; |
| } |
| } |
| usedLocalRotation = true; |
| usedLocalRotation = true; |
| if (flag && this.m_body) |
| if (flag && this.m_body) |
| { |
| { |
| Physics.SyncTransforms(); |
| Physics.SyncTransforms(); |
| } |
| } |
| return; |
| return; |
| } |
| } |
| } |
| } |
| } |
| } |
| this.m_haveTempRelPos = false; |
| this.m_haveTempRelPos = false; |
| Vector3 vector3 = zdo.GetPosition(); |
| Vector3 vector3 = zdo.GetPosition(); |
| if (zdo.DataRevision != this.m_posRevision) |
| if (zdo.DataRevision != this.m_posRevision) |
| { |
| { |
| this.m_posRevision = zdo.DataRevision; |
| this.m_posRevision = zdo.DataRevision; |
| this.m_targetPosTimer = 0f; |
| this.m_targetPosTimer = 0f; |
| } |
| } |
| if (zdo.HasOwner()) |
| if (zdo.HasOwner()) |
| { |
| { |
| this.m_targetPosTimer += dt; |
| this.m_targetPosTimer += dt; |
| this.m_targetPosTimer = Mathf.Min(this.m_targetPosTimer, 2f); |
| this.m_targetPosTimer = Mathf.Min(this.m_targetPosTimer, 2f); |
| Vector3 vec2 = zdo.GetVec3(ZDOVars.s_velHash, Vector3.zero); |
| Vector3 vec2 = zdo.GetVec3(ZDOVars.s_velHash, Vector3.zero); |
| vector3 += vec2 * this.m_targetPosTimer; |
| vector3 += vec2 * this.m_targetPosTimer; |
| } |
| } |
| float num = Vector3.Distance(base.transform.position, vector3); |
| float num = Vector3.Distance(base.transform.position, vector3); |
| if (num > 0.001f) |
| if (num > 0.001f) |
| { |
| { |
| base.transform.position = ((num < 5f) ? Vector3.Lerp(base.transform.position, vector3, 0.2f) : vector3); |
| base.transform.position = ((num < 5f) ? Vector3.Lerp(base.transform.position, vector3, 0.2f) : vector3); |
| if (this.m_body) |
| if (this.m_body) |
| { |
| { |
| Physics.SyncTransforms(); |
| Physics.SyncTransforms(); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void ClientSync(float dt) |
| private void ClientSync(float dt) |
| { |
| { |
| ZDO zdo = this.m_nview.GetZDO(); |
| ZDO zdo = this.m_nview.GetZDO(); |
| if (zdo.IsOwner()) |
| if (zdo.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| int frameCount = Time.frameCount; |
| int frameCount = Time.frameCount; |
| if (this.m_lastUpdateFrame == frameCount) |
| if (this.m_lastUpdateFrame == frameCount) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_lastUpdateFrame = frameCount; |
| this.m_lastUpdateFrame = frameCount; |
| if (this.m_isKinematicBody) |
| if (this.m_isKinematicBody) |
| { |
| { |
| if (this.m_syncPosition) |
| if (this.m_syncPosition) |
| { |
| { |
| Vector3 vector = zdo.GetPosition(); |
| Vector3 vector = zdo.GetPosition(); |
| if (Vector3.Distance(this.m_body.position, vector) > 5f) |
| if (Vector3.Distance(this.m_body.position, vector) > 5f) |
| { |
| { |
| this.m_body.position = vector; |
| this.m_body.position = vector; |
| } |
| } |
| else |
| else |
| { |
| { |
| if (Vector3.Distance(this.m_body.position, vector) > 0.01f) |
| if (Vector3.Distance(this.m_body.position, vector) > 0.01f) |
| { |
| { |
| vector = Vector3.Lerp(this.m_body.position, vector, 0.2f); |
| vector = Vector3.Lerp(this.m_body.position, vector, 0.2f); |
| } |
| } |
| this.m_body.MovePosition(vector); |
| this.m_body.MovePosition(vector); |
| } |
| } |
| } |
| } |
| if (this.m_syncRotation) |
| if (this.m_syncRotation) |
| { |
| { |
| Quaternion rotation = zdo.GetRotation(); |
| Quaternion rotation = zdo.GetRotation(); |
| if (Quaternion.Angle(this.m_body.rotation, rotation) > 45f) |
| if (Quaternion.Angle(this.m_body.rotation, rotation) > 45f) |
| { |
| { |
| this.m_body.rotation = rotation; |
| this.m_body.rotation = rotation; |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_body.MoveRotation(rotation); |
| this.m_body.MoveRotation(rotation); |
| } |
| } |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| bool flag = false; |
| bool flag = false; |
| if (this.m_syncPosition) |
| if (this.m_syncPosition) |
| { |
| { |
| this.SyncPosition(zdo, dt, out flag); |
| this.SyncPosition(zdo, dt, out flag); |
| } |
| } |
| if (this.m_syncRotation && !flag) |
| if (this.m_syncRotation && !flag) |
| { |
| { |
| Quaternion rotation2 = zdo.GetRotation(); |
| Quaternion rotation2 = zdo.GetRotation(); |
| if (Quaternion.Angle(base.transform.rotation, rotation2) > 0.001f) |
| if (Quaternion.Angle(base.transform.rotation, rotation2) > 0.001f) |
| { |
| { |
| base.transform.rotation = Quaternion.Slerp(base.transform.rotation, rotation2, 0.5f); |
| base.transform.rotation = Quaternion.Slerp(base.transform.rotation, rotation2, 0.5f); |
| } |
| } |
| } |
| } |
| if (this.m_body) |
| if (this.m_body) |
| { |
| { |
| this.m_body.useGravity = false; |
| this.m_body.useGravity = false; |
| if (this.m_syncBodyVelocity && this.m_nview.HasOwner()) |
| if (this.m_syncBodyVelocity && this.m_nview.HasOwner()) |
| { |
| { |
| Vector3 vec = zdo.GetVec3(ZDOVars.s_bodyVelHash, Vector3.zero); |
| Vector3 vec = zdo.GetVec3(ZDOVars.s_bodyVelHash, Vector3.zero); |
| Vector3 vec2 = zdo.GetVec3(ZDOVars.s_bodyAVelHash, Vector3.zero); |
| Vector3 vec2 = zdo.GetVec3(ZDOVars.s_bodyAVelHash, Vector3.zero); |
| if (vec.magnitude > 0.01f || vec2.magnitude > 0.01f) |
| if (vec.magnitude > 0.01f || vec2.magnitude > 0.01f) |
| { |
| { |
| this.m_body.velocity = vec; |
| this.m_body.velocity = vec; |
| this.m_body.angularVelocity = vec2; |
| this.m_body.angularVelocity = vec2; |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_body.Sleep(); |
| this.m_body.Sleep(); |
| } |
| } |
| } |
| } |
| else if (!this.m_body.IsSleeping()) |
| else if (!this.m_body.IsSleeping()) |
| { |
| { |
| this.m_body.velocity = Vector3.zero; |
| this.m_body.velocity = Vector3.zero; |
| this.m_body.angularVelocity = Vector3.zero; |
| this.m_body.angularVelocity = Vector3.zero; |
| this.m_body.Sleep(); |
| this.m_body.Sleep(); |
| } |
| } |
| } |
| } |
| } |
| } |
| if (this.m_syncScale) |
| if (this.m_syncScale) |
| { |
| { |
| Vector3 vec3 = zdo.GetVec3(ZDOVars.s_scaleHash, Vector3.zero); |
| Vector3 vec3 = zdo.GetVec3(ZDOVars.s_scaleHash, Vector3.zero); |
| if (vec3 != Vector3.zero) |
| if (vec3 != Vector3.zero) |
| { |
| { |
| base.transform.localScale = vec3; |
| base.transform.localScale = vec3; |
| return; |
| return; |
| } |
| } |
| float @float = zdo.GetFloat(ZDOVars.s_scaleScalarHash, base.transform.localScale.x); |
| float @float = zdo.GetFloat(ZDOVars.s_scaleScalarHash, base.transform.localScale.x); |
| if (!base.transform.localScale.x.Equals(@float)) |
| if (!base.transform.localScale.x.Equals(@float)) |
| { |
| { |
| base.transform.localScale = new Vector3(@float, @float, @float); |
| base.transform.localScale = new Vector3(@float, @float, @float); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public void CustomFixedUpdate(float fixedDeltaTime) |
| public void CustomFixedUpdate(float fixedDeltaTime) |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.ClientSync(fixedDeltaTime); |
| this.ClientSync(fixedDeltaTime); |
| } |
| } |
| |
| |
| . | public void CustomLateUpdate() |
| public void CustomLateUpdate(float deltaTime) |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.OwnerSync(); |
| this.OwnerSync(); |
| } |
| } |
| |
| |
| public void SyncNow() |
| public void SyncNow() |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.OwnerSync(); |
| this.OwnerSync(); |
| } |
| } |
| |
| |
| . | public static List<ZSyncTransform> Instances { get; } = new List<ZSyncTransform>(); |
| public static List<IMonoUpdater> Instances { get; } = new List<IMonoUpdater>(); |
| |
| |
| public bool m_syncPosition = true; |
| public bool m_syncPosition = true; |
| |
| |
| public bool m_syncRotation = true; |
| public bool m_syncRotation = true; |
| |
| |
| public bool m_syncScale; |
| public bool m_syncScale; |
| |
| |
| public bool m_syncBodyVelocity; |
| public bool m_syncBodyVelocity; |
| |
| |
| public bool m_characterParentSync; |
| public bool m_characterParentSync; |
| |
| |
| private const float m_smoothnessPos = 0.2f; |
| private const float m_smoothnessPos = 0.2f; |
| |
| |
| private const float m_smoothnessRot = 0.5f; |
| private const float m_smoothnessRot = 0.5f; |
| |
| |
| private bool m_isKinematicBody; |
| private bool m_isKinematicBody; |
| |
| |
| private bool m_useGravity = true; |
| private bool m_useGravity = true; |
| |
| |
| private Vector3 m_tempRelPos; |
| private Vector3 m_tempRelPos; |
| |
| |
| private bool m_haveTempRelPos; |
| private bool m_haveTempRelPos; |
| |
| |
| private float m_targetPosTimer; |
| private float m_targetPosTimer; |
| |
| |
| private uint m_posRevision = uint.MaxValue; |
| private uint m_posRevision = uint.MaxValue; |
| |
| |
| private int m_lastUpdateFrame = -1; |
| private int m_lastUpdateFrame = -1; |
| |
| |
| private bool m_wasOwner; |
| private bool m_wasOwner; |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private Rigidbody m_body; |
| private Rigidbody m_body; |
| |
| |
| private Projectile m_projectile; |
| private Projectile m_projectile; |
| |
| |
| private Character m_character; |
| private Character m_character; |
| |
| |
| private ZDOID m_tempParent; |
| private ZDOID m_tempParent; |
| |
| |
| private string m_tempAttachJoint; |
| private string m_tempAttachJoint; |
| |
| |
| private Vector3 m_tempRelativePos; |
| private Vector3 m_tempRelativePos; |
| |
| |
| private Quaternion m_tempRelativeRot; |
| private Quaternion m_tempRelativeRot; |
| |
| |
| private Vector3 m_tempRelativeVel; |
| private Vector3 m_tempRelativeVel; |
| } |
| } |
| |
| |