Example #1
0
        private GameObject AddActor(Util.ApiInfo apiInfo)
        {
            switch (apiInfo.Type)
            {
            case "button":
                var button = Instantiate(ButtonPrefab);
                button.GetComponentInChildren <Text>().text = apiInfo.Name;
                button.GetComponent <Button>().onClick.AddListener(delegate
                {
                    apiInfo.PerformAction();
                    apiInfo.Value = "click";
                });
                return(button);

            case "input":
                var input = Instantiate(InputPrefab);
                input.transform.Find("Button").GetComponent <Button>().onClick.AddListener(delegate
                {
                    var textInput = input.GetComponentInChildren <KeyboardInputField>().textComponent.text;
                    apiInfo.Value = textInput;
                    input.transform.Find("PasswordField").Find("Text").gameObject.GetComponent <Text>().text = "";
                    apiInfo.PerformAction(textInput);
                });
                return(input);

            case "output":
                var output = Instantiate(OutputPrefab);
                StartCoroutine(GetText(output, apiInfo));
                return(output);

            case "slider":
                var slider = Instantiate(SliderPrefab);
                slider.transform.Find("Name").GetComponent <Text>().text = apiInfo.Name;
                slider.GetComponent <Slider>().onValueChanged.AddListener(delegate
                {
                    apiInfo.Value = ((int)slider.GetComponent <Slider>().value).ToString();
                    apiInfo.PerformAction(apiInfo.Value);
                });
                return(slider);

            default:
                Debug.LogError("Cannot find type for " + apiInfo.Type);
                break;
            }

            return(null);
        }
Example #2
0
        IEnumerator GetText(GameObject go, Util.ApiInfo apiInfo)
        {
            apiInfo.ClearAllHandlers();
            apiInfo.OnAnswerReceived += (status, response) =>
            {
                apiInfo.Value = response;
                if (go != null)
                {
                    go.GetComponent <InputField>().text = "Current temperature: " + response + " C";
                }
            };

            while (true)
            {
                yield return(new WaitForSeconds(2));

                if (go == null || !go.activeInHierarchy)
                {
                    continue;
                }
                apiInfo.PerformAction();
            }
        }