コード例 #1
0
    /// <summary>
    /// If the keyboard is open, then send the text that is currently typed to the VR device
    /// </summary>
    private void SendKeyboardText()
    {
        if (keyboard != null)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            byte            error;

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

            rpc.args     = new object[1];
            rpc.args [0] = keyboard.text;

            if (keyboard.done || keyboard.wasCanceled || !keyboard.active)
            {
                keyboard       = null;
                rpc.methodName = CLOSE_KEYBOARD_ID;
            }
            else
            {
                rpc.methodName = SEND_KEYBOARD_ID;
            }

            formatter.Serialize(stream, rpc);
            NetworkTransport.Send(socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
        }
    }
コード例 #2
0
    private void HandleAssetBundle(RPCSerializer rpcData)
    {
        int index = (int)rpcData.args[0];

        if (index == -1)
        {
            sceneBundle = AssetBundle.LoadFromMemory(data);
            sceneBundle.LoadAllAssets();

            string[] scenes      = sceneBundle.GetAllScenePaths();
            string   mySceneName = scenes[0];
            mySceneName = mySceneName.Substring(0, mySceneName.Length - 6);             //remove .unity
            mySceneName = mySceneName.Substring(mySceneName.LastIndexOf("/") + 1);      //remove path

            SceneManager.LoadScene(mySceneName);
        }
        else if (index == 0)
        {
            data = new byte[(int)rpcData.args[1]];
            if (sceneBundle != null)
            {
                SceneManager.LoadScene(1);
                sceneBundle.Unload(true);
            }
        }
        else
        {
            int    start = (int)rpcData.args [1];
            byte[] bData = (byte[] )rpcData.args [2];
            for (int i = 0; i < bData.Length; i++)
            {
                data [i + start] = bData [i];
            }
        }
    }
コード例 #3
0
    /// <summary>
    /// This method handles remembering which connection shuold be used to send which type of data
    /// Once all connections have been establishsed, we also send a one time message of the size of the device we are using
    /// </summary>
    /// <param name="connectionID">ConnectionId we recieved data from</param>
    /// <param name="message">The type of data that should be sent over this connection</param>
    private void AssignID(int connectionID, string message)
    {
        if (message.Equals(POSE_MESSAGE_ID))
        {
            naviPoseConnectionID = connectionID;
            naviPoseAssigned     = true;
        }
        else if (message.Equals(TOUCH_MESSAGE_ID))
        {
            touchConnectionID       = connectionID;
            touchConnectionAssigned = true;

            //Send RPC with size data
            byte            error;
            BinaryFormatter formatter = new BinaryFormatter();
            byte[]          buffer    = new byte[BUFFER_SIZE];
            Stream          stream    = new MemoryStream(buffer);

            RPCSerializer rpc = new RPCSerializer();
            rpc.methodName = SET_SIZE_METHOD_ID;
            rpc.args       = new object[2];
            rpc.args [0]   = Screen.width;
            rpc.args [1]   = Screen.height;
            formatter.Serialize(stream, rpc);
            NetworkTransport.Send(socketID, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
        }
    }
コード例 #4
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]);
        }
    }
コード例 #5
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));
        }
    }
コード例 #6
0
    /// <summary>
    /// Method to parse and recieve image RPC from big data sources like an image
    /// </summary>
    /// <param name="recBuffer">The data that was recieved from the smart device</param>
    private void HandleBigRPC(byte[] recBuffer)
    {
        Stream          stream    = new MemoryStream(recBuffer);
        BinaryFormatter formatter = new BinaryFormatter();
        RPCSerializer   rpcData   = (RPCSerializer)formatter.Deserialize(stream);

        if (rpcData.methodName.Equals(ASSET_ID))
        {
            HandleAssetBundle(rpcData);
        }
    }
コード例 #7
0
    /// <summary>
    /// Method to parse and send an RPC event from smart device such as recieving touch input
    /// </summary>
    /// <param name="recBuffer">The data that was recieved from the smart device</param>
    private void HandleRPC(byte[] recBuffer)
    {
        Stream          stream    = new MemoryStream(recBuffer);
        BinaryFormatter formatter = new BinaryFormatter();
        RPCSerializer   rpcData   = (RPCSerializer)formatter.Deserialize(stream);

        if (rpcData.methodName.Equals(TOUCH_METHOD_ID))
        {
            TouchSerializer ts = (TouchSerializer)rpcData.args [0];
            TouchManager.ProcessTouch(ts);
        }
        else if (rpcData.methodName.Equals(SET_SIZE_METHOD_ID))
        {
            TouchManager.Instance.SetServerScreenSize((int)rpcData.args[0], (int)rpcData.args[1]);
        }
    }
コード例 #8
0
    /// <summary>
    /// Send the device / platform type of the smart device to the VR device
    /// </summary>
    public void SendDeviceType()
    {
        BinaryFormatter formatter = new BinaryFormatter();
        byte            error;

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

        RPCSerializer rpc = new RPCSerializer();

        rpc.methodName = SEND_PLATFORM_METHOD_ID;
        rpc.args       = new object[1];
        rpc.args [0]   = Application.platform;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
    }
