Ejemplo n.º 1
0
        /// <summary>
        /// Switches to a different state, and handles the killing
        /// of the currently running state.
        /// </summary>
        /// <param name="key">The key of the state to enter.</param>
        public override void EnterState(string key)
        {
            StateScript script;

            if (key != null && states.TryGetValue(key, out script))
            {
                var tmp = current;
                if (tmp != null)
                {
                    tmp.OnStop(scriptEngine);
                }

                if (script.OnStart(scriptEngine))
                {
                    currentKey = key;
                    current    = script;
                }
            }
            else
            {
                var tmp = current;
                if (tmp != null)
                {
                    tmp.OnStop(scriptEngine);
                }

                currentKey = null;
                current    = null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Switches to a different state, and handles the killing
        /// of the currently running state.
        /// </summary>
        /// <param name="script">The state to enter.</param>
        public override void EnterState(StateScript script)
        {
            var tmp = current;

            if (tmp != null)
            {
                tmp.OnStop(scriptEngine);
            }

            script.parent = this;
            if (script.OnStart(scriptEngine))
            {
                currentKey = string.Empty;
                current    = script;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds a new state to switch between.
 /// </summary>
 /// <param name="key">The key that can be used to switch to the new state.</param>
 /// <param name="script">The script belonging to the state.</param>
 public void AddState(string key, StateScript script)
 {
     script.Api    = Api;
     script.parent = this;
     states.Add(key, script);
 }