64 lines
1.2 KiB
C#
64 lines
1.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Device_Switch : Device_Base
|
|
{
|
|
public bool isOpen;
|
|
|
|
/// <summary>
|
|
/// 操作开关事件
|
|
/// </summary>
|
|
private Action<bool> actionBack;
|
|
|
|
/// <summary>
|
|
/// 添加开关操作回调
|
|
/// </summary>
|
|
/// <param name="actionBack"></param>
|
|
public void AddAction(Action<bool> actionBack)
|
|
{
|
|
this.actionBack= actionBack;
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
if(isOpen)
|
|
{
|
|
isOpen = false;
|
|
transform.localEulerAngles = new Vector3(45, 0, 0);
|
|
}
|
|
else
|
|
{
|
|
isOpen = true;
|
|
transform.localEulerAngles = new Vector3(0, 0, 0);
|
|
}
|
|
|
|
//调用自定义事件
|
|
if (actionBack != null)
|
|
{
|
|
actionBack.Invoke(isOpen);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开关打开状态
|
|
/// </summary>
|
|
public void OpenState()
|
|
{
|
|
isOpen = true;
|
|
transform.localEulerAngles = new Vector3(0, 0, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开关关闭状态
|
|
/// </summary>
|
|
public void CloseState()
|
|
{
|
|
isOpen = false;
|
|
transform.localEulerAngles = new Vector3(45, 0, 0);
|
|
}
|
|
|
|
|
|
}
|