/// <summary>
    /// Finishes caching data and then sends it over through the network. Used internally.
    /// </summary>
    /// <param name="info">Info.</param>
    private void Finish(SparkMessageInfo info)
    {
        if (IsEmpty)
        {
            return;
        }

        bool equal = networkVariables.OrderBy(pair => pair.Key).SequenceEqual(previousVariables.OrderBy(pair => pair.Key));

        if (equal)
        {
            return;
        }

        IsWriting = false;

        using (RTData data = RTData.Get())
        {
            data.SetString(1, SparkExtensions.Serialize(this));
            data.SetString(2, SparkExtensions.Serialize(info));

            SparkManager.instance.sparkNetwork.SendData(1, observeMethod, data);
        }

        sendCount         = 0;
        previousVariables = networkVariables;
        networkVariables.Clear();

        IsWriting = true;
    }
Beispiel #2
0
    private void OnSerializeSparkView(SparkStream stream, SparkMessageInfo info)
    {
        if (stream.IsWriting)
        {
            if ((sparkView.IsLocalPlayer && syncer == Syncer.LocalPlayer) || (SparkManager.instance.IsMasterPlayer && syncer == Syncer.MasterPlayer))
            {
                stream.SendNext(transform.position);
                stream.SendNext(transform.localScale);
                stream.SendNext(transform.eulerAngles);
            }
        }
        else
        {
            previousPosition = transform.position;
            nextPosition     = stream.ReceiveNext <Vector3>();

            previousScale = transform.localScale;
            nextScale     = stream.ReceiveNext <Vector3>();

            previousRotation = transform.eulerAngles;
            nextRotation     = stream.ReceiveNext <Vector3>();

            syncTime  = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;
        }
    }
Beispiel #3
0
    private void Start()
    {
        sendTime = sendRate;

        streams = new Dictionary <Guid, SparkStream>();
        info    = new SparkMessageInfo(sparkPeer);
    }
Beispiel #4
0
    /// <summary>
    /// Raises the packet event.
    /// </summary>
    /// <param name="packet">Packet.</param>
    public void OnPacket(RTPacket packet)
    {
        switch ((SparkManager.OpCode)Enum.ToObject(typeof(SparkManager.OpCode), packet.OpCode))
        {
        case SparkManager.OpCode.Sync:

            SparkStream      stream = SparkExtensions.Deserialize <SparkStream>(packet.Data.GetString(1));
            SparkMessageInfo info   = SparkExtensions.Deserialize <SparkMessageInfo>(packet.Data.GetString(2));

            foreach (SparkBehaviour behaviour in ObservedBehaviours)
            {
                if (stream.NetGuid == behaviour.netGuid)
                {
                    SendEvent_OnSerializeSparkView(behaviour, stream, info);
                }
            }

            break;

        case SparkManager.OpCode.SparkView_RPC:

            // RPC handling

            SparkRPC rpc = SparkExtensions.Deserialize <SparkRPC>(packet.Data.GetString(1));

            foreach (SparkBehaviour behaviour in ObservedBehaviours)
            {
                if (behaviour.netGuid == rpc.NetGuid)
                {
                    behaviour.Call(rpc.MethodName, rpc.Parameters);
                }
            }

            break;

        case SparkManager.OpCode.SparkView_LocalRPC:
            SparkRPC localRpc = SparkExtensions.Deserialize <SparkRPC>(packet.Data.GetString(1));

            if (localRpc.NetGuid == netGuid)
            {
                this.Call(localRpc.MethodName, localRpc.Parameters);
            }

            break;
        }
    }
Beispiel #5
0
 // Serialize
 private void OnSerializeSparkView(SparkStream stream, SparkMessageInfo info)
 {
 }
Beispiel #6
0
 /// <summary>
 /// Sends the event on serialize spark view.
 /// </summary>
 /// <param name="behaviour">Behaviour.</param>
 /// <param name="stream">Stream.</param>
 /// <param name="info">Info.</param>
 private void SendEvent_OnSerializeSparkView(SparkBehaviour behaviour, SparkStream stream, SparkMessageInfo info)
 {
     behaviour.Call("OnSerializeSparkView", stream, info);
 }