Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active December 19, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/5966840 to your computer and use it in GitHub Desktop.
Save tsubaki/5966840 to your computer and use it in GitHub Desktop.
超簡易FSM。 同じオブジェクト上なら1つしかenableにならないようにする。
using UnityEngine;
public abstract class FsmAIBase : MonoBehaviour
{
void OnEnable()
{
Change();
}
protected void Change()
{
foreach(FsmAIBase c in GetComponents<FsmAIBase> ())
{
c.enabled = (c == this);
}
}
}
using UnityEngine;
public class FsmAITypeA : FsmAIBase
{
void OnGUI ()
{
GUILayout.Label ("type A true");
if (GUILayout.Button ("type B false")) {
GetComponent<FsmAITypeB> ().enabled = true;
}
if (GUILayout.Button ("type C false")) {
GetComponent<FsmAITypeC> ().enabled = true;
}
}
}
using UnityEngine;
public class FsmAITypeB : FsmAIBase
{
void OnGUI ()
{
if (GUILayout.Button ("type A false")) {
GetComponent<FsmAITypeA> ().enabled = true;
}
GUILayout.Label ("type B true");
if (GUILayout.Button ("type C false")) {
GetComponent<FsmAITypeC> ().enabled = true;
}
}
}
using UnityEngine;
public class FsmAITypeC : FsmAIBase
{
void OnGUI ()
{
if (GUILayout.Button ("type A false")) {
GetComponent<FsmAITypeA> ().enabled = true;
}
if (GUILayout.Button ("type B false")) {
GetComponent<FsmAITypeB> ().enabled = true;
}
GUILayout.Label ("type C true");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment