Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class State : MonoBehaviour {
- public StateMachine Machine;
- public static implicit operator bool (State state) {
- return state != null;
- }
- public void Initialize (StateMachine machine) {
- Machine = machine;
- OnStateInitialize (machine);
- }
- protected virtual void OnStateInitialize (StateMachine machine = null) {
- }
- public void StateEnter () {
- enabled = true;
- OnStateEnter ();
- }
- protected virtual void OnStateEnter () {
- }
- public void StateExit () {
- OnStateExit ();
- enabled = false;
- }
- protected virtual void OnStateExit () {
- }
- public void OnEnable () {
- if (this != Machine.GetCurrentState) {
- enabled = false;
- }
- }
- public void OnDisable () {
- if (this == Machine.GetCurrentState) {
- enabled = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement