Last active
December 19, 2015 14:09
-
-
Save tsubaki/5966840 to your computer and use it in GitHub Desktop.
超簡易FSM。 同じオブジェクト上なら1つしかenableにならないようにする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public abstract class FsmAIBase : MonoBehaviour | |
{ | |
void OnEnable() | |
{ | |
Change(); | |
} | |
protected void Change() | |
{ | |
foreach(FsmAIBase c in GetComponents<FsmAIBase> ()) | |
{ | |
c.enabled = (c == this); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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