Esempio n. 1
0
        //----------------------------------------------------------------------------



        //----------------------------------------------------------------------------
        void DrawNodeCurve(Rect start, Rect end, EventConnection eventCon)
        {
            nodeLocation currentNodeLocation = getNodeLocation(start, end);

            Vector3 startPos = getStartPos(start, end, currentNodeLocation, eventCon.fromToCount);
            Vector3 endPos   = getEndPos(start, end, currentNodeLocation, eventCon.fromToCount);

            eventCon.fromPT = startPos;
            eventCon.toPT   = endPos;

            float chunk = Vector3.Distance(startPos, endPos) / 2.5f;

            Vector3 startTan = getStartTan(currentNodeLocation, chunk, startPos);
            Vector3 endTan   = getEndTan(currentNodeLocation, chunk, endPos);        //endPos +  chunk*Vector3.left;;

            Color shadowCol = new Color(0, 0, 0, 0.06f);

            //Vector3 end3=new Vector3(endPos.x-(endPos.x- startPos.x)/45,endPos.y-(endPos.y- startPos.y)/45,0);

            for (int i = 0; i < 3; i++)
            {                    // Draw a shadow
                //arrow = Resources.GetBuiltinResource<Texture>("/stateMachine/Resources/arrow.png");
                Handles.DrawBezier(startPos, endPos, startTan, endTan, shadowCol, null, (i + 3) * 5);
            }
            float arrowSize = 17;
            Rect  arrowRect = new Rect(endPos.x - arrowSize / 2, endPos.y - arrowSize / 2, arrowSize, arrowSize);

            if (currentNodeLocation == nodeLocation.bottom)
            {
                arrow = (Texture2D)Resources.Load("arrowDown", typeof(Texture2D));
            }

            else
            if (currentNodeLocation == nodeLocation.top)
            {
                arrow = (Texture2D)Resources.Load("arrowUp", typeof(Texture2D));
            }
            else
            if (currentNodeLocation == nodeLocation.left)
            {
                arrow = (Texture2D)Resources.Load("arrowLeft", typeof(Texture2D));
            }
            else
            {
                arrow = (Texture2D)Resources.Load("arrowRight", typeof(Texture2D));
            }


            //GUIUtility.RotateAroundPivot(20,new Vector2(0,0));

            Handles.color = Color.white;


            //Handles.ConeCap (0,end3, Quaternion.AngleAxis(0,Vector3.down) ,11);
            //Handles.ConeCap (0,endPos, Quaternion.AngleAxis(0,Vector3.down) ,7);

            Handles.DrawBezier(startPos, endPos, startTan, endTan, Color.gray, null, 2);
            drawHandle(startPos);
            GUI.DrawTexture(arrowRect, arrow);
        }
Esempio n. 2
0
        //----------------------------------------------------------------------------


        //----------------------------------------------------------------------------
        private void resetEvent(Vector2 point)
        {
            foreach (EventConnection ec in events)
            {
                ec.selected = false;
            }
            selectedEvent = null;
        }
Esempio n. 3
0
        //----------------------------------------------------------------------------



        //----------------------------------------------------------------------------
        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);
        }
Esempio n. 4
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);
                }
            }
        }
Esempio n. 5
0
        //---------------------------------------------------------------------------------


        //----------------------------------------------------------------------------
        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;
            }
        }
Esempio n. 6
0
        //----------------------------------------------------------------------------

        //----------------------------------------------------------------------------
        private void selectEvent(Vector2 point)
        {
            selectedEvent = null;
            Vector2 pmod = new Vector2(point.x + scrollPosition.x, point.y + scrollPosition.y);

            foreach (EventConnection ec in events)
            {
                if (ec.holdsPoint(pmod))
                {
                    ec.selected    = true;
                    selectedEvent  = ec;
                    eventName      = ec.eventName;
                    eventCondition = ec.conditions;
                    eventAction    = ec.actions;
                }
                else
                {
                    ec.selected = false;
                }
            }
        }
Esempio n. 7
0
        //*********************************************************************************
        //---------------------------------------------------------------------------------

/*
 *      //----------------------------------------------------------------------------
 *      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();
                    }
                }
            }
        }