Exemple #1
0
        //----------------------------------------------------------------------------



        //----------------------------------------------------------------------------
        public void Update()
        {
            if (justRecompiled)
            {
                justRecompiled = false;
                needUpdate     = false;
                loadFSM(HelperFile.getTextFileFromResource(filename));

                if (needToAddControllerScript)
                {
                    needToAddControllerScript = false;
                    GameObject o = (GameObject)source;
                    o.AddComponent(controllerName);
                }
            }

            if (source != null && Application.isPlaying)
            {
                GameObject sco = (GameObject)source;
                if (sco != null)
                {
                    stateController sc = sco.GetComponent <stateController>();
                    if (sc.myStateMachine != null)
                    {
                        if (sc.myStateMachine.state != null)
                        {
                            currentState           = sc.myStateMachine.state.name;
                            currentStateController = sc;
                            Repaint();
                        }
                    }
                }
            }
        }
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();
        }