备份CatanBuilding瘦身独立工程
This commit is contained in:
67
Assets/Scripts/EventPinball/PinballSwitcher.cs
Normal file
67
Assets/Scripts/EventPinball/PinballSwitcher.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user