コード例 #9
0
    private void ChangePlayerID(int newID, int currConnection)
    {
        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]   = newID + 1;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, currConnection, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
    }
コード例 #10
0
    /// <summary>
    /// Send the size of the smart device to the VR device
    /// </summary>
    public void SendCurrentSize()
    {
        BinaryFormatter formatter = new BinaryFormatter();
        byte            error;

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

        RPCSerializer rpc = new RPCSerializer();

        rpc.methodName = SET_SIZE_METHOD_ID;
        rpc.args       = new object[2];
        rpc.args [0]   = Screen.width;
        rpc.args [1]   = Screen.height;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
    }
コード例 #11
0
    public void SendImage(int player_id, Texture2D tex)
    {
        int connection_id = GetPlayerPose(player_id).connectionID;

        byte[] bytesTex = tex.EncodeToPNG();

        BinaryFormatter formatter = new BinaryFormatter();

        byte[] buffer = new byte[bytesTex.Length + BUFFER_SIZE];
        Stream stream = new MemoryStream(buffer);
        byte   error;

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

        rpc.methodName = IMAGE_ID;
        rpc.args       = new object[1];
        rpc.args [0]   = bytesTex;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableFragmentedChannelId, buffer, buffer.Length, out error);
    }
コード例 #12
0
    /// <summary>
    /// Method that is called when a smart device connects
    /// </summary>
    private void DeviceConnected()
    {
        if (OnResetHMD != null)
        {
            OnResetHMD();
        }
        GestureManager.OnFiveFingerTap += ResetVR;         //enable reset at any time


        BinaryFormatter formatter = new BinaryFormatter();

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

        RPCSerializer 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, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
    }
コード例 #13
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;
        }
    }
コード例 #14
0
ファイル: NaviMobileManager.cs プロジェクト: vmohan7/Navi
    private void HandleAssetBundle(RPCSerializer rpcData)
    {
        int index = (int) rpcData.args[0];
        if (index == -1) {
            sceneBundle = AssetBundle.LoadFromMemory (data);
            sceneBundle.LoadAllAssets ();

            string[] scenes = sceneBundle.GetAllScenePaths ();
            string mySceneName = scenes[0];
            mySceneName = mySceneName.Substring(0, mySceneName.Length - 6); //remove .unity
            mySceneName = mySceneName.Substring(mySceneName.LastIndexOf("/") + 1); //remove path

            SceneManager.LoadScene (mySceneName);
        } else if (index == 0) {
            data = new byte[ (int) rpcData.args[1] ] ;
            if (sceneBundle != null) {
                SceneManager.LoadScene (1);
                sceneBundle.Unload (true);
            }
        } else {
            int start = (int)rpcData.args [1];
            byte[] bData = (byte[] )rpcData.args [2];
            for (int i = 0; i < bData.Length; i++) {
                data [i + start] = bData [i];
            }
        }
    }
