예제 #1
0
    private void CreateInput(SimulationPropertyBase property, int num)
    {
        Transform content = GetPropertiesContentArea();

        GameObject inputControl;

        if (property is SimulationBoolProperty)
        {
            inputControl = Resources.Load("InputBool") as GameObject;
        }
        else if (property is SimulationListProperty)
        {
            inputControl = Resources.Load("InputList") as GameObject;
        }
        else
        {
            inputControl = Resources.Load("InputText") as GameObject;
        }

        GameObject a = Instantiate(inputControl);

        a.transform.SetParent(content.transform);

        //a.transform.position = new Vector3(-240, 45 + -(0 + (num * 35)), 0);
        a.transform.position = new Vector3(-240, 45 + (0 + (num * 35)), 0);
        a.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -((num + 1) * 35) + 13);
        a.GetComponent <RectTransform>().pivot            = new Vector2(0, .5f);

        a.transform.Find("Label").GetComponent <Text>().text = property.Name;

        if (property is SimulationBoolProperty)
        {
            var toggle = a.GetComponentInChildren <Toggle>();

            toggle.isOn = ((SimulationBoolProperty)property).Value;
            toggle.GetComponentInChildren <Text>().text = string.Empty;
            toggle.onValueChanged.AddListener((v) => ((SimulationBoolProperty)property).Value = v);
        }
        else if (property is SimulationListProperty)
        {
            var dropdown = a.GetComponentInChildren <Dropdown>();
            dropdown.ClearOptions();

            foreach (string option in ((SimulationListProperty)property).Options)
            {
                dropdown.options.Add(new Dropdown.OptionData(option));
            }

            dropdown.value = ((SimulationListProperty)property).Value;
            dropdown.RefreshShownValue();
            dropdown.onValueChanged.AddListener((v) => ((SimulationListProperty)property).Value = v);
        }
        else
        {
            var input = a.GetComponentInChildren <InputField>();

            input.text = property.GetValue();
            input.onValueChanged.AddListener(new InputWrapper(input, property).OnChange);
        }
    }
예제 #2
0
 public InputWrapper(InputField field, SimulationPropertyBase property)
 {
     Field    = field;
     Property = property;
 }