68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace game
|
|
{
|
|
public class PinballSwitcher : MonoBehaviour
|
|
{
|
|
public Animator m_Animator;
|
|
public string m_OpenAnimation;
|
|
public string m_CloseAnimation;
|
|
public GameObject m_Collider;
|
|
|
|
#region 状态相关
|
|
private EventPinballSwitcherState m_State;
|
|
public bool IsOpen()
|
|
{
|
|
return m_State == EventPinballSwitcherState.Open;
|
|
}
|
|
#endregion
|
|
|
|
#region 动画相关
|
|
public void OpenSwitcher(EventPinballSwitcherOpen data)
|
|
{
|
|
if (m_Animator != null && !string.IsNullOrEmpty(m_OpenAnimation))
|
|
{
|
|
m_Animator.Play(m_OpenAnimation);
|
|
m_State = EventPinballSwitcherState.Open;
|
|
}
|
|
if (m_Collider != null)
|
|
{
|
|
m_Collider.SetActive(false);
|
|
}
|
|
}
|
|
public void CloseSwitcher(EventPinballSwitcherClose data)
|
|
{
|
|
if (m_Animator != null && !string.IsNullOrEmpty(m_CloseAnimation))
|
|
{
|
|
m_Animator.Play(m_CloseAnimation);
|
|
m_State = EventPinballSwitcherState.Close;
|
|
}
|
|
if (m_Collider != null)
|
|
{
|
|
m_Collider.SetActive(true);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 事件相关
|
|
public void InitEvent()
|
|
{
|
|
FishingPinballAct.Subscribe<EventPinballSwitcherOpen>(OpenSwitcher);
|
|
FishingPinballAct.Subscribe<EventPinballSwitcherClose>(CloseSwitcher);
|
|
}
|
|
#endregion
|
|
|
|
#region 生命周期
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
InitEvent();
|
|
|
|
FishingPinballAct.Publish(new EventPinballSwitcherOpen());
|
|
}
|
|
#endregion
|
|
}
|
|
}
|