コード例 #15
0
ファイル: NaviMobileManager.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Method to parse and send an RPC event from smart device such as recieving touch input
    /// </summary>
    /// <param name="recBuffer">The data that was recieved from the smart device</param>
    private void HandleRPC(byte[] recBuffer)
    {
        Stream stream = new MemoryStream(recBuffer);
        BinaryFormatter formatter = new BinaryFormatter();
        byte error;
        RPCSerializer rpcData = new RPCSerializer();
        try {
            rpcData = (RPCSerializer) formatter.Deserialize(stream);
        } catch (Exception e) {
            Debug.Log(e);
            return;
        }

        //Handle all different types of requests that came via RPC
        if (rpcData.methodName.Equals (BUILD_MESSAGE_ID)) {
            SDKBuildNo = (int)rpcData.args [0];
        } else if (rpcData.methodName.Equals (ASSIGN_DEVICE_ID)) {
            SetDeviceNumber ((int)rpcData.args [0]);
            SendCurrentSize ();
            SendDeviceType ();
        } else if (rpcData.methodName.Equals (VIBRATE_ID)) {
            Handheld.Vibrate ();
        } else if (rpcData.methodName.Equals (INSTRUCTION_ID)) {
            SetInstruction ((string)rpcData.args [0]);
        } else if (rpcData.methodName.Equals (GAMEOBJ_LOC_ID)) {
            GameObject obj = GameObject.Find ((string)rpcData.args [0]); //0 arg is string of the name of the object
            if (obj != null) {
                obj.transform.position = new Vector3 ((float)rpcData.args [1], (float)rpcData.args [2], (float)rpcData.args [3]); //arg 1,2,3 are x,y,z
            }
        } else if (rpcData.methodName.Equals (GAMEOBJ_ROT_ID)) {
            GameObject obj = GameObject.Find ((string)rpcData.args [0]); //0 arg is string of the name of the object
            if (obj != null) {
                obj.transform.rotation = new Quaternion ((float)rpcData.args [1], (float)rpcData.args [2], (float)rpcData.args [3], (float)rpcData.args [4]); //arg 1,2,3 are x,y,z
            }
        } else if (rpcData.methodName.Equals (GAMEOBJ_ANIM_ID)) {
            GameObject obj = GameObject.Find ((string)rpcData.args [0]); //0 arg is string of the name of the object
            if (obj != null) {
                //arg 1,2,3 are x,y,z and 4 is time
                StartCoroutine (AnimateObj (obj, new Vector3 ((float)rpcData.args [1], (float)rpcData.args [2], (float)rpcData.args [3]), (float)rpcData.args [4]));
            }
        } else if (rpcData.methodName.Equals (GAMEOBJ_RENDER_ID)) {
            GameObject obj = GameObject.Find ((string)rpcData.args [0]); //0 arg is string of the name of the object
            if (obj != null) {
                Renderer[] rends = obj.GetComponentsInChildren<Renderer> ();
                foreach (Renderer r in rends) {
                    r.enabled = (bool)rpcData.args [1];
                }
            }
        } else if (rpcData.methodName.Equals (GAMEOBJ_DEL_ID)) {
            GameObject obj = GameObject.Find ((string)rpcData.args [0]); //0 arg is string of the name of the object
            if (obj != null) {
                Destroy (obj);
            }
        } else if (rpcData.methodName.Equals (GAMEOBJ_DUP_ID)) {
            GameObject obj = GameObject.Find ((string)rpcData.args [0]); //0 arg is string of the name of the object
            if (obj != null) {
                GameObject newObj = Instantiate<GameObject> (obj);
                newObj.name = (string)rpcData.args [1];
                if (rpcData.args.Length > 2) {
                    newObj.transform.position = new Vector3 ((float)rpcData.args [2], (float)rpcData.args [3], (float)rpcData.args [4]); //arg 2,3,4 are x,y,z
                    newObj.transform.rotation = new Quaternion ((float)rpcData.args [5], (float)rpcData.args [6], (float)rpcData.args [7], (float)rpcData.args [8]); //arg 5,6,7,8 are x,y,z,w
                }
            }
        } else if (rpcData.methodName.Equals (COMP_METHOD_ID)) {
            GameObject obj = GameObject.Find ((string)rpcData.args [0]); //0 arg is string of the name of the object
            if (obj != null) {
                if (rpcData.args.Length > 3) {
                    CallMethod(obj, (string )rpcData.args [1], (string)rpcData.args [2], (object[])rpcData.args [3]);
                } else {
                    CallMethod(obj, (string )rpcData.args [1], (string)rpcData.args [2], null);
                }
            }
        } else if (rpcData.methodName.Equals (COMP_PROP_ID)) {
            GameObject obj = GameObject.Find ((string)rpcData.args [0]); //0 arg is string of the name of the object
            if (obj != null) {
                if (rpcData.args.Length > 4) {
                    UpdateProperty(obj, (string )rpcData.args [1], (string)rpcData.args [2], rpcData.args [3], (object[] )rpcData.args [4]);
                } else {
                    UpdateProperty(obj, (string )rpcData.args [1], (string)rpcData.args [2], rpcData.args [3], null);
                }
            }
        } else if (rpcData.methodName.Equals (OPEN_KEYBOARD_ID)) {
            if (rpcData.args.Length == 2) {
                RequestKeyboard ((string)rpcData.args [0], (bool)rpcData.args [1]);
            } else	if (rpcData.args.Length == 1) {
                RequestKeyboard ((string)rpcData.args [0], true);
            } else {
                RequestKeyboard ("", true);
            }
        } else if (rpcData.methodName.Equals (CLOSE_KEYBOARD_ID)) {
            CloseKeyboard ();
        } else if (rpcData.methodName.Equals (CLEAR_KEYBOARD_ID)) {
            ClearKeyboard ();
        } else if (rpcData.methodName.Equals (SET_DEVICE_ROTATION_ID)) {
            SetDeviceOrientation ((ScreenOrientation)rpcData.args [0], (bool)rpcData.args [1]);
        }
    }
