using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class PhysicButtonContent : MonoBehaviour { //public static PhysicButtonContent Instance; public /*static*/ Action Confirm; public /*static*/ Action PageUp; public /*static*/ Action PageDown; public /*static*/ Action Back; public Paddle paddle; public bool b_Open; public GameObject PowerLight, CloseLigth, OpenLight; private Material powerMat, closeMat, openMat; public string SwitchName; private void Awake() { //Instance = this; } private void Start() { powerMat = PowerLight.GetComponent().material; closeMat = CloseLigth.GetComponent().material; openMat = OpenLight.GetComponent().material; //初始状态 if (b_Open) { closeMat.EnableKeyword("_EMISSION"); openMat.DisableKeyword("_EMISSION"); } else { closeMat.DisableKeyword("_EMISSION"); openMat.EnableKeyword("_EMISSION"); } DeviceStateManage.UpdateDeviceState(new DLQ() { Name = SwitchName, Gate = b_Open }); } public /*static*/ void OnPhysicButtonDown(PhysicButtonType _type) { Debug.Log("Press Button : " + _type.ToString()); switch (_type) { case PhysicButtonType.Confirm: Confirm?.Invoke(); // 发射发送数据 var target = Confirm.Target; var targetType = target.GetType(); targetType.GetMethod("GetProperty").Invoke(target, null); break; case PhysicButtonType.PageUp: PageUp?.Invoke(); break; case PhysicButtonType.PageDown: PageDown?.Invoke(); break; case PhysicButtonType.Back: Back?.Invoke(); break; case PhysicButtonType.trialJump: //试跳 //Instance.TrialJump(); TrialJump(); break; case PhysicButtonType.OperateSwitch: //分合闸 //Instance.OperationSwitch(); OperationSwitch(); break; default: break; } } void TrialJump() { Debug.Log("试跳"); } void OperationSwitch() { Debug.Log("分合闸"); if (paddle.isOpening) return; if (!turn) { turn = true; Invoke("Turn", 2f); } } bool turn; /// /// 分闸、合闸跳转 /// public void Turn() { turn = false; b_Open = !b_Open; if (b_Open) { closeMat.EnableKeyword("_EMISSION"); openMat.DisableKeyword("_EMISSION"); } else { closeMat.DisableKeyword("_EMISSION"); openMat.EnableKeyword("_EMISSION"); } DeviceStateManage.UpdateDeviceState(new DLQ() { Name = SwitchName, Gate = b_Open }); } }