using AX.MessageSystem; using System; using UnityEngine; using UnityEngine.UI; public class CarItemAttribute : MonoBehaviour { CarAttributeBase mCarAttri; public CarAttributeRecord CarAttributeRecord; private Text mName; /// /// 消防员 /// private InputField mFireMansInput; /// /// 水 /// private InputField mWaterInput; /// /// 泡沫 /// private InputField mBubbleInput; /// /// 压力 /// private InputField mPressureInput; /// /// 有举臂车类型所能达到的高度 /// private InputField mHeightInput; /// /// 干粉量 /// private InputField mDryPowerInput; private Toggle SelectedToggle; private void Awake() { Init(); } void Start() { InitCarAttriValue(); } void OnEnable() { if (mCarAttri != null) InitCarAttriValue(); } void Init() { mName = TransformHelper.FindChild(transform, "Name").GetComponent(); mFireMansInput = TransformHelper.FindChild(transform, "FireFighter").GetComponent(); mFireMansInput.onEndEdit.AddListener(FireManNumChange); mWaterInput = TransformHelper.FindChild(transform, "Water").GetComponent(); mWaterInput.onEndEdit.AddListener(WaterChange); mBubbleInput = TransformHelper.FindChild(transform, "Bubble").GetComponent(); mBubbleInput.onEndEdit.AddListener(BubbleChange); mDryPowerInput = TransformHelper.FindChild(transform, "DryPowder").GetComponent(); mDryPowerInput.onEndEdit.AddListener(DryPowderChange); mHeightInput = TransformHelper.FindChild(transform, "Height").GetComponent(); mHeightInput.onEndEdit.AddListener(HeightChange); mPressureInput = TransformHelper.FindChild(transform, "Pressure").GetComponent(); mPressureInput.onEndEdit.AddListener(PressureChange); SelectedToggle = transform.Find("Selected").GetComponent(); SelectedToggle.onValueChanged.AddListener(Selected); } private void PressureChange(string arg0) { float value; if (!float.TryParse(arg0, out value)) return; mPressureInput.text = value <= 0 ? "0" : value.ToString(); mCarAttri.HasPressure = value; } private void HeightChange(string arg0) { float value; if (!float.TryParse(arg0, out value)) return; mHeightInput.text = value <= 0 ? "0" : value.ToString(); mCarAttri.Height = value; } private void DryPowderChange(string arg0) { float value; if (!float.TryParse(arg0, out value)) return; mDryPowerInput.text = value <= 0 ? "0" : value.ToString(); mCarAttri.HasDryPowder = value; } private void BubbleChange(string arg0) { float value; if (!float.TryParse(arg0, out value)) return; mBubbleInput.text = value <= 0 ? "0" : value.ToString(); mCarAttri.HasBubble = value; } private void WaterChange(string arg0) { float value; if (!float.TryParse(arg0, out value)) return; mWaterInput.text = value <= 0 ? "0" : value.ToString(); mCarAttri.HasWater = value; } private void FireManNumChange(string arg0) { int value; if (!int.TryParse(arg0, out value)) return; mFireMansInput.text = value <= 0 ? "0" : value.ToString(); mCarAttri.FireManNum = value; } private void Selected(bool arg0) { mFireMansInput.interactable = arg0 ? mFireMansInput.text.Contains("-") ? false : arg0 : arg0; mWaterInput.interactable = arg0 ? mWaterInput.text.Contains("-") ? false : arg0 : arg0; mBubbleInput.interactable = arg0 ? mBubbleInput.text.Contains("-") ? false : arg0 : arg0; mDryPowerInput.interactable = arg0 ? mDryPowerInput.text.Contains("-") ? false : arg0 : arg0; mHeightInput.interactable = arg0 ? mHeightInput.text.Contains("-") ? false : arg0 : arg0; mPressureInput.interactable = arg0 ? mPressureInput.text.Contains("-") ? false : arg0 : arg0; } /// /// 初始化属性值跟编辑状态 /// private void InitCarAttriValue() { mCarAttri = CarAttributeRecord.CarAttributeBase; GetComponentInChildren().isOn = false; mName.text = CloneObjName.Instance.GetCloneNameByType(CarAttributeRecord.CarType); mFireMansInput.text = mCarAttri.FireManNum.ToString(); mFireMansInput.interactable = false; if (mCarAttri.HasWater == -1) { mWaterInput.text = "-"; } else { mWaterInput.text = mCarAttri.HasWater.ToString(); } mWaterInput.interactable = false; if (mCarAttri.HasBubble == -1) { mBubbleInput.text = "-"; } else { mBubbleInput.text = mCarAttri.HasBubble.ToString(); } mBubbleInput.interactable = false; if (mCarAttri.HasDryPowder == -1) { mDryPowerInput.text = "-"; } else { mDryPowerInput.text = mCarAttri.HasDryPowder.ToString(); } mDryPowerInput.interactable = false; if (mCarAttri.Height == -1) { mHeightInput.text = "-"; } else { mHeightInput.text = mCarAttri.Height.ToString(); } mHeightInput.interactable = false; if (mCarAttri.HasPressure == -1) { mPressureInput.text = "-"; } else { mPressureInput.text = mCarAttri.HasPressure.ToString(); } mPressureInput.interactable = false; } public void Submit() { if (GetComponentInChildren().isOn) CarAttributeRecord.CarAttributeBase = mCarAttri; } }