Exemplo n.º 1
0
    public void SendTransformEvent(int onlineIndex = 0, bool simulatingNonInteraction = false)
    {
        //if we are interacting with something we will send updates as fast as possible
        //otherwise we just send updates every so often to make sure things are synced
        if (simulatingNonInteraction)
        {
            if (Time.realtimeSinceStartup - lastSendTime < sendRate)
            {
                return;
            }
            Vector3 sending = new Vector3((float)System.Math.Round(this.transform.position.x, 2), (float)System.Math.Round(this.transform.position.y, 2), (float)System.Math.Round(this.transform.position.z, 2));
            //if(sending == lastSentPosition) return;
            lastSentPosition = sending;
        }

        NetworkedTransformInfo e = NetworkedTransformInfo.Create(Bolt.GlobalTargets.OnlyServer);

        e.position    = this.transform.position;
        e.rotation    = this.transform.rotation;
        e.accumulator = onlineIndex;
        e.id          = this.entity;
        e.Send();
        //DLog.Log("Sending NetworkedTransformInfo: " + e.position.ToString() + " : " + e.id.ToString());
        lastSendTime = Time.realtimeSinceStartup;
        //can we check to see if we NEEd to send this? e.g. values haven't changed?
    }
 public override void OnEvent(NetworkedTransformInfo evnt)
 {
     if (evnt.id != null)
     {
         evnt.id.gameObject.GetComponent <NetworkedPhysicsSharedControl>().RecEvent(evnt);
     }
 }
Exemplo n.º 3
0
    public void RecEvent(NetworkedTransformInfo evnt)
    {
        Debug.Log("Rec NetworkedTransformInfo: " + evnt.position.ToString() + " " + evnt.accumulator);

        state.simulator = evnt.accumulator;
        state.position  = evnt.position;
        state.rotation  = evnt.rotation;

        this.GetComponent <Renderer>().material.color = GetColor();

        //if we've recieved this event late...what then?
        //If player 0 asks for control, and sets control then recieves player 1's old "HEY IM STILL DOING THIS"
        //hand off isn't smooth.  How do we decide if we should STOP sending events

        //need a "local" control, if we're colliding with an object ignore all state info we get
    }