コード例 #16
0
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;

        byte[]           recBuffer  = new byte[MAX_RECIEVE_SIZE];
        int              bufferSize = MAX_RECIEVE_SIZE;
        int              dataSize;
        byte             error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);

        Array.Resize <byte> (ref recBuffer, dataSize);        //resize to how much data was received

        switch (recData)
        {
        case NetworkEventType.ConnectEvent:
            break;

        case NetworkEventType.DataEvent:
            if (channelId == myReiliableChannelId)
            {
                HandleRPC(recBuffer);
            }
            else if (channelId == myReliableFramentedChannelId)
            {
                HandleBigRPC(recBuffer);
            }

            break;

        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;

        default:         //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviConnectionID > 0)           //we are connected to a device
        {
            byte[]          buffer              = new byte[BUFFER_SIZE];
            Stream          stream              = new MemoryStream(buffer);
            BinaryFormatter formatter           = new BinaryFormatter();
            PoseSerializerWithAcceleration pose = new PoseSerializerWithAcceleration();
            pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation, Input.acceleration);
            formatter.Serialize(stream, pose);
            NetworkTransport.Send(socketID, naviConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error);              //send full buffer

            foreach (Touch t in Input.touches)
            {
                buffer = new byte[BUFFER_SIZE];
                stream = new MemoryStream(buffer);

                RPCSerializer rpc = new RPCSerializer();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args       = new object[1];
                TouchSerializer ts = new TouchSerializer();
                ts.Fill(t);
                rpc.args [0] = ts;
                formatter.Serialize(stream, rpc);
                NetworkTransport.Send(socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }

            SendKeyboardText();

            if (Screen.orientation != prevOrientation)
            {
                SendCurrentSize();
                prevOrientation = Screen.orientation;
            }
        }
    }
コード例 #17
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// If an asset bundle has been sent to the screen, this methd allows you to edit any component on game objects in the asset bundle. if there are no parameters, set parameters to null
    /// </summary>
    public void CallComponentMethod(int player_id, string objName, string componentName, string methodName, object[] parameters)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

        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 = COMP_METHOD_ID;
        rpc.args = new object[5];
        rpc.args [0] = objName;
        rpc.args [1] = componentName;
        rpc.args [2] = methodName;
        rpc.args [3] = parameters;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableChannelId, buffer, buffer.Length, out error);
    }
コード例 #18
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Private method to iteratively send asset data to the mobile device, because in general that file will be too big 
    /// </summary>
    private IEnumerator SendAssetData(int player_id, byte[] file)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

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

        //send player id
        RPCSerializer rpc = new RPCSerializer();
        rpc.methodName = ASSET_ID;
        rpc.args = new object[2];
        rpc.args [0] = 0;
        rpc.args [1] = file.Length;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableFragmentedChannelId, buffer, buffer.Length, out error);
        yield return new WaitForSeconds(.5f); //wait for network packets to send

        //for loop to send chunks of data to the device
        for (int i = 0; i < file.Length; i+=ASSET_SEND_SIZE) {
            buffer = new byte[ASSET_SEND_SIZE + BUFFER_SIZE];
            stream = new MemoryStream(buffer);

            int remaining = file.Length - i;
            int l = ASSET_SEND_SIZE > remaining ? remaining : ASSET_SEND_SIZE;
            byte[] data = new byte[l];
            for (int j = 0; j < l; j++) {
                data [j] = file [i + j];
            }

            rpc = new RPCSerializer();
            rpc.methodName = ASSET_ID;
            rpc.args = new object[3];
            rpc.args [0] = 1; //set index
            rpc.args [1] = i;
            rpc.args [2] = data;
            formatter.Serialize(stream, rpc);
            NetworkTransport.Send(socketID, connection_id, myReliableFragmentedChannelId, buffer, buffer.Length, out error);
            LoadingPercent = ((float)i / (float)file.Length);
            NaviConnectionSDK.Instance.SetInstructions (player_id, "Loading\n"+ (int) (LoadingPercent * 100f) + "%");

            while (error != 0) {
                yield return new WaitForSeconds(.1f); //wait for network packets to clear
                NetworkTransport.Send(socketID, connection_id, myReliableFragmentedChannelId, buffer, buffer.Length, out error);
            }
        }

        yield return new WaitForSeconds(.5f); //wait for network packets to send

        buffer = new byte[ASSET_SEND_SIZE + BUFFER_SIZE];
        stream = new MemoryStream(buffer);

        rpc = new RPCSerializer();
        rpc.methodName = ASSET_ID;
        rpc.args = new object[1];
        rpc.args [0] = -1;
        formatter.Serialize(stream, rpc);

        //sends asset bundle completed message
        NetworkTransport.Send(socketID, connection_id, myReliableFragmentedChannelId, buffer, buffer.Length, out error);

        while (error != 0) {
            yield return new WaitForSeconds(.1f); //wait for network packets to clear
            NetworkTransport.Send(socketID, connection_id, myReliableFragmentedChannelId, buffer, buffer.Length, out error);
        }

        NaviConnectionSDK.Instance.SetInstructions (player_id, "");
        if (OnAssetUploaded != null)
            OnAssetUploaded (player_id);
    }
