コード例 #1
0
    //----------------------------------------------------------
    // Unity calback methods
    //----------------------------------------------------------
    void Start()
    {
        gameUI = GameObject.Find("UI").GetComponent<GameUI>();

        gdRt = GamedoniaRT.SharedInstance ();

        reset ();

        gdRt.eventsDispatcher.AddEventListener (GamedoniaEvents.ON_CONNECTION_LOST, OnConnectionLost);
        gdRt.eventsDispatcher.AddEventListener (GamedoniaEvents.ON_USER_JOINED_ROOM, OnUserJoinedRoom);
        gdRt.eventsDispatcher.AddEventListener (GamedoniaEvents.ON_SET_USER_VARIABLES_SUCCESS, OnSetUserVariablesSuccess);
        gdRt.eventsDispatcher.AddEventListener (GamedoniaEvents.ON_USER_LEFT_ROOM, OnUserLeftRoom);
        gdRt.AddEventListener (GamedoniaEvents.ON_LEAVE_ROOM_SUCCESS, OnLeaveRoomSuccess);
        gdRt.AddEventListener (GamedoniaEvents.ON_LEAVE_ROOM_ERROR, OnLeaveRoomError);
        gdRt.AddEventListener (GamedoniaEvents.ON_SEND_PUBLIC_MESSAGE_SUCCESS, OnPublicMessageSuccess);
        gdRt.AddEventListener (GamedoniaEvents.ON_PUBLIC_MESSAGES_RECEIVED, OnPublicMessagesReceived);

        isSpectator = gdRt.roomsManager.GetLastJoinedRoom ().IsSpectator (gdRt.me);

        if (!isSpectator) {
            // Random avatar and color
            int numModel = UnityEngine.Random.Range (0, playerModels.Length);
            int numMaterial = UnityEngine.Random.Range (0, playerMaterials.Length);
            SpawnLocalPlayer (numModel, numMaterial);

            GameUI ui = GameObject.Find ("UI").GetComponent ("GameUI") as GameUI;
            ui.SetAvatarSelection (numModel);
            ui.SetColorSelection (numMaterial);
        }

        //Cargamos en la ventana del chat los mensajes que tengamos almacenados en el Buffer hasta el momento
        Room room = gdRt.roomsManager.GetLastJoinedRoom ();

        foreach (Map message in room.GetPublicMessages()) {

            gameUI.chatContentText.text += "<b><color=darkblue>" + message.GetString("u") +"</color></b>: "+  message.GetString("m") + "\n";

        }

        //Serializamos a fichero un mensaje
        List<Gamedonia.Rt.Entities.UserVariable> userVariables = new List<Gamedonia.Rt.Entities.UserVariable>();
        userVariables.Add(new Gamedonia.Rt.Entities.UserVariable("x", 1.1));
        userVariables.Add(new Gamedonia.Rt.Entities.UserVariable("y", 1.653));
        userVariables.Add(new Gamedonia.Rt.Entities.UserVariable("z", 1.2332));
        userVariables.Add(new Gamedonia.Rt.Entities.UserVariable("rot", 0.68));
        SetUserVariablesOperation suvop = new SetUserVariablesOperation(userVariables,gdRt.me);
        suvop.WriteFile ();
    }
コード例 #2
0
    void OnUserJoinedRoom(Gamedonia.Rt.Events.Event evt)
    {
        if (localPlayer != null) {

            IList<Gamedonia.Rt.Entities.UserVariable> userVariables = new List<Gamedonia.Rt.Entities.UserVariable> ();
            userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("x", (double)localPlayer.transform.position.x));
            userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("y", (double)localPlayer.transform.position.y));
            userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("z", (double)localPlayer.transform.position.z));
            userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("rot", (double)localPlayer.transform.rotation.eulerAngles.y));
            userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("model", (int)gdRt.me.GetVariable ("model").GetLong ()));
            userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("mat", (int)gdRt.me.GetVariable ("mat").GetLong ()));
            SetUserVariablesOperation suvop = new SetUserVariablesOperation (userVariables, gdRt.me);
            gdRt.SendOp (suvop);
        }
    }
コード例 #3
0
    //----------------------------------------------------------
    // Private player helper methods
    //----------------------------------------------------------
    private void SpawnLocalPlayer(int numModel, int numMaterial)
    {
        Vector3 pos;
        Quaternion rot;

        if (localPlayer != null) {
            pos = localPlayer.transform.position;
            rot = localPlayer.transform.rotation;
            Camera.main.transform.parent = null;
            Destroy(localPlayer);
        } else {
            pos = new Vector3(0, 1, 0);
            rot = Quaternion.identity;
        }

        //Span the local player
        localPlayer = GameObject.Instantiate(playerModels[numModel]) as GameObject;
        localPlayer.transform.position = pos;
        localPlayer.transform.rotation = rot;

        // Setup the material
        localPlayer.GetComponentInChildren<Renderer>().material = playerMaterials[numMaterial];

        //Setup camera
        localPlayer.AddComponent<PlayerController>();
        localPlayerController = localPlayer.GetComponent<PlayerController>();
        localPlayer.GetComponentInChildren<TextMesh>().text = gdRt.me.name;
        Camera.main.transform.parent = localPlayer.transform;

        //Send our position to the server
        IList<Gamedonia.Rt.Entities.UserVariable> vars = new List<Gamedonia.Rt.Entities.UserVariable>();
        vars.Add(new Gamedonia.Rt.Entities.UserVariable("model",numModel));
        vars.Add(new Gamedonia.Rt.Entities.UserVariable("mat",numMaterial));

        SetUserVariablesOperation suvop = new SetUserVariablesOperation(vars,GamedoniaRT.SharedInstance().me);

        gdRt.SendOp(suvop);
    }
コード例 #4
0
    void FixedUpdate()
    {
        if (gdRt != null) {

            if (localPlayer != null && localPlayerController != null && localPlayerController.MovementDirty) {
                IList<Gamedonia.Rt.Entities.UserVariable> userVariables = new List<Gamedonia.Rt.Entities.UserVariable>();
                userVariables.Add(new Gamedonia.Rt.Entities.UserVariable("x", (double)localPlayer.transform.position.x));
                userVariables.Add(new Gamedonia.Rt.Entities.UserVariable("y", (double)localPlayer.transform.position.y));
                userVariables.Add(new Gamedonia.Rt.Entities.UserVariable("z", (double)localPlayer.transform.position.z));
                userVariables.Add(new Gamedonia.Rt.Entities.UserVariable("rot", (double)localPlayer.transform.rotation.eulerAngles.y));
                SetUserVariablesOperation suvop = new SetUserVariablesOperation(userVariables,GamedoniaRT.SharedInstance().me);
                gdRt.SendOp(suvop);
                localPlayerController.MovementDirty = false;
            }

        }
    }