Пример #1
0
        //public void OnDroppedSubstance(ProceduralMaterial procMat){

        //	Texture diffuse = TryGetProceduralTexture(procMat, "_MainTex");
        //	Texture normal = TryGetProceduralTexture(procMat, "_BumpMap");
        //	//Texture parallax = TryGetProceduralTexture(procMat, "_ParallaxMap");
        //	//Texture emission = TryGetProceduralTexture(procMat, "_Illum");
        //	//TryGetProceduralTexture("_MainTex");

        //	SF_Node prevNode = TryLinkIfExistsAndOpenSlotAvailable(diffuse, "MainTex", editor.mainNode.diffuse, "RGB");
        //	TryLinkIfExistsAndOpenSlotAvailable(normal, "BumpMap", editor.mainNode.normal, "RGB", prevNode);


        //}

        // For connecting procedural materials to the main node
        public SF_Node TryLinkIfExistsAndOpenSlotAvailable(Texture tex, string propertyName, SF_NodeConnector connector, string outChannel, SF_Node prevNode = null)
        {
            if (tex)
            {
                SFN_Tex2d tNode = editor.AddNode <SFN_Tex2d>();
                if (prevNode != null)
                {
                    Rect r = tNode.rect;
                    r          = r.MovedDown(1);
                    r.y       += 64;
                    tNode.rect = r;
                }
                tNode.TextureAsset = tex;
                tNode.property.SetName(propertyName);
                tNode.OnAssignedTexture();
                if (connector.enableState == EnableState.Enabled && connector.availableState == AvailableState.Available && !connector.IsConnected())
                {
                    connector.LinkTo(tNode[outChannel]);
                }
                return(tNode);
            }
            return(null);
        }
Пример #2
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;
            }
        }