コード例 #19
0
ファイル: NaviMobileManager.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Send the size of the smart device to the VR device
    /// </summary>
    public void SendCurrentSize()
    {
        BinaryFormatter formatter = new BinaryFormatter();
        byte error;

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

        RPCSerializer rpc = new RPCSerializer ();
        rpc.methodName = SET_SIZE_METHOD_ID;
        rpc.args = new object[2];
        rpc.args [0] = Screen.width;
        rpc.args [1] = Screen.height;
        formatter.Serialize (stream, rpc);
        NetworkTransport.Send (socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
    }
コード例 #20
0
ファイル: NaviMobileManager.cs プロジェクト: schmidtec/Navi
    /// <summary>
    /// This method handles remembering which connection shuold be used to send which type of data
    /// Once all connections have been establishsed, we also send a one time message of the size of the device we are using
    /// </summary>
    /// <param name="connectionID">ConnectionId we recieved data from</param>
    /// <param name="message">The type of data that should be sent over this connection</param>
    private void AssignID(int connectionID, string message)
    {
        if (message.Equals (POSE_MESSAGE_ID)) {
            naviPoseConnectionID = connectionID;
            naviPoseAssigned = true;
        } else if (message.Equals (TOUCH_MESSAGE_ID)) {
            touchConnectionID = connectionID;
            touchConnectionAssigned = true;

            //Send RPC with size data
            byte error;
            BinaryFormatter formatter = new BinaryFormatter ();
            byte[] buffer = new byte[BUFFER_SIZE];
            Stream stream = new MemoryStream (buffer);

            RPCSerializer rpc = new RPCSerializer ();
            rpc.methodName = SET_SIZE_METHOD_ID;
            rpc.args = new object[2];
            rpc.args [0] = Screen.width;
            rpc.args [1] = Screen.height;
            formatter.Serialize (stream, rpc);
            NetworkTransport.Send (socketID, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
        }
    }
コード例 #21
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Sets the rotation of a gameobject located on the mobile device. This should be used after you have uploaded an asset bundle to the device. 
    /// </summary>
    public void SetObjRotation(int player_id, string objName, Quaternion rot)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

        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 = GAMEOBJ_ROT_ID;
        rpc.args = new object[5];
        rpc.args [0] = objName;
        rpc.args [1] = rot.x;
        rpc.args [2] = rot.y;
        rpc.args [3] = rot.z;
        rpc.args [4] = rot.w;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableChannelId, buffer, buffer.Length, out error);
    }
コード例 #22
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Method that is called when a player wants to switch to a given device id.
    /// </summary>
    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, myReliableChannelId, buffer, BUFFER_SIZE, out error);
            NetworkTransport.Send(socketID, dev2.connectionID, myReliableChannelId, buffer, BUFFER_SIZE, out error);

            dev.playerSwitchEnabled = false;
        }
    }
コード例 #23
0
ファイル: NaviMobileManager.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// If the keyboard is open, then send the text that is currently typed to the VR device
    /// </summary>
    private void SendKeyboardText()
    {
        if (keyboard != null) {
            BinaryFormatter formatter = new BinaryFormatter ();
            byte error;

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

            rpc.args = new object[1];
            rpc.args [0] = keyboard.text;

            if (keyboard.done || keyboard.wasCanceled || !keyboard.active) {
                keyboard = null;
                rpc.methodName = CLOSE_KEYBOARD_ID;
            } else {
                rpc.methodName = SEND_KEYBOARD_ID;
            }

            formatter.Serialize (stream, rpc);
            NetworkTransport.Send (socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
        }
    }
コード例 #24
0
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;

        byte[]           recBuffer  = new byte[1024];
        int              bufferSize = 1024;
        int              dataSize;
        byte             error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);

        switch (recData)
        {
        case NetworkEventType.DataEvent:
            if (!naviPoseAssigned || !touchConnectionAssigned)
            {
                Stream          stream    = new MemoryStream(recBuffer);
                BinaryFormatter formatter = new BinaryFormatter();
                string          message   = formatter.Deserialize(stream) as string;
                AssignID(connectionId, message);
            }

            break;

        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;

        default:         //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviPoseConnectionID > 0)
        {
            byte[]          buffer    = new byte[BUFFER_SIZE];
            Stream          stream    = new MemoryStream(buffer);
            BinaryFormatter formatter = new BinaryFormatter();
            PoseSerializer  pose      = new PoseSerializer();
            pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation);
            formatter.Serialize(stream, pose);
            NetworkTransport.Send(socketID, naviPoseConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error);             //send full buffer
        }


        if (touchConnectionID > 0)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            foreach (Touch t in Input.touches)
            {
                byte[] buffer = new byte[BUFFER_SIZE];
                Stream stream = new MemoryStream(buffer);

                RPCSerializer rpc = new RPCSerializer();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args       = new object[1];
                TouchSerializer ts = new TouchSerializer();
                ts.Fill(t);
                rpc.args[0] = ts;
                formatter.Serialize(stream, rpc);
                NetworkTransport.Send(socketID, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }
        }
    }
