using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class ScreenBase : MonoBehaviour
{
protected bool canUpLoad = false;
private string screenName = "";
private AttrData data;
public string ScreenName { get { if (string.IsNullOrEmpty(screenName)) screenName = gameObject.name;return screenName; } }
private List options;
public List Options { get { if (options == null) options = GetComponentsInChildren ().ToList(); return options; } }
public int CurrentOptionIndex = 0;
[SerializeField]
private PhysicButtonContent physicButtonContent;
public PhysicButtonContent PhysicButtonContent { get { if (physicButtonContent == null) physicButtonContent = GetComponentInParent().transform.parent.GetComponentInChildren(); return physicButtonContent; } }
private CenterManage centerManage;
public CenterManage CenterManage { get { if (centerManage == null) centerManage = GetComponentInParent();return centerManage; } }
public void Init()
{
//ScreenName = gameObject.name;
}
protected virtual void OnEnable()
{
PhysicButtonContent.Confirm = Confirm;
PhysicButtonContent.PageUp = PageUp;
PhysicButtonContent.PageDown = PageDown;
PhysicButtonContent.Back = Back;
}
///
/// 向上翻
///
public virtual void PageUp()
{
if (CurrentOptionIndex - 1 >= 0)
{
Options[CurrentOptionIndex].UnSelected();
CurrentOptionIndex -= 1;
Options[CurrentOptionIndex].OnSelected();
}
}
///
/// 向下翻
///
public virtual void PageDown()
{
if (CurrentOptionIndex + 1 < Options.Count)
{
Options[CurrentOptionIndex].UnSelected();
CurrentOptionIndex += 1;
Options[CurrentOptionIndex].OnSelected();
}
}
///
/// 确认
///
public virtual void Confirm()
{
if (Options[CurrentOptionIndex].CutScreen)
{
CenterManage.CutNextScreen(this, Options[CurrentOptionIndex].name);
}
}
///
/// 返回、取消
///
public virtual void Back()
{
CenterManage.BackLastScreen(this);
}
public void SetData(AttrData data)
{
this.data = data;
}
///
/// 发送数据 由“PhysicButtonContent”反射触发
///
public virtual void GetProperty()
{
if (!canUpLoad)
{
return;
}
List parDict = new List();
var t = this.GetType();
var properties = t.GetProperties();
foreach (var property in properties)
{
if (!property.IsDefined(typeof(ParamAttribute), false)) continue;
var _name = property.Name;
var _value = property.GetValue(this);
parDict.Add(new PrarmData() { Name = _name, Value = (string)_value });
}
//构造数据
ScreenData data = new ScreenData();
data.DeviceId = GetComponentInParent().DeviceId;
data.Params = parDict;
this.data.Screen = data;
// 发送数据
Request.SendCircuitBreakerData(this.data);
}
}