1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class TestInput : MonoBehaviour
- {
- public InputField inputField;
- public RectTransform parent;
- public RectTransform item;
- public GameObject linedown;
- public string[] content;
- void Start()
- {
- content = new string[] { "给水压力", "给水温度", "给水流量", "给水电动调节阀", "烟气压力","烟气温度","燃油压力","燃油流量","燃油阀开度","进风压力",
- "进风温度","风机频率","锅筒给水温度","锅筒给水压力","锅筒给水流量","过热蒸汽压力","过热蒸汽温度","过热蒸汽流量","过热蒸汽安全阀开度",
- "上锅筒压力","饱和蒸汽温度","上锅筒水温","上锅筒水位","上锅筒安全阀开度"};
- inputField.onValueChanged.AddListener((value) =>
- {
- if (value == "")
- {
- linedown.SetActive(false);
- }
- else
- {
- linedown.SetActive(true);
- }
-
- if (parent.childCount > 1)
- {
- for (int i = 1; i < parent.childCount; i++)
- {
- DestroyImmediate(parent.GetChild(i).gameObject);
- }
- }
- if (!string.IsNullOrEmpty(value))
- {
- if (parent.childCount > 1)
- {
- for (int i = 1; i < parent.childCount; i++)
- {
- DestroyImmediate(parent.GetChild(i).gameObject);
- }
- }
- foreach (var ch in content)
- {
- //关键比对代码
- if (ch.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
- {
- RectTransform rt = Instantiate(item, parent);
- rt.GetChild(0).GetComponent<Text>().text = ch;
- rt.GetComponent<Toggle>().isOn = true; //怎么准确获取到呢
- rt.GetComponent<Toggle>().onValueChanged.AddListener((value) =>
- {
- //发送事件同步变化,发送value
-
- });
- rt.gameObject.SetActive(true);
- }
- }
- }
- else
- {
- if (parent.childCount > 1)
- {
- for (int i = 1; i < parent.childCount; i++)
- {
- DestroyImmediate(parent.GetChild(i).gameObject);
- }
- }
- }
- });
- }
- }
|