This class is responsible for taking the unreliable network pose data and interpolating. The interpolated data can be accessed via the DeviceLocation static variable, which is the transform of the game object this script is attached to. Supports only one device.
Inheritance: MonoBehaviour
コード例 #1
0
    /// <summary>
    /// Method to parse and send an RPC event from smart device such as recieving touch input
    /// </summary>
    /// <param name="connectionID">The id of the device that connected</param>
    /// <param name="recBuffer">The data that was recieved from the smart device</param>
    private void HandleRPC(int connectionID, byte[] recBuffer)
    {
        Stream          stream    = new MemoryStream(recBuffer);
        BinaryFormatter formatter = new BinaryFormatter();
        RPCSerializer   rpcData   = (RPCSerializer)formatter.Deserialize(stream);

        int        playerID = -1;
        NaviDevice dev      = null;

        for (int i = 0; i < playerConnectionIds.Count; i++)
        {
            if (playerConnectionIds[i].connectionID == connectionID)
            {
                playerID = i;
                dev      = playerConnectionIds[i];
                break;
            }
        }

        if (rpcData.methodName.Equals(TOUCH_METHOD_ID))
        {
            TouchSerializer ts = (TouchSerializer)rpcData.args [0];
            TouchManager.ProcessTouch(playerID, ts);
        }
        else if (rpcData.methodName.Equals(SET_SIZE_METHOD_ID))
        {
            dev.SetServerScreenSize((int)rpcData.args[0], (int)rpcData.args[1]);
        }
    }
コード例 #2
0
    /// <summary>
    /// Method that is called when a connection is made. We then send a message back to the smart device
    /// so that the smart device knows which connection it should use to send different types of data.
    /// OnDeviceConnected is called when all connections have been made.
    /// </summary>
    /// <param name="connectionID">The id of the connection was made</param>
    private void OnConnection(int connectionID)
    {
        //string message = "";
        //CancelInvoke(SEND_DATA_METHOD_STR);

        NaviDevice deviceLocation = (Instantiate(DeviceLocationPrefab.gameObject) as GameObject).GetComponent <NaviDevice> ();

        deviceLocation.connectionID = connectionID;

        playerConnectionIds.Add(deviceLocation);

        int playerID = playerConnectionIds.Count;         //id is the last element of the array

        deviceLocation.name = "Device #" + playerID;

        BinaryFormatter formatter = new BinaryFormatter();

        byte[] buffer = new byte[BUFFER_SIZE];
        Stream stream = new MemoryStream(buffer);
        byte   error;

        //send player id
        RPCSerializer rpc = new RPCSerializer();

        rpc.methodName = ASSIGN_DEVICE_ID;
        rpc.args       = new object[1];
        rpc.args [0]   = playerID;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);

        //send build number
        buffer = new byte[BUFFER_SIZE];
        stream = new MemoryStream(buffer);

        rpc            = new RPCSerializer();
        rpc.methodName = BUILD_MESSAGE_ID;
        rpc.args       = new object[1];
        rpc.args[0]    = SDK_BUILD_NO;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);

        //send instructions
        buffer = new byte[BUFFER_SIZE];
        stream = new MemoryStream(buffer);

        rpc            = new RPCSerializer();
        rpc.methodName = INSTRUCTION_ID;
        rpc.args       = new object[1];
        rpc.args[0]    = CONTROL_INSTRUCTIONS;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);

        if (OnDeviceConnected != null)
        {
            OnDeviceConnected(GetPlayerID(connectionID));
        }
    }
コード例 #3
0
    public void TouchUp(int playerID, int fingerID, Vector2 pos)
    {
        NaviDevice dev = GetPlayerPose(playerID);

        dev.numFingersDown--;

        if (dev.playerSwitchEnabled && (Time.time - dev.playerResetTimer) > ResetWaitTime)
        {
            dev.playerSwitchEnabled = false;
        }
    }
