114 lines
3.3 KiB
C#
114 lines
3.3 KiB
C#
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<Option> options;
|
||
public List<Option> Options { get { if (options == null) options = GetComponentsInChildren<Option>().ToList(); return options; } }
|
||
|
||
public int CurrentOptionIndex = 0;
|
||
|
||
[SerializeField]
|
||
private PhysicButtonContent physicButtonContent;
|
||
public PhysicButtonContent PhysicButtonContent { get { if (physicButtonContent == null) physicButtonContent = GetComponentInParent<Canvas>().transform.parent.GetComponentInChildren<PhysicButtonContent>(); return physicButtonContent; } }
|
||
|
||
private CenterManage centerManage;
|
||
public CenterManage CenterManage { get { if (centerManage == null) centerManage = GetComponentInParent<CenterManage>();return centerManage; } }
|
||
public void Init()
|
||
{
|
||
//ScreenName = gameObject.name;
|
||
}
|
||
|
||
protected virtual void OnEnable()
|
||
{
|
||
PhysicButtonContent.Confirm = Confirm;
|
||
PhysicButtonContent.PageUp = PageUp;
|
||
PhysicButtonContent.PageDown = PageDown;
|
||
PhysicButtonContent.Back = Back;
|
||
}
|
||
|
||
/// <summary>
|
||
/// ÏòÉÏ·
|
||
/// </summary>
|
||
public virtual void PageUp()
|
||
{
|
||
if (CurrentOptionIndex - 1 >= 0)
|
||
{
|
||
Options[CurrentOptionIndex].UnSelected();
|
||
CurrentOptionIndex -= 1;
|
||
Options[CurrentOptionIndex].OnSelected();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// ÏòÏ·
|
||
/// </summary>
|
||
public virtual void PageDown()
|
||
{
|
||
if (CurrentOptionIndex + 1 < Options.Count)
|
||
{
|
||
Options[CurrentOptionIndex].UnSelected();
|
||
CurrentOptionIndex += 1;
|
||
Options[CurrentOptionIndex].OnSelected();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// È·ÈÏ
|
||
/// </summary>
|
||
public virtual void Confirm()
|
||
{
|
||
if (Options[CurrentOptionIndex].CutScreen)
|
||
{
|
||
CenterManage.CutNextScreen(this, Options[CurrentOptionIndex].name);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// ·µ»Ø¡¢È¡Ïû
|
||
/// </summary>
|
||
public virtual void Back()
|
||
{
|
||
CenterManage.BackLastScreen(this);
|
||
}
|
||
|
||
public void SetData(AttrData data)
|
||
{
|
||
this.data = data;
|
||
}
|
||
/// <summary>
|
||
/// ·¢ËÍÊý¾Ý ÓÉ¡°PhysicButtonContent¡±·´Éä´¥·¢
|
||
/// </summary>
|
||
public virtual void GetProperty()
|
||
{
|
||
if (!canUpLoad)
|
||
{
|
||
return;
|
||
}
|
||
List<PrarmData> parDict = new List<PrarmData>();
|
||
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<DevicesBase>().DeviceId;
|
||
data.Params = parDict;
|
||
|
||
this.data.Screen = data;
|
||
// ·¢ËÍÊý¾Ý
|
||
Request.SendCircuitBreakerData(this.data);
|
||
}
|
||
} |