示例#1
0
 public User()
 {
     uid     = System.Guid.NewGuid().ToString();
     isHost  = false;
     name    = "Phil";//(new List<string> { "", "", "", "" }).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
     roomKey = "";
     achor   = new AnchorPayload();
     Debug.Log("User has been created" + uid);
 }
示例#2
0
        /// <summary>
        /// Shows UI for the beginning phase of application "Hosting Mode".
        /// </summary>
        /// <param name="snackbarText">Optional text to put in the snackbar.</param>
        public void ShowHostingModeBegin(string snackbarText = null)
        {
            HostAnchorModeButton.GetComponentInChildren <Text>().text = "Cancel";
            HostAnchorModeButton.interactable = true;
            ResolveAnchorModeButton.GetComponentInChildren <Text>().text = "Resolve";
            ResolveAnchorModeButton.interactable = false;

            if (string.IsNullOrEmpty(snackbarText))
            {
                SnackbarText.text =
                    "The room code is now available. Please place an anchor to host, press Cancel to Exit.";
            }
            else
            {
                SnackbarText.text = snackbarText;
                Debug.Log("PayloadRestored, snackbar = " + snackbarText);
                if (snackbarText.Equals("Cloud anchor was created and saved."))
                {
                    Debug.Log("Got inside if statement");
                    //package data
                    //get dictionary
                    GameObject cloudController;
                    cloudController = GameObject.Find("CloudAnchorController");
                    RoomSharingServer roomSharingServer = cloudController.GetComponent <RoomSharingServer>();
                    //roomSharingServer.m_RoomAnchorsDict;
                    //_GetDeviceIpAddress()

                    string Cloud_ID = "";
                    foreach (KeyValuePair <int, XPAnchor> kvp in roomSharingServer.m_RoomAnchorsDict)
                    {
                        Cloud_ID = kvp.Value.CloudId;
                        Debug.Log("Key: " + kvp.Key + " ID: " + kvp.Value.CloudId);
                    }



                    AnchorPayload payload = new AnchorPayload
                    {
                        CloudID   = Cloud_ID,
                        ipAddress = _GetDeviceIpAddress()
                    };
                    Debug.Log("Payload Created" + roomSharingServer.m_RoomAnchorsDict.Count);



                    //send to Eventsystem
                    GameObject eventSystem;
                    eventSystem = GameObject.Find("EventSystem");
                    GameDataRelay gameDataRelay = eventSystem.GetComponent <GameDataRelay>();
                    gameDataRelay.seq.setHostLocalizationData(payload);
                }
            }

            InputRoot.SetActive(false);
        }
示例#3
0
    public void setupListeners()
    {
        // Invalid key specified..
        relay.On("invalidKey", (data) =>
        {
            Debug.Log(data);
        });

        // When anyone joins the room output room Id
        relay.On("joinedRoom", (data) =>
        {
            string str = data.ToString();
            JoinedRoomResult joinResult = JsonUtility.FromJson <JoinedRoomResult>(str);
            user.roomKey = joinResult.roomKey;

            gameList.roomKey(user.roomKey);

            gameList.addPlayerToLobber(user);
            Debug.Log(user.uid + "  " + user.isHost);

            // if (!user.isHost)
            // {
            //     Debug.Log("Party code entered in joined");
            //     // gameList.partyCodeEntered();
            // }

            if (user.achor.RoomKey == -1 && joinResult.localizationData != null)
            {
                user.achor              = joinResult.localizationData;
                GroupPayload            = joinResult.localizationData;
                user.trigger_get_anchor = true;
                // user.achor = anchorPayload;
            }
            if (user.isHost)
            {
                //construct payload
                //user.roomKey;

                //geterate ip
                //generate dictionary

                //setLocalizationData();
            }
        });



        relay.On("gameStarted", () =>
        {
            //f*****g game is running
            this.gameList.gameStarted();
        });

        relay.On("timeLeft", (time) =>
        {
            Debug.Log(time);
            this.gameList.timeLeft(time.ToString());
        });

        relay.On("gameOver", () =>
        {
            Debug.Log("gameover");

            this.gameList.gameOver();
        });


        relay.On("finalScores", (scores) =>
        {
            Debug.Log("finalScores");

            this.gameList.finalScores(scores);

            // Debug.Log(scores);
        });



        // This is emmited from the channel of the room
        relay.On("newMemberJoined", (data) =>
        {
            User newUser = JsonUtility.FromJson <User>(data.ToString());
            if (user.uid == newUser.uid)
            {
                Debug.Log("I Joined!");
            }
            else
            {
                Debug.Log("New person joined!");
                Debug.Log(newUser.uid);
            }
        });


        // This is emmited from the channel of the room
        relay.On("memberDropped", (data) =>
        {
            User deadUser = JsonUtility.FromJson <User>(data.ToString());
            Debug.Log("Someone left!");
            Debug.Log(deadUser.uid);
        });

        relay.On("broadcastLocalizationData", (data) =>
        {
            Debug.Log("Data: " + data.ToString() + "User.UID = " + user.uid);
            AnchorPayload anchorPayload = JsonUtility.FromJson <AnchorPayload>(data.ToString());
            GroupPayload = anchorPayload;
            if (user.achor.RoomKey == -1)
            {
                user.trigger_get_anchor = true;
                // user.achor = anchorPayload;
            }
        });


        relay.On("broadcastData", (data) =>
        {
            BaseDataBroadcast payload = JsonUtility.FromJson <BaseDataBroadcast>(data.ToString());

            switch (payload.type)
            {
            case "something":
                break;
            }
        });
    }
示例#4
0
 public void setHostLocalizationData(AnchorPayload payload)
 {
     Debug.Log("setHostLocalizationDataCalled " + payload.asJson());
     user.achor = payload;
     setLocalizationData();
 }