Example #1
0
    public void ApplyButtonOnClick(Toggle toggle)
    {
        string finilisedList;

        if (toggle.isOn.Equals(true))
        {
            YellowStateMachinesList[counter].errorState = "2";
            if (counter == size)
            {
                //Send Updated List to the server
                //Load Optimised List Scene
                // finilisedList = JsonUtility.ToJson(YellowStateMachinesList);
                finilisedList = JsonUtility.ToJson(YellowStateMachinesList);
                JsonEntity jsonEntity = new JsonEntity();
                jsonEntity.JsonFlag   = "OptimisationRequest";
                jsonEntity.JsonObject = finilisedList;
                string optimisationMessage = JsonUtility.ToJson(jsonEntity);
                OptimisedListCommunication optimisedListCommunication = new OptimisedListCommunication();
                optimisedListCommunication.SendDataToServer(optimisationMessage);
                SceneManager.LoadScene("OptimisedRoot");
            }
            else
            {
                GameObject         newMachine = Instantiate(ListItemPrefab) as GameObject;
                ListItemController controller = newMachine.GetComponent <ListItemController>();
                controller.MachineId.text       = YellowStateMachinesList[counter + 1].id;
                controller.OperationToDo.text   = YellowStateMachinesList[counter + 1].operationToDo;
                newMachine.transform.parent     = ContentPanel.transform;
                newMachine.transform.localScale = Vector3.one;
                counter++;
            }
        }
        else
        {
            YellowStateMachinesList[counter].errorState = "0";
            if (counter == size)
            {
                //Send Updated List to the server
                //Load Optimised List Scene
                finilisedList = JsonUtility.ToJson(YellowStateMachinesList);
                JsonEntity jsonEntity = new JsonEntity();
                jsonEntity.JsonFlag   = "OptimisationRequest";
                jsonEntity.JsonObject = finilisedList;
                string optimisationMessage = JsonUtility.ToJson(jsonEntity);
                OptimisedListCommunication optimisedListCommunication = new OptimisedListCommunication();
                optimisedListCommunication.SendDataToServer(optimisationMessage);
                SceneManager.LoadScene("OptimisedRoot");
            }
            else
            {
                GameObject         newMachine = Instantiate(ListItemPrefab) as GameObject;
                ListItemController controller = newMachine.GetComponent <ListItemController>();
                controller.MachineId.text       = YellowStateMachinesList[counter + 1].id;
                controller.OperationToDo.text   = YellowStateMachinesList[counter + 1].operationToDo;
                newMachine.transform.parent     = ContentPanel.transform;
                newMachine.transform.localScale = Vector3.one;
                counter++;
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        OptimisedListCommunication redRootCommunication = new OptimisedListCommunication();

        ServerResponseRedRoot = redRootCommunication.ReceiveRedRootDataFromServer();
        OptimisedListCommunication greenRootCommunication = new OptimisedListCommunication();

        ServerResponseGreenRoot = greenRootCommunication.ReceiveGreenRootDataFromServer();

        List <MachineEntity> greenRootMachinesList = new List <MachineEntity>();
        List <MachineEntity> redRootMachinesList   = new List <MachineEntity>();

        redRootMachinesList   = JsonUtility.FromJson <List <MachineEntity> >(ServerResponseRedRoot);
        greenRootMachinesList = JsonUtility.FromJson <List <MachineEntity> >(ServerResponseGreenRoot);

        foreach (MachineEntity machines in greenRootMachinesList)
        {
            GameObject newMachine = Instantiate(GreenListItemPrefab) as GameObject;
            OptimisedListItemController greenController = newMachine.GetComponent <OptimisedListItemController>();
            greenController.MachineId.text     = machines.id;
            greenController.OperationToDo.text = machines.operationToDo;
            greenController.Xaxis.text         = machines.xAxis;
            greenController.Yaxis.text         = machines.yAxis;
            newMachine.transform.parent        = GreenContentPanel.transform;
            newMachine.transform.localScale    = Vector3.one;
        }

        foreach (MachineEntity machines in redRootMachinesList)
        {
            GameObject newMachine = Instantiate(RedListItemPrefab) as GameObject;
            OptimisedListItemController redController = newMachine.GetComponent <OptimisedListItemController>();
            redController.MachineId.text     = machines.id;
            redController.OperationToDo.text = machines.operationToDo;
            redController.Xaxis.text         = machines.xAxis;
            redController.Yaxis.text         = machines.yAxis;
            newMachine.transform.parent      = RedContentPanel.transform;
            newMachine.transform.localScale  = Vector3.one;
        }
    }