コード例 #25
0
ファイル: NaviMobileManager.cs プロジェクト: vmohan7/Navi
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;
        byte[] recBuffer = new byte[MAX_RECIEVE_SIZE];
        int bufferSize = MAX_RECIEVE_SIZE;
        int dataSize;
        byte error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
        Array.Resize<byte> (ref recBuffer, dataSize); //resize to how much data was received

        switch (recData)
        {
        case NetworkEventType.ConnectEvent:
            break;
        case NetworkEventType.DataEvent:
            if (channelId == myReiliableChannelId) {
                HandleRPC (recBuffer);
            } else if (channelId == myReliableFramentedChannelId) {
                HandleBigRPC (recBuffer);
            }

            break;
        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;
        default: //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviConnectionID > 0) { //we are connected to a device
            byte[] buffer = new byte[BUFFER_SIZE];
            Stream stream = new MemoryStream (buffer);
            BinaryFormatter formatter = new BinaryFormatter ();
            PoseSerializerWithAcceleration pose = new PoseSerializerWithAcceleration ();
            pose.Fill (TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation, Input.acceleration);
            formatter.Serialize (stream, pose);
            NetworkTransport.Send (socketID, naviConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error); //send full buffer

            foreach (Touch t in Input.touches) {
                buffer = new byte[BUFFER_SIZE];
                stream = new MemoryStream (buffer);

                RPCSerializer rpc = new RPCSerializer ();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args = new object[1];
                TouchSerializer ts = new TouchSerializer ();
                ts.Fill (t);
                rpc.args [0] = ts;
                formatter.Serialize (stream, rpc);
                NetworkTransport.Send (socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }

            SendKeyboardText ();

            if (Screen.orientation != prevOrientation) {
                SendCurrentSize ();
                prevOrientation = Screen.orientation;
            }
        }
    }
コード例 #26
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Method to tell connected device that it should open its mobile keyboard
    /// </summary>
    public void OpenMobileKeyboard(int player_id, string initalText, bool hideInputOnKeyboards)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

        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 = OPEN_KEYBOARD_ID;
        rpc.args = new object[2];
        rpc.args [0] = initalText;
        rpc.args [1] = hideInputOnKeyboards; //broken on Android
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableChannelId, buffer, buffer.Length, out error);
    }
コード例 #27
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Method to close mobile keyboard on device
    /// </summary>
    public void CloseMobileKeyboard(int player_id)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

        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 = CLOSE_KEYBOARD_ID;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableChannelId, buffer, buffer.Length, out error);
    }
コード例 #28
0
ファイル: NaviMobileManager.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Send the device / platform type of the smart device to the VR device
    /// </summary>
    public void SendDeviceType()
    {
        BinaryFormatter formatter = new BinaryFormatter();
        byte error;

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

        RPCSerializer rpc = new RPCSerializer ();
        rpc.methodName = SEND_PLATFORM_METHOD_ID;
        rpc.args = new object[1];
        rpc.args [0] = Application.platform;
        formatter.Serialize (stream, rpc);
        NetworkTransport.Send (socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
    }
コード例 #29
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// If an asset bundle has been sent to the screen, this method allows you to edit any component on game objects in the asset bundle. if there are no indices, set indices to null
    /// </summary>
    public void UpdateComponentProperty(int player_id, string objName, string componentName, string propName, object value, object[] indicies)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

        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 = COMP_PROP_ID;
        rpc.args = new object[5];
        rpc.args [0] = objName;
        rpc.args [1] = componentName;
        rpc.args [2] = propName;
        rpc.args [3] = value;
        rpc.args [3] = indicies;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableChannelId, buffer, buffer.Length, out error);
    }
