public static string GetStateParentChildInitializer(StateMachineDefinition def, int index)
        {
            string str   = "";
            var    state = def.states[index];
            string p     = state.parent;

            if (p != null && p.Length > 0)
            {
                var parent = def.GetState(p);
                if (parent != null && parent.hasChildren)
                {
                    str += "        state" + state.name + ".parent = state" + p + ";\n";
                    str += "        state" + state.name + ".parentMachine = state" + p + ".subMachine;\n";
                }
                else
                {
                    Debug.LogWarning("State " + state.name + " has non-existant parent " + p + ".");
                    str += "        state" + state.name + ".parentMachine = rootMachine;\n";
                }
            }
            else
            {
                str += "        state" + state.name + ".parentMachine = rootMachine;\n";
            }

            if (state.hasChildren)
            {
                var children = def.GetChildren(state.name);

                if (children.Count > 0)
                {
                    StateMachineDefinition.State defState = null;
                    foreach (var child in children)
                    {
                        if (child.name == state.localDefault)
                        {
                            defState = child;
                            break;
                        }
                    }

                    if (defState == null)
                    {
                        defState = children[0];
                    }

                    str += "        state" + state.name + ".subMachine.defaultState = state" + defState.name + ";\n";
                }
            }

            return(str);
        }
        public static string GetStateInitializer(StateMachineDefinition def, int index)
        {
            var    state    = def.states[index];
            string variable = "state" + state.name;

            string str = "        State " + variable + " = new State() {\n";

            str += "            id = StateID." + state.name + ",\n";

            if (state.hasEnter)
            {
                str += "            enter = StateEnter_" + state.name + ",\n";
            }

            if (state.hasDuring)
            {
                str += "            during = State_" + state.name + ",\n";
            }

            if (state.hasExit)
            {
                str += "            exit = StateExit_" + state.name + ",\n";
            }

            if (state.hasChildren && def.GetChildren(state.name).Count > 0)
            {
                str += "            subMachine = new SubStateMachine(),\n";
            }

            str += "            transitions = new List<Transition>(" + (state.transitions == null ? 0 : state.transitions.Count) + ")\n";
            str += "        };\n";
            str += "        allStates[" + index + "] = " + variable + ";\n";

            str += "\n";
            return(str);
        }