コード例 #4
0
    //TODO: comment what is going on here
    //Basic is that immediately after a reset, you need to hold X fingers on the device for 5 seconds, where X is the player number you would like to become
    public void StartPlayerSwitchIds(int playerID, int fingerID, Vector2 pos)
    {
        NaviDevice dev = GetPlayerPose(playerID);

        dev.numFingersDown++;
        if (dev.playerSwitchEnabled && (Time.time - dev.playerResetTimer) <= ResetWaitTime)           //you have 2 seconds to place next finger to keep playerReset option
        {
            dev.playerResetTimer = Time.time;
        }
        else
        {
            dev.playerSwitchEnabled = false;
        }
    }
コード例 #5
0
ファイル: CopyTablet.cs プロジェクト: vmohan7/NaviPirateDemo
 /// <summary>
 /// Updates the game objects transform based on the device location and the current copy setting (rotation or both rotation and position)
 /// </summary>
 void Update()
 {
     if (NaviConnectionSDK.Instance.GetPlayerPose(0) != null)
     {
         NaviDevice player0 = NaviConnectionSDK.Instance.GetPlayerPose(0);
         if (justRotation)
         {
             transform.rotation = player0.transform.rotation;
         }
         else
         {
             //TODO figure out how to scale the position and make it rotate around you based on some assumptions of reset
             transform.position = initalRadius * player0.transform.position + initalPos;
             moveableObject.transform.rotation = player0.transform.rotation;
         }
     }
 }
コード例 #6
0
    /// <summary>
    /// Method that is called when one of the connection disconnects.
    /// </summary>
    /// <param name="recSocketId">The id of the device that is connecting</param>
    /// <param name="connectionID">The connection id that disconnected</param>
    private void OnDisconnect(int connectionID)
    {
        for (int i = 0; i < playerConnectionIds.Count; i++)
        {
            NaviDevice naviDevice = playerConnectionIds[i];
            if (naviDevice.connectionID == connectionID)
            {
                playerConnectionIds.Remove(naviDevice);
                GameObject.Destroy(naviDevice);

                if (OnDeviceDisconnected != null)
                {
                    OnDeviceDisconnected(i);
                }

                break;
            }
        }
    }
コード例 #7
0
    /// <summary>
    /// Resets the HMD and smart device. Will call OnGameStart once both the device and HMD have been reset.
    /// This method is mapped to a 5 finger tap. So whenever a user taps with 5 fingers they will be reset
    /// </summary>
    public void ResetVR(int playerID)
    {
        if (playerID == 0)
        {
            if (OnResetHMD != null)
            {
                OnResetHMD();
            }

            ResetDevice();

            if (OnGameStart != null && initalReset)
            {
                initalReset = false;
                OnGameStart();
            }
        }

        NaviDevice dev = GetPlayerPose(playerID);

        dev.playerResetTimer    = Time.time;
        dev.playerSwitchEnabled = true;
    }
コード例 #8
0
    public void SwitchPlayerIds(int playerID, int fingerID, Vector2 pos)
    {
        NaviDevice dev = GetPlayerPose(playerID);

        if (dev.playerSwitchEnabled && (Time.time - dev.playerResetTimer) >= ResetHoldTime)           // hold num fingers on screen for required time
        {
            int        dev2PlayerID = dev.numFingersDown - 1;
            NaviDevice dev2         = GetPlayerPose(dev2PlayerID);
            if (dev2 == null)
            {
                dev2PlayerID = playerConnectionIds.Count - 1;
                dev2         = GetPlayerPose(dev2PlayerID);         //zero based
            }

            playerConnectionIds[dev2PlayerID] = dev;
            playerConnectionIds[playerID]     = dev2;

            //send playerIds to device
            ChangePlayerID(dev2PlayerID, dev.connectionID);
            ChangePlayerID(playerID, dev2.connectionID);

            BinaryFormatter formatter = new BinaryFormatter();
            byte[]          buffer    = new byte[BUFFER_SIZE];
            Stream          stream    = new MemoryStream(buffer);
            byte            error;

            //vibrate the two devices in recogniztion of switching
            RPCSerializer rpc = new RPCSerializer();
            rpc.methodName = VIBRATE_ID;
            formatter.Serialize(stream, rpc);
            NetworkTransport.Send(socketID, dev.connectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            NetworkTransport.Send(socketID, dev2.connectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);

            dev.playerSwitchEnabled = false;
        }
    }