コード例 #1
0
ファイル: editorFSM.cs プロジェクト: yasirmx/UmbraFeraMain
        //----------------------------------------------------------------------------


        //----------------------------------------------------------------------------
        private string getLinkedEvents(statePanel state)
        {
            List <string> links = new List <string>();

            foreach (EventConnection ec in events)
            {
                if (ec.from == state)
                {
                    links.Add(ec.id.ToString());
                }
            }

            string outString = "";

            for (int i = 0; i < links.Count; i++)
            {
                if (i > 0)
                {
                    outString = outString + ":" + links[i];
                }
                else
                {
                    outString = links[i];
                }
            }

            return(outString);
        }
コード例 #2
0
ファイル: editorFSM.cs プロジェクト: yasirmx/UmbraFeraMain
        //----------------------------------------------------------------------------

        //----------------------------------------------------------------------------
        private void selectStateReset()
        {
            foreach (statePanel sp in states)
            {
                sp.selected = false;
            }
            selectedState = null;
        }
コード例 #3
0
ファイル: editorFSM.cs プロジェクト: yasirmx/UmbraFeraMain
        //----------------------------------------------------------------------------



        //----------------------------------------------------------------------------
        private void addState()
        {
            statePanel newState = new statePanel(new Rect(startPos.x - HelperConstants.StateWidth / 2, startPos.y - HelperConstants.StateHeight / 2,
                                                          HelperConstants.StateWidth,
                                                          HelperConstants.StateHeight), stateName);

            newState.stateDiscription = stateDiscription;
            newState.id = states.Count;
            states.Add(newState);
        }
コード例 #4
0
ファイル: editorFSM.cs プロジェクト: yasirmx/UmbraFeraMain
        private void reset()
        {
            //source = null;
            states.Clear();
            events.Clear();
            attributes.Clear();
            clickCounter       = 0;
            startStateSelected = null;
            endStateSelected   = null;

            Repaint();
        }
コード例 #5
0
ファイル: editorFSM.cs プロジェクト: yasirmx/UmbraFeraMain
        //----------------------------------------------------------------------------



        //----------------------------------------------------------------------------
        int getNumberEvents(statePanel from, statePanel to, int startIndex)
        {
            int sum = 0;

            for (int i = startIndex; i < events.Count; i++)
            {
                EventConnection ec = (EventConnection)events[i];
                if (ec.from == from && ec.to == to)
                {
                    sum++;
                }
            }
            return(sum);
        }
コード例 #6
0
ファイル: editorFSM.cs プロジェクト: yasirmx/UmbraFeraMain
        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);
                }
            }
        }
コード例 #7
0
ファイル: editorFSM.cs プロジェクト: yasirmx/UmbraFeraMain
        //---------------------------------------------------------------------------------


        //----------------------------------------------------------------------------
        void deleteState(statePanel target_)
        {
            states.Remove(target_);


            for (int i = events.Count - 1; i >= 0; i--)
            {
                if (events[i].from == target_ || events[i].to == target_)
                {
                    EventConnection ec = (EventConnection)events[i];
                    events.Remove(ec);
                }
            }
            for (int i = 0; i < events.Count; i++)
            {
                events[i].id = i;
            }
        }
コード例 #8
0
 public EventConnection(statePanel start, statePanel end)
 {
     from = start;
     to   = end;
 }
コード例 #9
0
 public EventConnection(statePanel start)
 {
     from = start;
 }
コード例 #10
0
ファイル: editorFSM.cs プロジェクト: yasirmx/UmbraFeraMain
        //*********************************************************************************
        //---------------------------------------------------------------------------------

/*
 *      //----------------------------------------------------------------------------
 *      private EventConnection getConnection(Vector2 point)
 *              {
 *                      //Debug.Log("scrollPosition ["+scrollPosition.x+", "+scrollPosition.y+"]  "+point.x+",  "+point.y);
 *                      Vector2 pmod=new Vector2(point.x+scrollPosition.x,point.y+scrollPosition.y);
 *                      foreach (EventConnection ec in events)
 *                      {
 *                              if(ec.holdsPoint(pmod))return ec;
 *                      }
 *              return null;
 *              }
 *      //----------------------------------------------------------------------------
 */

        //----------------------------------------------------------------------------
        private void eventMouseMaker()
        {//...................................................................
            if (mouseUp)
            {
                Vector2 stopMousePos = Event.current.mousePosition;
                //currentPos = Event.current.mousePosition;

                bool clicked = Vector2.Distance(stopMousePos, startPos) < .5f;
                if (clicked)
                {
                    clickCounter++;
                    selectEvent(startPos);
                    Debug.Log("Clicked" + clickCounter + "  " + Vector2.Distance(stopMousePos, lastClick));
                    if (selectedEvent == null && clickCounter > 1)
                    {
                        clickCounter = 1;
                        if (Vector2.Distance(stopMousePos, lastClick) < .9f)
                        {
                            clickCounter = 0;
                            addState();
                            Repaint();
                            return;
                        }
                    }
                    if (clickCounter > 1)
                    {
                        clickCounter = 1;
                    }
                    lastClick = new Vector2(stopMousePos.x, stopMousePos.y);
                    //if(Vector2.Distance(stopMousePos,lastClick)<.9f)
                }
                else
                {
                    clickCounter = 0;
                }

                statePanel sp = getStateForPoint(stopMousePos);

                if (sp != null && startStateSelected != null && eventConDrag != null)
                {
                    endStateSelected = sp;
                    //Debug.Log("mouseUP  "+sp.stateName);
                    EventConnection newEvent = new EventConnection(startStateSelected, endStateSelected);
                    //newState.stateDiscription = stateDiscription;
                    newEvent.eventName  = eventName;
                    newEvent.id         = events.Count;
                    newEvent.conditions = eventCondition;
                    newEvent.actions    = eventAction;
                    events.Add(newEvent);
                }
                eventConDrag = null;

                //getConnection(stopMousePos);

                selectStateReset();
                Repaint();
            }
            //...................................................................
            if (mouseDown)
            {
                startPos = Event.current.mousePosition;
                Vector2 startMousePos = Event.current.mousePosition;

                statePanel sp = getStateHandleForPoint(startMousePos);
                if (sp != null)
                {
                    startStateSelected = sp;
                    eventConDrag       = new EventConnection(sp);
                }
                Repaint();
            }
            //...................................................................
            if (mouseDrag && startStateSelected != null)
            {
                Vector2 mousePos = Event.current.mousePosition;

                Vector2 pmod = new Vector2(mousePos.x + scrollPosition.x, mousePos.y + scrollPosition.y);
                mousePos = pmod;
                //if(startStateSelected!=null && eventConDrag!=null)
                if (eventConDrag != null)
                {
                    if (eventConDrag.to == null)
                    {
                        eventConDrag.to = new statePanel(new Rect(mousePos.x, mousePos.y, 5, 5), "temp");
                    }
                    else
                    {
                        eventConDrag.to.location.x = mousePos.x;
                        eventConDrag.to.location.y = mousePos.y;


                        selectState(mousePos);
                        //}

                        Repaint();
                    }
                }
            }
        }