예제 #1
0
    //This method is called when receiving remote transform
    // We update lastState here to know last received transform state
    void ReceiveTransform(SFSObject data)
    {
        Debug.Log("ReceiveTransform()");
        if (receiveMode) {
            Vector3 pos = new Vector3(Convert.ToSingle(data.GetNumber("x")),
                                        Convert.ToSingle(data.GetNumber("y")),
                                        Convert.ToSingle(data.GetNumber("z"))
                                        );

            Quaternion rot = new Quaternion(
                                        Convert.ToSingle(0.0),
                                        Convert.ToSingle(data.GetNumber("ry")),
                                        Convert.ToSingle(0.0),
                                        Convert.ToSingle(data.GetNumber("w"))
            );

            lastState.InitFromValues(pos, rot);

            // Adding next received state to the queue
            NetworkTransform nextState = new NetworkTransform(this.gameObject);
            nextState.InitFromValues(pos, rot);
            queue.Enqueue(nextState);
            Debug.Log("queue length: "+Convert.ToString(queue.Count));
        }
    }
예제 #2
0
    //This method is called when receiving remote heading
    // We update course here
    public void ReceiveHeading(SFSObject data)
    {
        if (receiveMode)
        {
            Vector3 pos = new Vector3(Convert.ToSingle(data.GetNumber("x")),
                                        Convert.ToSingle(data.GetNumber("y")),
                                        Convert.ToSingle(data.GetNumber("z"))
                                        );
            float angle = Convert.ToSingle(data.GetNumber("a"));
            long time = (long) data.GetNumber("t");
            float speed = Convert.ToSingle(data.GetNumber("s"));
            long accelerationTime = (long) data.GetNumber("at");
            float endSpeed = -1;
            if (accelerationTime != -1)
            {
                endSpeed = Convert.ToSingle(data.GetNumber("es"));
            }
            //Debug.Log("ReceiveHeading() has received a heading : "+pos+"; a="+angle+", s="+speed+", t="+time+", at="+accelerationTime+", es="+endSpeed);

            course.InitFromValues(pos, angle, time, speed, endSpeed, accelerationTime);
            if(hasReceivedHeading == true)
                CreateInterceptor();

            hasReceivedHeading = true;
        }
    }
예제 #3
0
 private void ForceSendTransform(SFSObject data)
 {
     //if this message is addressed to this user
     if ((int)data.GetNumber("to_uid") == smartFoxClient.myUserId) {
         // Find local player object
         GameObject user = GameObject.Find("localPlayer");
         // Send him message
         if (user) user.SendMessage("ForceSendTransform");
     }
 }
예제 #4
0
    //This method is called when receiving remote transform
    // We update lastState here to know last received transform state
    void ReceiveTransform(SFSObject data)
    {
        if (receiveMode) {
            Vector3 pos = new Vector3(Convert.ToSingle(data.GetNumber("x")),
                                        Convert.ToSingle(data.GetNumber("y"))+yAdjust,
                                        Convert.ToSingle(data.GetNumber("z"))
                                        );

            Quaternion rot = new Quaternion(Convert.ToSingle(data.GetNumber("rx")),
                                        Convert.ToSingle(data.GetNumber("ry")),
                                        Convert.ToSingle(data.GetNumber("rz")),
                                        Convert.ToSingle(data.GetNumber("w"))

            );

            lastState.InitFromValues(pos, rot);

            // Adding next received state to the queue
            NetworkTransform nextState = new NetworkTransform(this.gameObject);
            nextState.InitFromValues(pos, rot);
            queue.Enqueue(nextState);
        }
    }
예제 #5
0
    public void OnExtensionResponse(SFSObject data)
    {
        //Debug.Log("received request n°"+(++numReceive));

        responsePending = false;

        long serverTimeStamp = (long) data.GetNumber("t");
        AddTimeDelta(timeRequestSent, (long) (Time.time*1000), serverTimeStamp);

        if (bursting)
        {
            if (deltas.Count == maxDeltas)
            {
                ClockReady(EventArgs.Empty);
            }
            RequestServerTime();
        }
        //Debug.Log("latency = "+latency+", syncTimeDelta = " + syncTimeDelta);
    }
예제 #6
0
 // Here we process incoming SFS objects
 private void OnObjectReceived(SFSObject data, User fromUser)
 {
     //First determine the type of this object - what it contains ?
     String _cmd = data.GetString("_cmd");
     switch (_cmd) {
         case "t":  // "t" - means transform sync data
             SendTransformToRemotePlayerObject(data, fromUser);
             break;
         case "f":  // "f" - means force our local player to send his transform
             ForceSendTransform(data);
             break;
         case "a": // "a" - for animation message received
             SendAnimationMessageToRemotePlayerObject(data, fromUser);
             break;
         case "d": //"d" - for damage message received
             DamageLocalPlayer(data.GetNumber("amount"));
             break;
         case "k": //"k" - for player killed
             KillRemotePlayer();
             break;
     }
 }