Version: 2017.1
public static double time ;

描述

获取当前网络时间(秒)。

该时间可用于(例如)与 NetworkMessageInfo 返回的时间进行比较。下面的示例 脚本需附加到具有网络视图的对象,并让该网络视图参考该脚本。 该脚本测量发送消息(用于同步对象变换的 X 位置值)所花费的时间。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float something; public double transitTime; void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) { float horizontalInput = 0.0F; if (stream.isWriting) { horizontalInput = transform.position.x; stream.Serialize(ref horizontalInput); } else { transitTime = Network.time - info.timestamp; stream.Serialize(ref horizontalInput); something = horizontalInput; } } void OnGUI() { GUILayout.Label("Last transmission time: " + transitTime); } }