Пример #1
0
    public void OnExtensionResponse(BaseEvent evt)
    {
        string    cmd        = (string)evt.Params["cmd"];
        SFSObject dataObject = (SFSObject)evt.Params["params"];

        switch (cmd)
        {
        case "start":
            Debug.Log("start cmd");
            // Setup my properties
            GameObject player1 = Instantiate(playerAPrefab);
            GameObject player2 = Instantiate(playerBPrefab);
            GameObject puckGO  = Instantiate(puckPrefab);
            current = player1.GetComponent <Player>();
            other   = player2.GetComponent <Player>();
            puck    = puckGO.GetComponent <Puck>();

            current.SetId(sfs.MySelf.Id);
            current.SetPosition(dataObject);

            //TODO : can be done in a better way---
            int[] uids = dataObject.GetIntArray("userIds");
            foreach (int uid in uids)
            {
                Debug.Log("uid recv :" + uid);
                if (uid != sfs.MySelf.Id)
                {
                    other.SetId(uid);
                    other.SetPosition(dataObject);
                }
            }
            //---
            puck.SetPosition(dataObject);
            if (current.transform.position.y > 0)
            {
                camera.transform.rotation = Quaternion.Euler(0, 0, 180);
            }
            current.SetTextComponent(scoreBottom);
            other.SetTextComponent(scoreTop);
            current.EnableTouch();
            current.gameObject.name = "me";
            other.gameObject.name   = "other";
            puck.gameObject.name    = "puck";
            Debug.Log("other : " + other.id + ", current : " + current.id);
            break;

        case "move":
            other.SetPosition(dataObject);
            puck.SetPosition(dataObject);
            break;

        case "updateScore":
            Debug.Log("ext response : " + cmd);
            current.SetScore(dataObject);
            other.SetScore(dataObject);
            break;

        case "reset":
            current.SetPosition(dataObject);
            other.SetPosition(dataObject);
            puck.SetPosition(dataObject);
            break;

        case "end":
            Debug.Log("ext response : " + cmd);
            bool won = dataObject.GetInt("id") == sfs.MySelf.Id;
            Debug.Log("End game " + won);
            if (won)
            {
                gameWonPanel.SetActive(true);
            }
            else
            {
                gameLosePanel.SetActive(true);
            }
            break;
        }
    }