コード例 #30
0
    /// <summary>
    /// Method to parse and send an RPC event from smart device such as recieving touch input
    /// </summary>
    /// <param name="recBuffer">The data that was recieved from the smart device</param>
    private void HandleRPC(byte[] recBuffer)
    {
        Stream          stream    = new MemoryStream(recBuffer);
        BinaryFormatter formatter = new BinaryFormatter();
        byte            error;
        RPCSerializer   rpcData = new RPCSerializer();

        try {
            rpcData = (RPCSerializer)formatter.Deserialize(stream);
        } catch (Exception e) {
            Debug.Log(e);
            return;
        }

        //Handle all different types of requests that came via RPC
        if (rpcData.methodName.Equals(BUILD_MESSAGE_ID))
        {
            SDKBuildNo = (int)rpcData.args [0];
        }
        else if (rpcData.methodName.Equals(ASSIGN_DEVICE_ID))
        {
            SetDeviceNumber((int)rpcData.args [0]);
            SendCurrentSize();
            SendDeviceType();
        }
        else if (rpcData.methodName.Equals(VIBRATE_ID))
        {
            Handheld.Vibrate();
        }
        else if (rpcData.methodName.Equals(INSTRUCTION_ID))
        {
            SetInstruction((string)rpcData.args [0]);
        }
        else if (rpcData.methodName.Equals(GAMEOBJ_LOC_ID))
        {
            GameObject obj = GameObject.Find((string)rpcData.args [0]);              //0 arg is string of the name of the object
            if (obj != null)
            {
                obj.transform.position = new Vector3((float)rpcData.args [1], (float)rpcData.args [2], (float)rpcData.args [3]);                  //arg 1,2,3 are x,y,z
            }
        }
        else if (rpcData.methodName.Equals(GAMEOBJ_ROT_ID))
        {
            GameObject obj = GameObject.Find((string)rpcData.args [0]);              //0 arg is string of the name of the object
            if (obj != null)
            {
                obj.transform.rotation = new Quaternion((float)rpcData.args [1], (float)rpcData.args [2], (float)rpcData.args [3], (float)rpcData.args [4]);                  //arg 1,2,3 are x,y,z
            }
        }
        else if (rpcData.methodName.Equals(GAMEOBJ_ANIM_ID))
        {
            GameObject obj = GameObject.Find((string)rpcData.args [0]);              //0 arg is string of the name of the object
            if (obj != null)
            {
                //arg 1,2,3 are x,y,z and 4 is time
                StartCoroutine(AnimateObj(obj, new Vector3((float)rpcData.args [1], (float)rpcData.args [2], (float)rpcData.args [3]), (float)rpcData.args [4]));
            }
        }
        else if (rpcData.methodName.Equals(GAMEOBJ_RENDER_ID))
        {
            GameObject obj = GameObject.Find((string)rpcData.args [0]);              //0 arg is string of the name of the object
            if (obj != null)
            {
                Renderer[] rends = obj.GetComponentsInChildren <Renderer> ();
                foreach (Renderer r in rends)
                {
                    r.enabled = (bool)rpcData.args [1];
                }
            }
        }
        else if (rpcData.methodName.Equals(GAMEOBJ_DEL_ID))
        {
            GameObject obj = GameObject.Find((string)rpcData.args [0]);              //0 arg is string of the name of the object
            if (obj != null)
            {
                Destroy(obj);
            }
        }
        else if (rpcData.methodName.Equals(GAMEOBJ_DUP_ID))
        {
            GameObject obj = GameObject.Find((string)rpcData.args [0]);              //0 arg is string of the name of the object
            if (obj != null)
            {
                GameObject newObj = Instantiate <GameObject> (obj);
                newObj.name = (string)rpcData.args [1];
                if (rpcData.args.Length > 2)
                {
                    newObj.transform.position = new Vector3((float)rpcData.args [2], (float)rpcData.args [3], (float)rpcData.args [4]);                             //arg 2,3,4 are x,y,z
                    newObj.transform.rotation = new Quaternion((float)rpcData.args [5], (float)rpcData.args [6], (float)rpcData.args [7], (float)rpcData.args [8]); //arg 5,6,7,8 are x,y,z,w
                }
            }
        }
        else if (rpcData.methodName.Equals(COMP_METHOD_ID))
        {
            GameObject obj = GameObject.Find((string)rpcData.args [0]);              //0 arg is string of the name of the object
            if (obj != null)
            {
                if (rpcData.args.Length > 3)
                {
                    CallMethod(obj, (string )rpcData.args [1], (string)rpcData.args [2], (object[])rpcData.args [3]);
                }
                else
                {
                    CallMethod(obj, (string )rpcData.args [1], (string)rpcData.args [2], null);
                }
            }
        }
        else if (rpcData.methodName.Equals(COMP_PROP_ID))
        {
            GameObject obj = GameObject.Find((string)rpcData.args [0]);              //0 arg is string of the name of the object
            if (obj != null)
            {
                if (rpcData.args.Length > 4)
                {
                    UpdateProperty(obj, (string )rpcData.args [1], (string)rpcData.args [2], rpcData.args [3], (object[] )rpcData.args [4]);
                }
                else
                {
                    UpdateProperty(obj, (string )rpcData.args [1], (string)rpcData.args [2], rpcData.args [3], null);
                }
            }
        }
        else if (rpcData.methodName.Equals(OPEN_KEYBOARD_ID))
        {
            if (rpcData.args.Length == 2)
            {
                RequestKeyboard((string)rpcData.args [0], (bool)rpcData.args [1]);
            }
            else if (rpcData.args.Length == 1)
            {
                RequestKeyboard((string)rpcData.args [0], true);
            }
            else
            {
                RequestKeyboard("", true);
            }
        }
        else if (rpcData.methodName.Equals(CLOSE_KEYBOARD_ID))
        {
            CloseKeyboard();
        }
        else if (rpcData.methodName.Equals(CLEAR_KEYBOARD_ID))
        {
            ClearKeyboard();
        }
        else if (rpcData.methodName.Equals(SET_DEVICE_ROTATION_ID))
        {
            SetDeviceOrientation((ScreenOrientation)rpcData.args [0], (bool)rpcData.args [1]);
        }
    }
