Пример #1
0
    //////////////////
    // Synchonization functionality
    //////////////////
    // Receive a sync
    public void ReceiveSyncData(byte[] aData, Vector3 aPosition, Quaternion aRotation)
    {
#if UNITY_EDITOR
        previousPostions[previousPositionIndex]          = new PreviousPositionData();
        previousPostions[previousPositionIndex].position = aPosition;
        previousPostions[previousPositionIndex].rotation = aRotation;
        previousPostions[previousPositionIndex].time     = Time.time;
        previousPostions[previousPositionIndex].color    = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
        previousPositionIndex++;
        if (previousPositionIndex > previousPostions.Length - 1)
        {
            previousPositionIndex = 0;
        }
#endif
        if (owned)
        {
            return;
        }

        position = aPosition;
        rotation = aRotation;


        transform.localPosition = aPosition;
        transform.localRotation = aRotation;

        MemoryStream stream    = new MemoryStream(aData);
        BinaryReader binReader = new BinaryReader(stream);
        if (setDataFunction != null)
        {
            setDataFunction(ref binReader);
        }
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        position  = transform.position;
        rotation  = transform.rotation;
        origScene = gameObject.scene.name;

        // If our network id hasn't been set, ask the server to give us one
        if (networkId == -1)
        {
            ClientNetwork client = FindObjectOfType <ClientNetwork>();
            if (client == null)
            {
                Debug.LogError("NetworkId::Start() has been called without a ClientNetwork being available");
                this.enabled = false;
                return;
            }
            client.ConnectNetworkSync(this);
        }
        else
        {
            // Check if we own this object
            if (clientNet.isOwned(networkId))
            {
                isOwned = true;
            }
        }

#if UNITY_EDITOR
        for (int i = 0; i < previousPostions.Length; i++)
        {
            previousPostions[i]       = new PreviousPositionData();
            previousPostions[i].color = new Color(0.0f, 0.0f, 0.0f, 0.0f);
        }
#endif
    }