Mode controller?

About a year ago I stumbled upon a concept in Unity scripting that I can’t seem to find. I’ve tried searching, but my memory is too vague to narrow down the search terms.

The concept is something like this:

  1. You create a series of functions that serve as game modes. (I remember the documentation of this saying something about how this function declaration is shorthand for defining a class, which the compiler makes it into behind the scenes)
  2. Game logic can then set these modes as enabled or disabled
  3. These modes had their own update/OnGUI parameters so you could run multiple states of one system through one script file. I think the example shows how this can be used to control menu popups in a game (different menus pop up depending upon which one of these modes is active). I know when I played around with it a year ago I had used it to define control schemes for each game mode.

It wasn’t just a generic finite state machine concept. I don’t remember if it was specific to js or c#.

I was tinkering with running a AI mood controller using something similar. Basically it managed multiple different characters through gui’s. This was all based on a GUI window model that I built…

http://forum.unity3d.com/threads/73139-Utility-Window

I am sure it is basic and not exactly what you are looking for but it is along the same lines as what you are talking about.

Thanks, but that’s not it.

Edit: To be more specific, this isn’t a design methodology. It’s a particular function/directive/keyword that Unity has that lets you define a function that contains its own versions of things like OnGUI() that only runs when that “mode” is enabled.

It’s been too long and I no longer have the files, but I want to say the code ends up looking something like this:

class Foo (){

     (Unknown Type) state1 = Bar1();
     (Unknown Type) state2 = Bar2();

     function Start(){
           state1.active = true;
     }

     function Bar1(){
           OnGUI(){
                if( GUIButton("Button1") ){
                        state1.active=false;
                        state2.active=true;
                }
           }
     }

     function Bar2(){
            OnGUI(){
                  if(GUIButton("Button2") ){
                       Application.Quit();
                  }
            }
     }
}

The implication being, Button 2 doesn’t show up unless state2 is active. I know there are dozens of ways to implement that functionality, I’m asking if anyone knows what this specific implementation is. This isn’t workable code in any way, it’s just a rough layout as I remember it.

Answered my own question.

Delegates.