示例#1
0
    public override void OnInspectorGUI()
    {
        VNetTransform me = (target as VNetTransform);

        GUIStyle style = new GUIStyle(GUI.skin.button);

        style.normal.textColor = Color.red;
        if (me.netIdentifier == 0 &&
            GUILayout.Button("Generate Net UID", style))
        {
            me.netIdentifier = VNetUtils.GenerateUIDInEditor();
        }

        if (me.isLocalControlled == false &&
            me.isRemoteControlled == false &&
            GUILayout.Button("Take Local Control"))
        {
            me.TakeLocalControl();
        }

        if (me.isLocalControlled &&
            GUILayout.Button("Revoke Local Control"))
        {
            me.RevokeLocalControl();
        }


        base.OnInspectorGUI();
    }
示例#2
0
    public void OnTransformDataMessage(VNetMessageNetTransformData message)
    {
        // Get out the transform from the remote control stack
        if (!m_networkTransforms.ContainsKey(message.transformUID))
        {
            return;
        }
        VNetTransform trans = m_networkTransforms[message.transformUID];

        trans.AddRemoteDataPoint(message);
    }
示例#3
0
    public void OnRunCoroutineMessage(VNetMessageRunCoroutine message)
    {                   // Get out the object
        if (m_networkTransforms.ContainsKey(message.networkID) == false)
        {
            return;
        }

        double        currentTime = VNetSessionTime.Inst.GetServerTimePrecise();
        VNetTransform trans       = m_networkTransforms [message.networkID];
        MonoBehaviour comp        = trans.GetComponent(message.componentType) as MonoBehaviour;

        StartCoroutine(StartCoroutineDelayed((float)(message.netTimeStart - currentTime), comp, message.coroutineName));
    }
示例#4
0
    // Tell a transform that it's control was changed
    public void OnTransformControlMessage(VNetMessageTransformControl message)
    {
        if (m_networkTransforms.ContainsKey(message.transformUID) == false)
        {
            return;
        }

        VNetTransform trans = m_networkTransforms [message.transformUID];

        if (message.clientUID == VNetCommon.NET_CLIENT_INVALID_UID &&
            message._client.GetUID() == trans.controllingClient)
        {
            trans.RemoteRevokeControl();
            return;
        }

        trans.RemoteTakeControl(message.requestTime, message.clientUID);
    }
示例#5
0
    public void RunCoroutineSynced(MonoBehaviour component, string coroutineName)
    {
        // Get out the network transform name
        VNetTransform trans = component.GetComponent <VNetTransform>();

        if (trans == null)
        {
            throw new UnityException("Can't run synced coroutine on object without a VNetTransform!");
        }

        VNetMessageRunCoroutine message = new VNetMessageRunCoroutine();

        message.networkID     = trans.netIdentifier;
        message.componentType = component.GetType().ToString();
        message.coroutineName = coroutineName;
        message.netTimeStart  = VNetSessionTime.Inst.GetServerTimePrecise() + VNetManager.Inst.CoroutineStartDelay;
        VNet.Inst.SendToLobby(message, true);


        // delay the start of the coroutine here, too
        StartCoroutine(VNetTransformManager.Inst.StartCoroutineDelayed((float)VNetManager.Inst.CoroutineStartDelay, component, coroutineName));
    }
示例#6
0
    public void Update()
    {
        if (netSpawnAtTime == 0)
        {
            return;
        }

        if (netSpawnAtTime > VNetSessionTime.Inst.GetServerTime())
        {
            return;
        }

        netSpawnAtTime = 0;
        enabled        = false;

        // Spawn the prefab
        PrefabInstance = GameObject.Instantiate(m_prefab);
        PrefabInstance.transform.position = spawnPos;
        PrefabInstance.transform.rotation = spawnRot;
        VNetTransform netTrans = PrefabInstance.GetComponent <VNetTransform>();

        if (netTrans)
        {
            netTrans.netIdentifier = spawnObjectGUID;
            if (spawnOwnerID != VNetCommon.NET_CLIENT_INVALID_UID)
            {
                if (spawnOwnerID == VNet.Inst.GetUID())
                {
                    netTrans.TakeLocalControl();
                }
                else
                {
                    netTrans.RemoteTakeControl(netSpawnAtTime, spawnOwnerID);
                }
            }
        }
    }
示例#7
0
 // Remove a network transform from the list of all registered transforms (and children)
 public void RemoveTransform(VNetTransform transform)
 {
     m_networkTransforms.Remove(transform.netIdentifier);
 }
示例#8
0
 // Add a network transform to this list. must have a unique ID
 public void RegisterTransform(VNetTransform transform)
 {
     m_networkTransforms.Add(transform.netIdentifier, transform);
 }