Exemplo n.º 1
0
 void Start()
 {
     if (Application.isPlaying)
     {
         _currentRunnables = new HashSet <RunnableNode>();
         followers         = new Dictionary <Node, NodeFollower>();
         _model.ReloadOnce();
         foreach (Node node in _model.GetNodes())
         {
             node.OnGameStart(this);
             if (node is ActiveNode)
             {
                 followers.Add(node, new NodeFollower(this, node, null, true));
             }
         }
         Node entry = _model.GetNodes <EntryNode>()[0];
         followers.Add(entry, new NodeFollower(this, entry, null));
     }
 }
Exemplo n.º 2
0
 public static EventNode GetEventNodeFromMethod(NodeMachineModel model, Type type, string methodName)
 {
     foreach (EventNode stateNode in model.GetNodes <EventNode>())
     {
         if (stateNode.stateType == type && stateNode.eventMethodName == methodName)
         {
             return(stateNode);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
        void OnGUI()
        {
            if (_model == null)
            {
                if (_selectedMachine == null)
                {
                    NodeMachineGUIUtils.DrawNothingOpenScreen(this);
                }
                else
                {
                    NodeMachineGUIUtils.DrawMachineNoModelScreen(this);
                }
                return;
            }

            Vector2 center = new Vector2(position.width / 2, position.height / 2) - (_nodeEditor.position / 2);

            _offset = _uncenteredOffset + center;

            titleContent = _changesMade ? NodeMachineEditor.titleUnsaved : NodeMachineEditor.titlePlain;

            bool livePreview = _selectedMachine != null && EditorApplication.isPlaying;

            bool modelNeedsSaving = false;

            _nodeEditor = new Rect(250, 30, position.width - 250, position.height - 30);
            _sideMenu   = new Rect(10, 20, 230, position.height - 20);
            _toolbar    = new Rect(260, 5, position.width - 260, 25);

            // ----- TOOLBAR --------

            GUILayout.BeginArea(_toolbar);
            GUILayout.BeginHorizontal();

            _drawTransparentLinks = GUILayout.Toggle(_drawTransparentLinks, " Link X-Ray", GUILayout.ExpandWidth(false));
            GUILayout.Label("  ", GUILayout.ExpandWidth(false));
            _showInivisibleNodes = GUILayout.Toggle(_showInivisibleNodes, " Reveal hidden nodes", GUILayout.ExpandWidth(false));
            GUILayout.Label("  ", GUILayout.ExpandWidth(false));

            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            // ----- SIDE MENU ------

            GUILayout.BeginArea(_sideMenu);
            GUILayout.BeginVertical();

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            EditorGUILayout.LabelField(_model.name, EditorStyles.boldLabel);

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            EditorGUILayout.Space();

            float checkinTimeBeforeDraw     = _model.CheckinTime;
            bool  supportParallelBeforeDraw = _model.supportParallel;

            _model.CheckinTime     = EditorGUILayout.FloatField("Checkin time", _model.CheckinTime);
            _model.supportParallel = EditorGUILayout.Toggle("Parallel flow", _model.supportParallel);
            if (checkinTimeBeforeDraw != _model.CheckinTime || supportParallelBeforeDraw != _model.supportParallel)
            {
                modelNeedsSaving = true;
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            EditorGUILayout.Space();

            _propertyMenu.DrawMenu(EditorApplication.isPlayingOrWillChangePlaymode, _selectedMachine);

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            // --------- ERRORS ---------

            EditorGUILayout.Space();

            _errorPanel.Draw();

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            GUILayout.EndVertical();
            GUILayout.EndArea();

            // ----- NODE EDITOR -----

            GUILayout.BeginArea(_nodeEditor, new GUIStyle("Box"));

            NodeMachineGUIUtils.DrawGrid(10, 0.2f, Color.gray, this); // * zoom
            NodeMachineGUIUtils.DrawGrid(50, 0.4f, Color.gray, this); // * zoom

            foreach (Link link in _model.GetLinks())
            {
                if (livePreview)
                {
                    NodeMachineGUIUtils.DrawLink(link, _selectedMachine.CurrentLinks.Contains(link), this);
                }
                else
                {
                    NodeMachineGUIUtils.DrawLink(link, false, this);
                }
            }

            if (_creatingLink)
            {
                Rect fromTransform = new Rect(_selectedNode.drawnTransform.position - _nodeEditor.position, _selectedNode.drawnTransform.size);
                NodeMachineGUIUtils.DrawArrow(fromTransform, Event.current.mousePosition, this);
            }

            foreach (Node node in _model.GetNodes())
            {
                if (livePreview && node is RunnableNode)
                {
                    RunnableNode runnable = node as RunnableNode;
                    if (_selectedMachine.CurrentRunnables.Contains(node))
                    {
                        if (NodeMachineGUIUtils.DrawNode(node, runnable.activeBackground, this, Event.current))
                        {
                            modelNeedsSaving = true;
                        }
                    }
                    else
                    {
                        if (NodeMachineGUIUtils.DrawNode(node, this, Event.current))
                        {
                            modelNeedsSaving = true;
                        }
                    }
                }
                else
                {
                    if (NodeMachineGUIUtils.DrawNode(node, this, Event.current))
                    {
                        modelNeedsSaving = true;
                    }
                }
            }

            // Draw transparent links over everything - looks like links are showing through from behind nodes
            if (_drawTransparentLinks)
            {
                foreach (Link link in _model.GetLinks())
                {
                    if (livePreview)
                    {
                        NodeMachineGUIUtils.DrawTransparentLink(link, _selectedMachine.CurrentLinks.Contains(link), this);
                    }
                    else
                    {
                        NodeMachineGUIUtils.DrawTransparentLink(link, false, this);
                    }
                }
            }

            GUILayout.EndArea();

            // --------------------- PROCESS EVENTS ----------------------------

            if (_nodeEditor.Contains(Event.current.mousePosition))
            {
                Vector2 totalOffset = _offset + _nodeEditor.position;
                foreach (Node node in _model.GetNodes().Reverse())
                {
                    if (node.visible || _showInivisibleNodes)
                    {
                        if (node.ProcessEvents(Event.current, _zoom, SelectNode, ProcessNodeContextMenu))
                        {
                            modelNeedsSaving = true;
                        }
                    }
                }
                foreach (Link link in _model.GetLinks())
                {
                    link.ProcessEvents(Event.current, totalOffset, ProcessLinkContextMenu, SelectLink);
                }
            }

            ProcessEvents(Event.current);

            if (modelNeedsSaving)
            {
                MarkUnsaved();
            }
            if (GUI.changed)
            {
                Repaint();
            }
        }