Пример #1
0
    public void Update()
    {
        Dictionary <int, ServerNetwork.NetworkObject> objInfo = serverNet.GetAllObjects();

        foreach (KeyValuePair <int, ServerNetwork.NetworkObject> objKV in objInfo)
        {
            netObjs[objKV.Key].transform.position = objKV.Value.position;
        }

        Dictionary <int, ServerNetwork.NetworkObject> objs = serverNet.GetAllObjects();

        if (objectCurrentlyIt == 0 || !objs.ContainsKey(objectCurrentlyIt))
        {
            if (objs.Count == 0)
            {
                return;
            }

            // Pick someone "random" and tell them they are it
            foreach (KeyValuePair <int, ServerNetwork.NetworkObject> objData in objs)
            {
                if (objData.Value.prefabName == "Player")
                {
                    objectCurrentlyIt = objData.Value.networkId;
                    serverNet.CallRPC("SetItState", UCNetwork.MessageReceiver.AllClients,
                                      objData.Value.networkId, true);
                    return;
                }
            }
        }

        // Check if someone has been "tagged"
        if (objs.Count > 1 && canTag)
        {
            ServerNetwork.NetworkObject itObj = objs[objectCurrentlyIt];
            foreach (KeyValuePair <int, ServerNetwork.NetworkObject> objData in objs)
            {
                if (objData.Value.prefabName == "Player")
                {
                    if (objData.Value.networkId == objectCurrentlyIt)
                    {
                        continue;
                    }
                    float sqrDis = (itObj.position - objData.Value.position).sqrMagnitude;
                    if (sqrDis < 1)
                    {
                        serverNet.CallRPC("SetItState", UCNetwork.MessageReceiver.AllClients,
                                          objectCurrentlyIt, false);
                        serverNet.CallRPC("SetItState", UCNetwork.MessageReceiver.AllClients,
                                          objData.Value.networkId, true);
                        objectCurrentlyIt = objData.Value.networkId;

                        canTag = false;
                        StartCoroutine(TagbackTime());
                        return;
                    }
                }
            }
        }
    }
 public void OnDestroyNetworkObject(int aNetworkId)
 {
     ServerNetwork.NetworkObject netObj = serverNet.GetNetObjById(aNetworkId);
     foreach (long adminClientId in adminClients)
     {
         serverNet.CallRPC("RemoveNetObject", adminClientId, -1, aNetworkId);
     }
 }
 public void OnIntantiateNetworkObject(int aNetworkId)
 {
     ServerNetwork.NetworkObject netObj = serverNet.GetNetObjById(aNetworkId);
     foreach (long adminClientId in adminClients)
     {
         serverNet.CallRPC("UpdateNetObject", adminClientId, -1, netObj.networkId, netObj.areaId, netObj.prefabName, netObj.position, netObj.rotation, netObj.followsClient);
     }
 }
    public void SetPosition(int aObjectId, Vector3 aPosition, Quaternion aRotation, int aAreaId)
    {
        // Send a message to the given game object asking it to change its position
        ServerNetwork.NetworkObject obj = serverNet.GetNetObjById(aObjectId);
        long aClientId = serverNet.GetOwnerClientId(aObjectId);

        // Send the message to the client
        serverNet.CallRPC("SetPositionFromServer", aClientId, aObjectId, aPosition, aRotation, aAreaId);
    }