Exemplo n.º 1
0
        /// <summary>
        /// 分类,相同的分到一个StateTransitionArrowLine里
        /// </summary>
        /// <param name="transitions"></param>
        /// <returns></returns>
        public static StateTransitionArrowLine[] CreateStateTransitionArrowLines(List <StateTransition> transitions)
        {
            List <StateTransition>          tempLists = new List <StateTransition>(transitions);
            List <StateTransitionArrowLine> list      = new List <StateTransitionArrowLine>();
            StateTransition tempT = null;

            while (tempLists.Count > 0)
            {
                StateTransitionArrowLine line = ScriptableObject.CreateInstance <StateTransitionArrowLine>();
                tempT = tempLists[0];
                tempLists.RemoveAt(0);

                for (int i = 0; i < tempLists.Count; i++)
                {
                    StateTransition t = tempLists[i];
                    if (t.fromState == tempT.fromState && t.toState == tempT.toState)
                    {
                        line.transitions.Add(t);
                    }
                }
                for (int i = 0; i < line.transitions.Count; i++)
                {
                    tempLists.Remove(line.transitions[i]);
                }
                line.transitions.Add(tempT);

                list.Add(line);
            }

            return(list.ToArray());
        }
        private static void MouseSelectObject()
        {
            Event e = Event.current;

            if (e.button == 0 && e.type == EventType.MouseDown)
            {
                if (StateMachineBGGUI.controlWindowRange.Contains(e.mousePosition))
                {
                    bool isSelect = false;
                    foreach (var item in MachineStateGUIDataControl.allMachineStateGUI)
                    {
                        if (StateMachineUtils.MachineGridRectContainsMousePos(e.mousePosition, item.GUIRect))
                        {
                            isSelect = true;
                            SelectObjectController.SelectItemObject(item);
                            break;
                        }
                    }
                    if (!isSelect)
                    {
                        StateTransitionArrowLine line = StateTransitionArrowLineDataControl.FindClosestStateTransitionArrowLine(e.mousePosition);
                        if (line)
                        {
                            isSelect = true;
                            SelectObjectController.SelectItemObject(line);
                        }
                    }
                    if (isSelect == false)
                    {
                        SelectObjectController.SelectObjectCancel();
                    }
                    e.Use();
                }
            }
        }
        public static Dictionary <StateTransitionArrowLine, StateTransitionArrowLine> StateTransitionArrowLinesToGrouping()
        {
            Dictionary <StateTransitionArrowLine, StateTransitionArrowLine> dic = new Dictionary <StateTransitionArrowLine, StateTransitionArrowLine>();
            List <StateTransitionArrowLine> linesList = new List <StateTransitionArrowLine>(allStateTransitionArrowLineList);

            StateTransitionArrowLine tempOne = null;
            StateTransitionArrowLine tempTwo = null;

            //dic.Add(temp,null);
            while (linesList.Count > 0)
            {
                tempOne = linesList[0];
                linesList.RemoveAt(0);
                tempTwo = null;
                for (int i = 0; i < linesList.Count; i++)
                {
                    StateTransitionArrowLine s = linesList[i];
                    if (s.transitions[0].fromState == tempOne.transitions[0].toState && s.transitions[0].toState == tempOne.transitions[0].fromState)
                    {
                        tempTwo = s;
                        break;
                    }
                }
                if (tempTwo != null)
                {
                    linesList.Remove(tempTwo);
                }
                dic.Add(tempOne, tempTwo);
            }

            return(dic);
        }
        public static StateTransitionArrowLine FindClosestStateTransitionArrowLine(Vector2 mousePosition)
        {
            Vector2 v2 = StateMachineUtils.MousePos2MachineGridPos(mousePosition);

            StateTransitionArrowLine result = null;
            float lenth = float.PositiveInfinity;

            foreach (var item in allStateTransitionArrowLineList)
            {
                float temoLenth;
                if (item.IsLineSelf)
                {
                    temoLenth = Vector2.Distance(item.LineSelfOneTrianglePoints[3], v2);
                }
                else
                {
                    temoLenth = HandleUtility.DistancePointLine(v2, item.UseFormLinePosition, item.UseToLinePosition);
                }

                if (temoLenth < lenth && temoLenth < 10)
                {
                    lenth  = temoLenth;
                    result = item;
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        protected override void OnHeaderGUI()
        {
            if (line == null)
            {
                line = (StateTransitionArrowLine)target;
            }
            if (line.transitions.Count == 0)
            {
                return;
            }
            EditorGUIUtility.SetIconSize(Vector2.one * 32);
            GUIContent cc = EditorGUIUtility.IconContent("d_UnityEditor.VersionControl");

            cc.text = "";
            GUILayout.BeginHorizontal("LargeButton");
            GUILayout.Space(5);
            GUILayout.Label(cc);

            GUILayout.BeginVertical();
            GUILayout.Space(2);
            MachineStateGUI mag0 = MachineStateGUIDataControl.GetMachineStateGUI(line.transitions[0].fromState);
            MachineStateGUI mag1 = MachineStateGUIDataControl.GetMachineStateGUI(line.transitions[0].toState);

            GUILayout.Label(mag0.name + " -> " + mag1.name);
            GUILayout.Space(2);
            GUILayout.Label(line.transitions.Count + " Transitions");
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
Exemplo n.º 6
0
        public static void DeleteStateTransitionArrowLine(StateTransitionArrowLine line)
        {
            bool res = StateTransitionArrowLineDataControl.DeleteStateTransitionArrowLine(line);

            if (res)
            {
                if (StateMachineEditorWindow.OnDeleteStateTransitionArrowLine != null)
                {
                    StateMachineEditorWindow.OnDeleteStateTransitionArrowLine(line);
                }
            }
        }
 public static bool DeleteStateTransitionArrowLine(StateTransitionArrowLine line)
 {
     if (allStateTransitionArrowLineList.Contains(line))
     {
         foreach (var item in line.transitions)
         {
             StateTransitionDataControl.DeleteStateTransition(item);
         }
         allStateTransitionArrowLineList.Remove(line);
         Object.DestroyImmediate(line);
         return(true);
     }
     return(false);
 }
        public static StateTransitionArrowLine AddStateTransitionToCreateArrowLine(StateTransition trans)
        {
            foreach (var item in allStateTransitionArrowLineList)
            {
                if (item.transitions[0].toState == trans.toState && item.transitions[0].fromState == trans.fromState)
                {
                    item.transitions.Add(trans);
                    return(item);
                }
            }
            StateTransitionArrowLine line = ScriptableObject.CreateInstance <StateTransitionArrowLine>();

            line.transitions.Add(trans);
            allStateTransitionArrowLineList.Add(line);
            return(line);
        }
Exemplo n.º 9
0
 public static void DeleteStateTransition(StateTransitionArrowLine line, StateTransition st)
 {
     if (line.transitions.Contains(st))
     {
         if (line.transitions.Count == 1)
         {
             StateTransitionArrowLineDataControl.DeleteStateTransitionArrowLine(line);
         }
         else
         {
             StateTransitionDataControl.DeleteStateTransition(st);
             line.transitions.Remove(st);
         }
         if (StateMachineEditorWindow.OnDeleteStateTransition != null)
         {
             StateMachineEditorWindow.OnDeleteStateTransition(st);
         }
     }
 }
Exemplo n.º 10
0
 public static void DrawLine(StateTransitionArrowLine line, int posNum)
 {
     if (line.IsLineSelf)
     {
         //Debug.Log("line.IsLineSelf:" + line.IsLineSelf + "  " + line.transitions[0].fromState.showContent.text);
         DrawLineSelf(line);
     }
     else
     {
         if (line.transitions.Count > 1)
         {
             DrawArrowCenterThreeTriangle(line.GetUseFormLinePosition(posNum), line.GetUseToLinePosition(posNum), lineSize, triangleSize, line.color);
         }
         else
         {
             DrawArrowCenterOneTriangle(line.GetUseFormLinePosition(posNum), line.GetUseToLinePosition(posNum), lineSize, triangleSize, line.color);
         }
     }
 }
Exemplo n.º 11
0
 public static void DrawLineSelf(StateTransitionArrowLine line)
 {
     if (line.transitions.Count > 1)
     {
         DrawOneTriangleDowm(line.LineSelfOneTrianglePoints, line.color);
         Vector2[] arrPos0 = new Vector2[3];
         arrPos0[0] = line.LineSelfOneTrianglePoints[0] + new Vector2(triangleSize, 0);
         arrPos0[1] = line.LineSelfOneTrianglePoints[1] + new Vector2(triangleSize, 0);
         arrPos0[2] = line.LineSelfOneTrianglePoints[2] + new Vector2(triangleSize, 0);
         DrawOneTriangleDowm(arrPos0, line.color);
         Vector2[] arrPos1 = new Vector2[3];
         arrPos1[0] = line.LineSelfOneTrianglePoints[0] - new Vector2(triangleSize, 0);
         arrPos1[1] = line.LineSelfOneTrianglePoints[1] - new Vector2(triangleSize, 0);
         arrPos1[2] = line.LineSelfOneTrianglePoints[2] - new Vector2(triangleSize, 0);
         DrawOneTriangleDowm(arrPos1, line.color);
     }
     else
     {
         DrawOneTriangleDowm(line.LineSelfOneTrianglePoints, line.color);
     }
 }