コード例 #1
0
        protected virtual void DrawWindow(int windowId)
        {
            Sequence     sequence     = windowSequenceMap[windowId];
            FungusScript fungusScript = sequence.GetFungusScript();

            // Select sequence when node is clicked
            if (Event.current.button == 0 &&
                Event.current.type == EventType.MouseDown &&
                !mouseOverVariables)
            {
                // Check if might be start of a window drag
                if (Event.current.button == 0)
                {
                    dragWindowId        = windowId;
                    startDragPosition.x = sequence.nodeRect.x;
                    startDragPosition.y = sequence.nodeRect.y;
                }

                if (windowId < windowSequenceMap.Count)
                {
                    Undo.RecordObject(fungusScript, "Select");

                    SelectSequence(fungusScript, sequence);

                    GUIUtility.keyboardControl = 0;                     // Fix for textarea not refeshing (change focus)
                }
            }

            bool selected = (fungusScript.selectedSequence == sequence);

            GUIStyle nodeStyleCopy = new GUIStyle(nodeStyle);

            if (sequence.eventHandler != null)
            {
                nodeStyleCopy.normal.background = selected ? FungusEditorResources.texEventNodeOn : FungusEditorResources.texEventNodeOff;
            }
            else
            {
                // Count the number of unique connections (excluding self references)
                List <Sequence> uniqueList         = new List <Sequence>();
                List <Sequence> connectedSequences = sequence.GetConnectedSequences();
                foreach (Sequence connectedSequence in connectedSequences)
                {
                    if (connectedSequence == sequence ||
                        uniqueList.Contains(connectedSequence))
                    {
                        continue;
                    }
                    uniqueList.Add(connectedSequence);
                }

                if (uniqueList.Count > 1)
                {
                    nodeStyleCopy.normal.background = selected ? FungusEditorResources.texChoiceNodeOn : FungusEditorResources.texChoiceNodeOff;
                }
                else
                {
                    nodeStyleCopy.normal.background = selected ? FungusEditorResources.texProcessNodeOn : FungusEditorResources.texProcessNodeOff;
                }
            }

            // Show event handler name, or a custom summary if one is provided
            string nodeName = "";

            if (sequence.eventHandler != null)
            {
                string handlerSummary = sequence.eventHandler.GetSummary();
                if (handlerSummary == "")
                {
                    EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(sequence.eventHandler.GetType());
                    if (info != null)
                    {
                        handlerSummary = info.EventHandlerName;
                    }
                }
                nodeName = "(" + handlerSummary + ")\n";
            }
            nodeName += sequence.sequenceName;

            // Make sure node is wide enough to fit the node name text
            float width = nodeStyleCopy.CalcSize(new GUIContent(nodeName)).x;

            sequence.nodeRect.width = Mathf.Max(sequence.nodeRect.width, width);

            GUILayout.Box(nodeName, nodeStyleCopy, GUILayout.Width(sequence.nodeRect.width), GUILayout.Height(sequence.nodeRect.height));
            if (sequence.description.Length > 0)
            {
                GUILayout.Label(sequence.description, EditorStyles.whiteLabel);
            }

            if (Event.current.type == EventType.ContextClick)
            {
                GenericMenu menu = new GenericMenu();

                menu.AddItem(new GUIContent("Duplicate"), false, DuplicateSequence, sequence);
                menu.AddItem(new GUIContent("Delete"), false, DeleteSequence, sequence);

                menu.ShowAsContext();
            }
        }