Ejemplo n.º 1
0
    void Start()
    {
        pw       = GetComponent <PlayerPrefsWrapper>();
        serverIP = pw.GetIPKey();
        deviceID = Int32.Parse(pw.GetDeviceID());
        Debug.Log("Client ID (ClientScene): " + deviceID);
        connectionStatus = GameObject.FindGameObjectWithTag("ConnectionStatus").GetComponent <Text>();

        xCoord     = GameObject.FindGameObjectWithTag("xCoord").GetComponent <Text>();
        yCoord     = GameObject.FindGameObjectWithTag("yCoord").GetComponent <Text>();
        zCoord     = GameObject.FindGameObjectWithTag("zCoord").GetComponent <Text>();
        angle      = GameObject.FindGameObjectWithTag("Angle").GetComponent <Text>();
        factor     = GameObject.FindGameObjectWithTag("Factor").GetComponent <Text>();
        tableAngle = GameObject.FindGameObjectWithTag("Table").GetComponent <Text>();

        upButt     = GameObject.Find("upButt").GetComponent <Button>();
        downButt   = GameObject.Find("downButt").GetComponent <Button>();
        rightButt  = GameObject.Find("rightButt").GetComponent <Button>();
        leftButt   = GameObject.Find("leftButt").GetComponent <Button>();
        scaleUp    = GameObject.Find("scaleUp").GetComponent <Button>();
        scaleDown  = GameObject.Find("scaleDown").GetComponent <Button>();
        factorUp   = GameObject.Find("factorUp").GetComponent <Button>();
        factorDown = GameObject.Find("factorDown").GetComponent <Button>();
        showHide   = GameObject.Find("showHide").GetComponent <Button>();
        swapLayer  = GameObject.Find("swapLayer").GetComponent <Button>();
        mainCam    = GameObject.Find("Main Camera");

        upButt.onClick.AddListener(upClicked);
        downButt.onClick.AddListener(downClicked);
        rightButt.onClick.AddListener(rightClicked);
        leftButt.onClick.AddListener(leftClicked);
        scaleUp.onClick.AddListener(scaleUpClicked);
        scaleDown.onClick.AddListener(scaleDownClicked);
        factorUp.onClick.AddListener(upFactorClicked);
        factorDown.onClick.AddListener(downFactorClicked);
        showHide.onClick.AddListener(showHideClicked);
        swapLayer.onClick.AddListener(swapLayerClicked);

        handSkin        = GameObject.Find("Skin");
        handSkeleton    = GameObject.Find("Skeleton");
        handNervous     = GameObject.Find("Nervous");
        handMuscles     = GameObject.Find("Muscles");
        handCirculatory = GameObject.Find("Circulatory");

        currentModel = handSkin;

        try {
            Debug.Log("Connecting to " + serverIP);
            connectionStatusString = "Connecting to " + serverIP;
            connectionStatus.text  = connectionStatusString;
            TcpClient client = new TcpClient(serverIP, 8081);
            reader = new StreamReader(client.GetStream());
            writer = new StreamWriter(client.GetStream());
            serverConnectionIsAlive = true;
            Debug.Log("Connected to " + serverIP + "!");
            connectionStatusString = "Connected to " + serverIP;
            connectionStatus.text  = connectionStatusString;
            networkThread          = new Thread(new ThreadStart(readFromServer));
            networkThread.Start();
        } catch (Exception e) {
            Console.WriteLine(e);
        }
        // Debug.Log("AutoSwitch? " + autoSwitch + ", counter: " + autoSwitchCounter);
    }