Exemple #1
0
        private void loadFSM(string FSM)
        {
            reset();
            //string line = FSM.Replace(" ","");
            string line = HelperFormater.stripComments(FSM.Split('\n'));

            string[] parts = line.Split('|');

            string[] stateParts     = parts[0].Split(';');
            string[] attributeParts = parts[1].Split(';');
            string[] eventParts     = parts[2].Split(';');

            for (int i = 0; i < stateParts.Length; i++)
            {
                states.Add(new statePanel(stateParts[i]));
            }


            for (int i = 0; i < attributeParts.Length; i++)
            {
                string[] s = attributeParts[i].Split('=');
                if (s.Length > 1)
                {
                    attributes.Add(new AttributePair(s[0], s[1]));
                }
            }
            //name,id,to,cond,action
            for (int i = 0; i < eventParts.Length; i++)
            {
                string[] s = eventParts[i].Split(',');
                if (s.Length > 3)
                {
                    //Debug.Log("EVENT="+eventParts[i]);
                    int        id_   = int.Parse(s[1]);
                    string     name_ = s[0];
                    statePanel from_ = getStateFrom(id_);
                    statePanel to_   = states[int.Parse(s[2])];

                    EventConnection ec = new EventConnection(from_, to_);
                    ec.eventName  = name_;
                    ec.id         = id_;
                    ec.conditions = s[3];
                    ec.actions    = s[4];
                    events.Add(ec);
                }
            }
        }
Exemple #2
0
        //----------------------------------------------------------------------------



        //----------------------------------------------------------------------------
        void fileControlPanel(Vector2 point)
        {
            HelperEditor.DrawColorBox(new Rect(point.x - 7, point.y - 7, 204, 274), Color.gray);
            HelperEditor.DrawColorBox(new Rect(point.x - 5, point.y - 5, 200, 270), new Color(.15f, .15f, .15f));

            GUI.Label(new Rect(point.x, point.y, 150, 20), "Resource Directory");
            resourcesDirectory = GUI.TextField(new Rect(point.x, point.y + 20, 180, 20), resourcesDirectory);

            GUI.Label(new Rect(point.x, point.y + 45, 200, 20), "Resource Filename");
            filename = GUI.TextField(new Rect(point.x, point.y + 65, 150, 20), filename);



            GUILayout.BeginArea(new Rect(point.x, point.y + 90, 80, 50));
            if (GUILayout.Button("SAVE FSM"))
            {
                Debug.Log(("SAVE FSM " + Application.dataPath + resourcesDirectory));
                save();
                HelperFile.saveToFile(Application.dataPath + resourcesDirectory + "/" + filename + ".txt", getFSMString());

                //AssetDatabase.ImportAsset(Application.dataPath + resourcesDirectory+"/"+filename+".txt");
                //loadFSM(HelperFile.getTextFileFromResource(filename));
                Repaint();
            }            //
            GUILayout.EndArea();

            GUILayout.BeginArea(new Rect(point.x + 100, point.y + 90, 80, 50));
            if (GUILayout.Button("LOAD FSM"))
            {
                Debug.Log(("LOAD FSM " + Application.dataPath + resourcesDirectory));
                save();
                //HelperFile.saveToFile(Application.dataPath + resourcesDirectory+"/"+filename+".txt",getFSMString());

                string filestring = HelperFile.getTextFileFromResource(filename);
                //filestring = EditorGUILayout.ObjectField(filestring,typeof(object), true);


                if (filestring.Length > 3)
                {
                    loadFSM(filestring);
                }
            }
            GUILayout.EndArea();



            GUI.Label(new Rect(point.x, point.y + 130, 200, 20), "Controller name");

            controllerName = GUI.TextField(new Rect(point.x, point.y + 150, 180, 20), controllerName);

            GUILayout.BeginArea(new Rect(point.x, point.y + 175, 100, 50));
            if (GUILayout.Button("Build Controller"))
            {
                if (controllerName == "stateController")
                {
                    controllerName = controllerName + "1";
                }
                Debug.Log("Make Controller: " + Application.dataPath + "/" + controllerName);
                save();
                HelperFile.saveToFile(Application.dataPath + "/stateMachine/Controllers/" + controllerName + ".cs", HelperFormater.makeFileUsing(controllerName, filename, states));

                //AssetDatabase.ImportAsset(Application.dataPath+"/"+controllerName+".cs");
                //loadFSM(HelperFile.getTextFileFromResource(filename));

                //if(currentStateController == null)
                if (source == null)
                {
                    Debug.Log("No controller selected");
                    GameObject o = new GameObject();
                    o.name = controllerName;
                    source = o;
                    needToAddControllerScript = true;
                    AssetDatabase.Refresh();                    //
                    //GameObject go = (GameObject)Instantiate(o);
                    //o.AddComponent(controllerName);//
                }
                else
                {
                    GameObject so    = (GameObject)source;
                    object     testO = so.GetComponent(controllerName);
                    if (testO == null)
                    {
                        needToAddControllerScript = true;
                        AssetDatabase.Refresh();                        //
                    }
                }

                Repaint();
            }
            GUILayout.EndArea();
            string beforeSource = "";

            if (source != null)
            {
                beforeSource = source.name;
            }
            GUI.Label(new Rect(point.x, point.y + 210, 200, 20), "Target");
            GUILayout.BeginArea(new Rect(point.x + 50, point.y + 210, 135, 50));
            source = EditorGUILayout.ObjectField(source, typeof(GameObject), true);
            GUILayout.EndArea();
            if (source != null)
            {
                if (source.name != beforeSource)
                {
                    PlayerPrefs.SetString("target", source.name);
                    PlayerPrefs.Save();
                    GameObject      o      = (GameObject)source;
                    stateController tempSC = o.GetComponent <stateController>();
                    if (tempSC != null)
                    {
                        controllerName = getShortName(tempSC.ToString());
                        PlayerPrefs.SetString("controllerName", controllerName);
                        PlayerPrefs.Save();
                    }
                }
            }
            //

            GUILayout.BeginArea(new Rect(point.x, point.y + 240, 100, 50));
            if (GUILayout.Button("Clear Screen"))
            {
                reset();
            }
            GUILayout.EndArea();
        }