上海苏宁宝丽嘉酒店,2020.11.17 15:30改为单机版本,以后合成单机版本可以以此版本为模板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

193 lines
6.0 KiB

using AX.MessageSystem;
using System;
using UnityEngine;
using UnityEngine.UI;
public class CarItemAttribute : MonoBehaviour
{
CarAttributeBase mCarAttri;
public CarAttributeRecord CarAttributeRecord;
private Text mName;
/// <summary>
/// 消防员
/// </summary>
private InputField mFireMansInput;
/// <summary>
/// 水
/// </summary>
private InputField mWaterInput;
/// <summary>
/// 泡沫
/// </summary>
private InputField mBubbleInput;
/// <summary>
/// 压力
/// </summary>
private InputField mPressureInput;
/// <summary>
/// 有举臂车类型所能达到的高度
/// </summary>
private InputField mHeightInput;
/// <summary>
/// 干粉量
/// </summary>
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<Text>();
mFireMansInput = TransformHelper.FindChild(transform, "FireFighter").GetComponent<InputField>();
mFireMansInput.onEndEdit.AddListener(FireManNumChange);
mWaterInput = TransformHelper.FindChild(transform, "Water").GetComponent<InputField>();
mWaterInput.onEndEdit.AddListener(WaterChange);
mBubbleInput = TransformHelper.FindChild(transform, "Bubble").GetComponent<InputField>();
mBubbleInput.onEndEdit.AddListener(BubbleChange);
mDryPowerInput = TransformHelper.FindChild(transform, "DryPowder").GetComponent<InputField>();
mDryPowerInput.onEndEdit.AddListener(DryPowderChange);
mHeightInput = TransformHelper.FindChild(transform, "Height").GetComponent<InputField>();
mHeightInput.onEndEdit.AddListener(HeightChange);
mPressureInput = TransformHelper.FindChild(transform, "Pressure").GetComponent<InputField>();
mPressureInput.onEndEdit.AddListener(PressureChange);
SelectedToggle = transform.Find("Selected").GetComponent<Toggle>();
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;
}
/// <summary>
/// 初始化属性值跟编辑状态
/// </summary>
private void InitCarAttriValue()
{
mCarAttri = CarAttributeRecord.CarAttributeBase;
GetComponentInChildren<Toggle>().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<Toggle>().isOn)
CarAttributeRecord.CarAttributeBase = mCarAttri;
}
}