38 lines
No EOL
1.1 KiB
C#
38 lines
No EOL
1.1 KiB
C#
using System;
|
|
using Patterns_And_Principles.Patterns.The_State_Pattern.Script.State;
|
|
using UnityEngine;
|
|
|
|
namespace Patterns_And_Principles.Patterns.The_State_Pattern.Script.Manager
|
|
{
|
|
public class AppleStateManager : MonoBehaviour
|
|
{
|
|
private AppleBaseState _currentState;
|
|
public AppleGrowingState _growingState = new AppleGrowingState();
|
|
public AppleChewedState _chewedState = new AppleChewedState();
|
|
public AppleRottenState _rottenState = new AppleRottenState();
|
|
public AppleWholeState _wholeState = new AppleWholeState();
|
|
|
|
private void OnCollisionEnter(Collision other)
|
|
{
|
|
_currentState.OnCollisionEnter(this, other);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
//Start state machine
|
|
_currentState = _growingState;
|
|
_currentState.EnterState(this);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
_currentState.UpdateState(this);
|
|
}
|
|
|
|
public void SwitchState(AppleBaseState newState)
|
|
{
|
|
_currentState = newState;
|
|
newState.EnterState(this);
|
|
}
|
|
}
|
|
} |