コード例 #31
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Method to tell that device that it has changed to a different player number
    /// </summary>
    private void ChangePlayerID(int newID, int currConnection)
    {
        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] = newID+1;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, currConnection, myReliableChannelId, buffer, BUFFER_SIZE, out error);
    }
コード例 #32
0
ファイル: NaviMobileManager.cs プロジェクト: schmidtec/Navi
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;
        byte[] recBuffer = new byte[1024];
        int bufferSize = 1024;
        int dataSize;
        byte error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
        switch (recData)
        {
        case NetworkEventType.DataEvent:
            if (!naviPoseAssigned || !touchConnectionAssigned) {
                Stream stream = new MemoryStream(recBuffer);
                BinaryFormatter formatter = new BinaryFormatter();
                string message = formatter.Deserialize(stream) as string;
                AssignID(connectionId, message);
            }

            break;
        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;
        default: //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviPoseConnectionID > 0) {
            byte[] buffer = new byte[BUFFER_SIZE];
            Stream stream = new MemoryStream(buffer);
            BinaryFormatter formatter = new BinaryFormatter();
            PoseSerializer pose = new PoseSerializer();
            pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation);
            formatter.Serialize(stream, pose);
            NetworkTransport.Send(socketID, naviPoseConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error); //send full buffer
        }

        if (touchConnectionID > 0) {
            BinaryFormatter formatter = new BinaryFormatter();
            foreach (Touch t in Input.touches){
                byte[] buffer = new byte[BUFFER_SIZE];
                Stream stream = new MemoryStream(buffer);

                RPCSerializer rpc = new RPCSerializer();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args = new object[1];
                TouchSerializer ts = new TouchSerializer();
                ts.Fill(t);
                rpc.args[0] = ts;
                formatter.Serialize(stream, rpc);
                NetworkTransport.Send(socketID, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }
        }
    }
コード例 #33
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <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, myReliableChannelId, 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, myReliableChannelId, 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, myReliableChannelId, buffer, BUFFER_SIZE, out error);

        if (OnDeviceConnected != null) {
            OnDeviceConnected ( GetPlayerID(connectionID) );
        }
    }
コード例 #34
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Sets whether to render a gameobject located on the mobile device. This should be used after you have uploaded an asset bundle to the device. 
    /// </summary>
    public void RenderObj(int player_id, string objName, bool render)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

        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 = GAMEOBJ_RENDER_ID;
        rpc.args = new object[4];
        rpc.args [0] = objName;
        rpc.args [1] = render;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableChannelId, buffer, buffer.Length, out error);
    }
コード例 #35
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Animates a gameobject to a given location on the mobile device. This should be used after you have uploaded an asset bundle to the device. 
    /// </summary>
    public void AnimObjLocation(int player_id, string objName, Vector3 location, float time)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

        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 = GAMEOBJ_ANIM_ID;
        rpc.args = new object[5];
        rpc.args [0] = objName;
        rpc.args [1] = location.x;
        rpc.args [2] = location.y;
        rpc.args [3] = location.z;
        rpc.args [4] = time;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableChannelId, buffer, buffer.Length, out error);
    }
コード例 #36
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Method to set the device orientation on the mobile device. This uses Unity's enum and sends that to the device
    /// </summary>
    public void SetDeviceOrientaton(int player_id, ScreenOrientation orient, bool canUserChange)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

        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 = SET_DEVICE_ROTATION_ID;
        rpc.args = new object[2];
        rpc.args [0] = orient;
        rpc.args [1] = canUserChange;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableChannelId, buffer, buffer.Length, out error);
    }
コード例 #37
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/Navi
    /// <summary>
    /// Method to set the instructions on the instruction panel screen of the mobile device
    /// </summary>
    public void SetInstructions(int player_id, string instructions)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

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

        RPCSerializer rpc = new RPCSerializer();
        rpc.methodName = INSTRUCTION_ID;
        rpc.args = new object[1];
        rpc.args[0] = instructions;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableChannelId, buffer, BUFFER_SIZE, out error);
    }
コード例 #38
0
    /// <summary>
    /// Method that is called when a smart device connects
    /// </summary>
    private void DeviceConnected()
    {
        if (OnResetHMD != null)
            OnResetHMD ();
        GestureManager.OnFiveFingerTap += ResetVR; //enable reset at any time

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

        RPCSerializer 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, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
    }
コード例 #39
0
ファイル: NaviConnectionSDK.cs プロジェクト: vmohan7/NaviSnap
    public void SendImage(int player_id, Texture2D tex)
    {
        int connection_id = GetPlayerPose (player_id).connectionID;

        byte[] bytesTex = tex.EncodeToPNG ();

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

        //send player id
        RPCSerializer rpc = new RPCSerializer();
        rpc.methodName = IMAGE_ID;
        rpc.args = new object[1];
        rpc.args [0] = bytesTex;
        formatter.Serialize(stream, rpc);
        NetworkTransport.Send(socketID, connection_id, myReliableFragmentedChannelId, buffer, buffer.Length, out error);
    }