개발/WHITE POLYGON
[퍼즐게임] WHITE POLYGON - 5
ssong_dev
2022. 7. 19. 11:13
회전 퀘스트에 대해 옵저버 패턴을 적용하였다.
public interface RotateEndObservable
{
public void SubscribeEvent(RotateObserver observer);
public void UnSubscribeEvent(RotateObserver observer);
public void Notify();
}
public interface RotateObserver
{
public void UpdateObserver(Cube cube);
}
이렇게 두 인터페이스를 만들어 두고
회전이 끝날 때에 구독 옵저버의 퀘스트 클리어 함수가 실행되도록 하였다.
public class Cube : RotatableObj, RotateEndObservable
{
[Header("CubeType Object Wall Check")]
[SerializeField]
protected Vector2 wallNBottomNumSetting;
public Vector2 wallNBottomNowState;
public List<RotateObserver> observerList;
public override void Awake()
{
observerList = new List<RotateObserver>();
}
public void SubscribeEvent(RotateObserver observer)
{
observerList.Add(observer);
}
public void UnSubscribeEvent(RotateObserver observer)
{
observerList.Remove(observer);
}
public void Notify()
{
for (int i = 0; i < observerList.Count; i++)
{
observerList[i].UpdateObserver(this);
}
}
//...중략
public virtual void RotateEndCheck()
{
float angle = Quaternion.Angle(gameObject.transform.rotation, m_qTartgetRotation);
if (angle <= 0)
{
//회전 완료
gameObject.transform.rotation = m_qTartgetRotation;
rotateStart = false;
Notify();
}
}
}
회전이 끝난 후 이벤트가 잘 실행된다.