コード例 #1
0
 private void SetupNewNode(StateGraphNode node)
 {
     _graph.Nodes.Add(node);
     node.Set(_mouseScrollPosition, GetUniqueId(), _graph);
     EditorUtility.SetDirty(_graph);
     Repaint();
 }
コード例 #2
0
        public void DrawGui(StateGraphNode node, GUIStyle textStyle, GUIStyle buttonStyle)
        {
#if UNITY_EDITOR
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label("If", textStyle);
            DrawComparison(textStyle, buttonStyle);
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            if (DrawType(node.Graph, textStyle, buttonStyle))
            {
                UnityEditor.EditorUtility.SetDirty(node);
            }
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label("Then Exit ", textStyle);
            var indices = new string[node.OutPoints.Count];
            for (int i = 0; i < indices.Length; i++)
            {
                indices[i] = i.ToString();
            }
            Output = UnityEditor.EditorGUILayout.Popup(Output, indices, textStyle);
            if (GUILayout.Button("X", buttonStyle))
            {
                node.Remove(this);
            }
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
#endif
        }
コード例 #3
0
        private void OnDuplicate(StateGraphNode node)
        {
            var newObj = Instantiate(node);

            AssetDatabase.AddObjectToAsset(newObj, _graph);
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newObj));
            SetupNewNode(newObj);
            newObj.CheckSize();
        }
コード例 #4
0
 private void ClearList(List <ConnectionOutPoint> points, StateGraphNode node)
 {
     for (int c = 0; c < points.Count; c++)
     {
         if (points[c].Target == node)
         {
             points[c].Target   = null;
             points[c].TargetId = -1;
         }
     }
 }
コード例 #5
0
        public void ClearConnectsWith(StateGraphNode node)
        {
            for (int i = 0; i < Nodes.Count; i++)
            {
                ClearList(Nodes[i].OutPoints, node);
            }
//            for (int i = Connections.Count - 1; i >= 0; i--) {
//                if (Connections[i].GetIn().Owner == node || Connections[i].GetOut().Owner == node) {
//                    Connections.RemoveAt(i);
//                }
//            }
        }
コード例 #6
0
 private void OnClickRemoveNode(StateGraphNode node)
 {
     if (_graph.Default == node)
     {
         _graph.Default = null;
     }
     _graph.ClearConnectsWith(node);
     _graph.Nodes.Remove(node);
     DestroyImmediate(node, true);
     EditorUtility.SetDirty(_graph);
     Repaint();
 }
コード例 #7
0
 protected RuntimeStateNode(StateGraphNode node, RuntimeStateGraph graph)
 {
     Node  = node;
     Graph = graph;
     for (int i = 0; i < Node.Conditions.Count; i++)
     {
         var runtime = node.Conditions[i].GetRuntime();
         if (runtime != null)
         {
             Conditions.Add(runtime);
         }
     }
 }
コード例 #8
0
 private void OnClickSetDefault(StateGraphNode node)
 {
     if (_graph.Default == node)
     {
         _graph.Default = null;
     }
     else
     {
         _graph.Default = node;
     }
     EditorUtility.SetDirty(_graph);
     Repaint();
 }
コード例 #9
0
        public RuntimeStateNode CreateRuntimeNode(StateGraphNode node)
        {
            if (_lookup.TryGetValue(node.Id, out var existing))
            {
                return(existing);
            }
            var runtimeNode = node.GetRuntimeNode(this);

            _lookup.Add(node.Id, runtimeNode);
            if (runtimeNode is IGlobalRuntimeStateNode global)
            {
                _globals.Add(global);
            }
            //_allNodes.Add(runtimeNode);
            return(runtimeNode);
        }
コード例 #10
0
 private void OnSetEarlyExit(StateGraphNode node)
 {
     node.AllowEarlyExit = !node.AllowEarlyExit;
     EditorUtility.SetDirty(_graph);
     Repaint();
 }
コード例 #11
0
        private void ProcessNodeEvents(Event e)
        {
            if (_graph == null)
            {
                return;
            }
            _mouseScrollPosition = e.mousePosition + _scrollPosition;
            for (int i = _graph.Nodes.Count - 1; i >= 0; i--)
            {
                var  node       = _graph.Nodes[i];
                bool guiChanged = false;
                switch (e.type)
                {
                case EventType.MouseDown:
                    switch (e.button)
                    {
                    case 0:
                        if (node.Rect.Contains(_mouseScrollPosition))
                        {
                            _selected   = _dragged = node;
                            GUI.changed = true;
                        }
                        else if (_selected == node)
                        {
                            _selected   = null;
                            GUI.changed = true;
                        }
                        break;

                    case 1:
                        if (node.Rect.Contains(_mouseScrollPosition))
                        {
                            _selected   = node;
                            GUI.changed = true;
                            GenericMenu genericMenu = new GenericMenu();
                            genericMenu.AddItem(new GUIContent("Remove node"), false, () => OnClickRemoveNode(node));
                            genericMenu.AddItem(new GUIContent("Toggle Default"), false, () => OnClickSetDefault(node));
                            genericMenu.AddItem(new GUIContent("Duplicate"), false, () => OnDuplicate(node));
                            genericMenu.AddItem(new GUIContent("CheckSize"), false, () => node.CheckSize());
                            genericMenu.AddItem(new GUIContent(node.AllowEarlyExit? "Disable Early Exit" : "Enable Early Exit"), false, () =>
                                                OnSetEarlyExit(node));
                            genericMenu.ShowAsContext();
                            e.Use();
                        }
                        break;
                    }
                    break;

                case EventType.MouseUp:
                    _dragged = null;
                    break;

                case EventType.MouseDrag:
                    if (e.button == 0 && _dragged == node && e.clickCount < 2)
                    {
                        node.Drag(e.delta);
                        e.Use();
                        guiChanged = true;
                        EditorUtility.SetDirty(node);
                    }
                    break;
                }
                if (guiChanged)
                {
                    GUI.changed = true;
                }
            }
        }