示例#1
0
        public bool IsDeleteHovering(bool world = true)
        {
            if (!IsConnected())
            {
                return(false);                // There's no link to delete to begin with
            }
            if (!Hovering(world))
            {
                return(false);                // You aren't hovering at all
            }
            if (node.editor.nodeView.selection.boxSelecting)
            {
                return(false);                // You're in the middle of a box selection
            }
            if (node.editor.nodeView.isCutting)
            {
                return(false);                // We're already doing a cut-deletion, don't mark it for click-deletion
            }
            if (SF_NodeConnector.IsConnecting())
            {
                if (SF_NodeConnector.pendingConnectionSource == this)
                {
                    return(false);                    // Hovering the pending connection, don't mark it for delete
                }
                if (!UnconnectableToPending() && this.conType == ConType.cInput)
                {
                    return(true);                    // This will be a relink-delete!
                }
            }



            if (SF_GUI.HoldingAlt())
            {
                return(true);                // RMB delete
            }
            return(false);
        }
示例#2
0
        //public Texture TryGetProceduralTexture(ProceduralMaterial procMat, string propName){
        //	Texture returnTex = null;
        //	try{
        //		if(procMat.HasProperty(propName))
        //			returnTex = procMat.GetTexture(propName);
        //	} catch (UnityException e){
        //		e.Equals(e);
        //	}
        //	return returnTex;
        //}



        public void UpdateCutLine()
        {
            if (SF_GUI.HoldingAlt() && Event.current.type == EventType.MouseDown && Event.current.button == 1)
            { // Alt + RMB drag
                StartCutting();
            }
            else if (SF_GUI.ReleasedRawRMB())
            {
                StopCutting();
            }

            if (isCutting)
            {
                Vector2 cutEnd = GetNodeSpaceMousePos();

                GUILines.DrawDashedLine(editor, cutStart, cutEnd, Color.white, 5f);


                foreach (SF_Node n in editor.nodes)
                {
                    foreach (SF_NodeConnector con in n.connectors)
                    {
                        if (con.IsConnected() && con.conType == ConType.cInput && con.enableState != EnableState.Hidden)
                        {
                            Vector2 intersection = Vector2.zero;
                            if (con.conLine.Intersects(cutStart, cutEnd, out intersection))
                            {
                                con.conLine.aboutToBeDeleted = true;

                                Vector2 hit = editor.nodeView.ScreenSpaceToZoomSpace(intersection);

                                float scale     = 5f;
                                float scaleDiff = 0.95f;
                                //Vector2 rg, up, lf, dn;


                                //Vector2 localRight = (cutStart-cutEnd).normalized;
                                //Vector2 localUp = new Vector2(localRight.y,-localRight.x);

                                //rg = hit + localRight * scale;
                                //up = hit + localUp * scale;
                                //lf = hit - localRight * scale;
                                //dn = hit - localUp * scale;
                                Color c0 = new Color(1f, 0.1f, 0.1f, 0.9f);
                                Color c1 = new Color(1f, 0.1f, 0.1f, 0.7f);
                                Color c2 = new Color(1f, 0.1f, 0.1f, 0.5f);
                                Color c3 = new Color(1f, 0.1f, 0.1f, 0.3f);

                                GUILines.DrawDisc(hit, scale, c0);
                                GUILines.DrawDisc(hit, scale - scaleDiff, c1);
                                GUILines.DrawDisc(hit, scale - scaleDiff * 2, c2);
                                GUILines.DrawDisc(hit, scale - scaleDiff * 3, c3);

                                //GUILines.DrawLine(rg,up,Color.red,2f,true);
                                //GUILines.DrawLine(up,lf,Color.red,2f,true);
                                //GUILines.DrawLine(lf,dn,Color.red,2f,true);
                                //GUILines.DrawLine(dn,rg,Color.red,2f,true);



                                continue;
                            }
                            else
                            {
                                con.conLine.aboutToBeDeleted = false;
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public void OnLocalGUI(Rect r)
        {
            //r = r.PadTop(Mathf.CeilToInt(22*zoom));



            editor.mousePosition = Event.current.mousePosition;
            rect = r;



            // TOOLBAR
            //DrawToolbar( new Rect( rect.x, rect.y, rect.width, TOOLBAR_HEIGHT ) );



            Rect localRect = new Rect(r);

            localRect.x = 0;
            localRect.y = 0;

            //rect.y += TOOLBAR_HEIGHT;
            //rect.height -= TOOLBAR_HEIGHT;



            // VIEW
            Rect rectInner = new Rect(rect);

            rectInner.width  = float.MaxValue / 2f;
            rectInner.height = float.MaxValue / 2f;


            // TEMP:
            //			Rect btn = rectInner;
            //			btn.width = 64;
            //			btn.height = 24;
            //			if(SF_Debug.renderDataNodes){
            //				if(selection.Selection.Count > 0){
            //					if(GUI.Button(btn,"NSS")){
            //						editor.TakeNodePreviewScreenshot();
            //					}
            //				}
            //			}



            if (Event.current.type == EventType.Repaint)
            {
                nodeSpaceMousePos = ScreenSpaceToZoomSpace(Event.current.mousePosition);
            }



            bool mouseOverNode = false;



            SF_ZoomArea.Begin(zoom, rect, cameraPos);
            {
                selection.OnGUI(); // To detect if you press things
                if (editor.nodeView != null)
                {
                    editor.nodeView.selection.DrawBoxSelection();
                }

                if (Event.current.type == EventType.Repaint)
                {
                    viewSpaceMousePos = ZoomSpaceToScreenSpace(Event.current.mousePosition);
                }
                // NODES
                if (editor.nodes != null)
                {
                    // If we're repainting, draw in reverse to sort properly
                    //if(Event.current.rawType == EventType.repaint){
                    for (int i = editor.nodes.Count - 1; i >= 0; i--)
                    {
                        if (!editor.nodes[i].Draw())
                        {
                            break;
                        }
                    }

                    /*} else {
                     *                          for(int i=0;i<editor.nodes.Count;i++) {
                     *                                  if( !editor.nodes[i].Draw() )
                     *                                          break;
                     *                          }
                     *                  }*/

                    if (!mouseOverNode)
                    {
                        for (int i = 0; i < editor.nodes.Count; i++)
                        {
                            if (editor.nodes[i].MouseOverNode(world: true))
                            {
                                mouseOverNode = true;
                            }
                        }
                    }

                    if (Event.current.type == EventType.Repaint)
                    {
                        for (int i = 0; i < editor.nodes.Count; i++)
                        {
                            editor.nodes[i].DrawConnectors();
                        }
                    }
                }


                UpdateCutLine();

                UpdateCameraPanning();
            }
            SF_ZoomArea.End(zoom);


            if (!SF_Node.isEditingAnyNodeTextField)
            {
                SF_Editor.instance.UpdateKeyHoldEvents(mouseOverNode);
            }


            if (MouseInsideNodeView(false) && Event.current.type == EventType.ScrollWheel)
            {
                zoomTarget = ClampZoom(zoomTarget * (1f - Event.current.delta.y * 0.02f));
            }



            SetZoom(Mathf.Lerp(zoom, zoomTarget, 0.2f));



            if (Event.current.type == EventType.ContextClick && !SF_GUI.HoldingAlt())
            {
                Vector2 mousePos = Event.current.mousePosition;
                if (rect.Contains(mousePos))
                {
                    // Now create the menu, add items and show it
                    GenericMenu menu = new GenericMenu();

                    // First item is for creating a comment box
                    //menu.AddItem( new GUIContent("Create comment box"), false, ContextClick, mousePos );

                    //menu.AddSeparator("");

                    for (int i = 0; i < editor.nodeTemplates.Count; i++)
                    {
                        if (editor.ps.catLighting.renderPath == SFPSC_Lighting.RenderPath.Deferred && !editor.nodeTemplates[i].availableInDeferredPrePass)
                        {
                            continue; // Skip forward nodes when in deferred
                        }
                        menu.AddItem(new GUIContent(editor.nodeTemplates[i].fullPath), false, ContextClick, editor.nodeTemplates[i]);
                    }
                    editor.ResetRunningOutdatedTimer();
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }



            if (Event.current.type == EventType.DragPerform)
            {
                Object droppedObj = DragAndDrop.objectReferences[0];
                if (droppedObj is Texture2D || /*droppedObj is ProceduralTexture ||*/ droppedObj is RenderTexture)
                {
                    SFN_Tex2d texNode = editor.nodeBrowser.OnStopDrag() as SFN_Tex2d;
                    texNode.TextureAsset = droppedObj as Texture;
                    texNode.OnAssignedTexture();
                    Event.current.Use();
                }
                //if(droppedObj is ProceduralMaterial){
                //	OnDroppedSubstance(droppedObj as ProceduralMaterial);
                //}
            }

            if (Event.current.type == EventType.DragUpdated && Event.current.type != EventType.DragPerform)
            {
                if (DragAndDrop.objectReferences.Length > 0)
                {
                    Object dragObj = DragAndDrop.objectReferences[0];
                    if (dragObj is Texture2D || /*dragObj is ProceduralTexture || */ dragObj is RenderTexture)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        if (!editor.nodeBrowser.IsPlacing())
                        {
                            editor.nodeBrowser.OnStartDrag(editor.GetTemplate <SFN_Tex2d>());
                        }
                        else
                        {
                            editor.nodeBrowser.UpdateDrag();
                        }
                    }
                    //               else if(dragObj is ProceduralMaterial){
                    //	DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                    //}
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                    }
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
            }



            // If release
            if (MouseInsideNodeView(false) && Event.current.type == EventType.MouseUp)
            {
                bool ifCursorStayed = Vector2.SqrMagnitude(mousePosStart - Event.current.mousePosition) < SF_Tools.stationaryCursorRadius;

                if (ifCursorStayed && !SF_GUI.MultiSelectModifierHeld())
                {
                    selection.DeselectAll(registerUndo: true);
                }


                //editor.Defocus( deselectNodes: ifCursorStayed );
            }

            if (SF_GUI.ReleasedRawLMB())
            {
                SF_NodeConnector.pendingConnectionSource = null;
            }

            // If press
            if (Event.current.type == EventType.MouseDown && MouseInsideNodeView(false))
            {
                //bool ifNotHoldingModifier = !SF_GUI.MultiSelectModifierHeld();
                mousePosStart = Event.current.mousePosition;
                editor.Defocus();
            }


            if (!editor.screenshotInProgress)
            {
                Rect logoRect = rect;
                logoRect.y     -= 14;
                logoRect.x     += 1;
                logoRect.width  = SF_GUI.Logo.width;
                logoRect.height = SF_GUI.Logo.height;
                GUI.color       = new Color(1f, 1f, 1f, 0.5f);
                GUI.DrawTexture(logoRect, SF_GUI.Logo);

                logoRect.y     += logoRect.height;
                logoRect.height = 16;

                GUI.Label(logoRect, "v" + SF_Tools.version, EditorStyles.boldLabel);
                GUI.color = Color.white;
            }
        }
示例#4
0
        public void CheckConnection(SF_Editor editor)
        {
            if (ShouldBeInvisible())
            {
                return;
            }



            if (conType == ConType.cInput && Event.current.type == EventType.Repaint)
            {
                DrawConnection(editor);
            }

            if (enableState == EnableState.Disabled || availableState == AvailableState.Unavailable)
            {
                return;
            }

            if (Clicked())
            {
                SF_NodeConnector.pendingConnectionSource = this;
                editor.nodeView.selection.DeselectAll(registerUndo: false);
                foreach (SF_Node iNode in editor.nodes)
                {
                    foreach (SF_NodeConnector con in iNode.connectors)
                    {
                        con.UpdateCanValidlyConnectToPending();
                    }
                }
                Event.current.Use();
            }

            if (Clicked(1) && SF_GUI.HoldingAlt())
            {
                Disconnect();
            }

            if (!ConnectionInProgress())
            {
                if (Released())
                {
                    TryMakeConnection();
                }
                return;
            }


            // Active connection:

            editor.ResetRunningOutdatedTimer();

            //if(Event.current.type == EventType.repaint)
            //node.Repaint();


            bool hovering = false;

            foreach (SF_Node n in editor.nodes)
            {
                foreach (SF_NodeConnector con in n.connectors)
                {
                    if (con.CanConnectToPending() && con.Hovering(false))
                    {
                        hovering = true;
                        break;
                    }
                }
                if (hovering)
                {
                    break;
                }
            }

            if (Event.current.type == EventType.Repaint)
            {
                Color c = hovering ? Color.green : GetConnectionLineColor();

                bool    input = (conType == ConType.cInput);
                Vector2 start = input ? GetConnectionPoint() : MousePos();
                Vector2 end   = input ? MousePos() : GetConnectionPoint();;

                if (valueType == ValueType.VTm4x4 || valueType == ValueType.VTv4m4x4)
                {
                    GUILines.DrawMatrixConnection(editor, start, end, c);
                }
                else
                {
                    GUILines.DrawStyledConnection(editor, start, end, GetCompCount(), c);
                }
            }



            //Drawing.DrawLine(rect.center,MousePos(),Color.white,2,true);
        }