コード例 #1
0
        public override void NeatWindow()
        {
            GUI.skin.box.clipping = TextClipping.Overflow;
            GUI.BeginGroup(rect);

            if (IsGlobalProperty())
            {
                GUI.enabled = false;
            }

            if (IsProperty() && Event.current.type == EventType.DragPerform && rectInner.Contains(Event.current.mousePosition))
            {
                Object droppedObj = DragAndDrop.objectReferences[0];
#if !UNITY_2018_1_OR_NEWER
                if (droppedObj is Texture2D || droppedObj is ProceduralTexture || droppedObj is RenderTexture)
#else
                if (droppedObj is Texture2D || droppedObj is RenderTexture)
#endif
                {
                    Event.current.Use();
                    textureAsset = droppedObj as Texture;
                    OnAssignedTexture();
                }
            }

            if (IsProperty() && Event.current.type == EventType.DragUpdated)
            {
                if (DragAndDrop.objectReferences.Length > 0)
                {
                    Object dragObj = DragAndDrop.objectReferences[0];
#if !UNITY_2018_1_OR_NEWER
                    if (dragObj is Texture2D || dragObj is ProceduralTexture || dragObj is RenderTexture)
#else
                    if (dragObj is Texture2D || dragObj is RenderTexture)
#endif
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        editor.nodeBrowser.CancelDrag();
                        Event.current.Use();
                    }
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                    }
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
            }

            if (IsGlobalProperty())
            {
                GUI.enabled = true;
            }



            Color prev = GUI.color;
            if (textureAsset)
            {
                GUI.color = Color.white;
                GUI.DrawTexture(rectInner, texture.texture, ScaleMode.StretchToFill, false);
            }             //else {
                          //GUI.color = new Color( GUI.color.r, GUI.color.g, GUI.color.b,0.5f);
                          //GUI.Label( rectInner, "Empty");
                          //}

            if (showLowerPropertyBox)
            {
                GUI.color = Color.white;
                DrawLowerPropertyBox();
            }

            GUI.color = prev;



            if (rectInner.Contains(Event.current.mousePosition) && !SF_NodeConnector.IsConnecting() && !IsGlobalProperty())
            {
                Rect selectRect = new Rect(rectInner);
                selectRect.yMin += 80;
                selectRect.xMin += 40;

                if (GUI.Button(selectRect, "Select", EditorStyles.miniButton))
                {
                    EditorGUIUtility.ShowObjectPicker <Texture>(textureAsset, false, "", this.id);
                    Event.current.Use();
                }
            }


            if (!IsGlobalProperty() && Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == this.id)
            {
                Event.current.Use();
                Texture newTextureAsset = EditorGUIUtility.GetObjectPickerObject() as Texture;
                if (newTextureAsset != textureAsset)
                {
                    if (newTextureAsset == null)
                    {
                        UndoRecord("unassign texture of " + property.nameDisplay);
                    }
                    else
                    {
                        UndoRecord("switch texture to " + newTextureAsset.name + " in " + property.nameDisplay);
                    }
                    textureAsset = newTextureAsset;
                    OnAssignedTexture();
                }
            }

            GUI.EndGroup();



            //	GUI.DragWindow();



            /*
             * EditorGUI.BeginChangeCheck();
             * textureAsset = (Texture)EditorGUI.ObjectField( rectInner, textureAsset, typeof( Texture ), false );
             * if( EditorGUI.EndChangeCheck() ) {
             *      OnAssignedTexture();
             * }
             * */
        }
コード例 #2
0
        void UpdateCameraPanning()
        {
            if (SF_GUI.ReleasedCameraMove())
            {
                panCamera = false;
            }

            bool insideNodeView     = MouseInsideNodeView(true);
            bool dragging           = (Event.current.type == EventType.MouseDrag && panCamera);
            bool connecting         = SF_NodeConnector.IsConnecting();
            bool rotatingPreview    = editor.preview.isDraggingLMB;
            bool placingNode        = editor.nodeBrowser.IsPlacing();
            bool draggingSeparators = editor.DraggingAnySeparator();


            if (connecting)
            {
                // Pan camera when cursor nears edges while making a connection
                Vector2 mousePosInNodeViewScreenSpace = ZoomSpaceToScreenSpace(Event.current.mousePosition) - Vector2.right * editor.separatorLeft.rect.xMax;

                float areaWidth;
                if (SF_Settings.showNodeSidebar)
                {
                    areaWidth = editor.separatorRight.rect.xMin - editor.separatorLeft.rect.xMax;
                }
                else
                {
                    areaWidth = Screen.width - editor.separatorLeft.rect.xMax;
                }
                float areaHeight    = editor.nodeView.rect.height;
                float dragPanMargin = 32f;
                float panSpeed      = 0.2f;
                float leftMag       = Mathf.Clamp(-mousePosInNodeViewScreenSpace.x + dragPanMargin, 0f, dragPanMargin);
                float rightMag      = Mathf.Clamp(mousePosInNodeViewScreenSpace.x - areaWidth + dragPanMargin, 0f, dragPanMargin);
                float topMag        = Mathf.Clamp(-mousePosInNodeViewScreenSpace.y + dragPanMargin, 0f, dragPanMargin);
                float bottomMag     = Mathf.Clamp(mousePosInNodeViewScreenSpace.y - areaHeight + dragPanMargin, 0f, dragPanMargin);
                cameraPos += new Vector2(rightMag - leftMag, bottomMag - topMag) * panSpeed;
            }


            bool doingSomethingElse = connecting || rotatingPreview || placingNode || draggingSeparators;
            bool dragInside         = dragging && insideNodeView;

            if (dragInside && !doingSomethingElse)
            {
                //if( !SF_GUI.MultiSelectModifierHeld() )
                //	selection.DeselectAll();
                //Debug.Log("Delta: " + Event.current.delta);
                cameraPos -= Event.current.delta;
                SnapCamera();

                BoundsAdjustCamera();
                editor.Defocus();
                //Debug.Log( "USING" );
                Event.current.Use();
            }


            if (SF_GUI.PressedCameraMove())
            {
                panCamera = true;
            }
        }
コード例 #3
0
        public override void NeatWindow(  )
        {
            rect.height = TexAssetConnected() ? NODE_HEIGHT : NODE_HEIGHT + 34;

            GUI.skin.box.clipping = TextClipping.Overflow;
            GUI.BeginGroup(rect);

            if (IsProperty() && Event.current.type == EventType.DragPerform && rectInner.Contains(Event.current.mousePosition))
            {
                Object droppedObj = DragAndDrop.objectReferences[0];
                if (droppedObj is Texture2D || droppedObj is RenderTexture)
                {
                    Event.current.Use();
                    TextureAsset = droppedObj as Texture;
                    OnAssignedTexture();
                }
            }

            if (IsProperty() && Event.current.type == EventType.DragUpdated)
            {
                if (DragAndDrop.objectReferences.Length > 0)
                {
                    Object dragObj = DragAndDrop.objectReferences[0];
                    if (dragObj is Texture2D || dragObj is RenderTexture)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        editor.nodeBrowser.CancelDrag();
                        Event.current.Use();
                    }
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                    }
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
            }



            Color prev = GUI.color;

            if (TextureAsset)
            {
                GUI.color = Color.white;
                GUI.DrawTexture(rectInner, texture.texture, ScaleMode.StretchToFill, false);                   // TODO: Doesn't seem to work
                if (displayVectorDataMask)
                {
                    GUI.DrawTexture(rectInner, SF_GUI.VectorIconOverlay, ScaleMode.ScaleAndCrop, true);
                }
            }

            if (showLowerPropertyBox && !TexAssetConnected())
            {
                GUI.color = Color.white;
                DrawLowerPropertyBox();
            }

            //else {
            //GUI.color = new Color( GUI.color.r, GUI.color.g, GUI.color.b,0.5f);
            //GUI.Label( rectInner, "Empty");
            //}
            GUI.color = prev;



            if (IsProperty())
            {
                bool draw = rectInner.Contains(Event.current.mousePosition) && !SF_NodeConnector.IsConnecting();

                Rect selectRect = new Rect(rectInner);
                selectRect.yMin += 80;
                selectRect.xMin += 40;
                Color c = GUI.color;
                GUI.color = new Color(1, 1, 1, draw ? 1 : 0);
                if (GUI.Button(selectRect, "Select", EditorStyles.miniButton))
                {
                    EditorGUIUtility.ShowObjectPicker <Texture>(TextureAsset, false, "", this.id);
                    Event.current.Use();
                }
                GUI.color = c;
            }


            if (IsProperty() && Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == this.id)
            {
                Event.current.Use();
                Texture newTextureAsset = EditorGUIUtility.GetObjectPickerObject() as Texture;
                if (newTextureAsset != TextureAsset)
                {
                    if (newTextureAsset == null)
                    {
                        UndoRecord("unassign texture of " + property.nameDisplay);
                    }
                    else
                    {
                        UndoRecord("switch texture to " + newTextureAsset.name + " in " + property.nameDisplay);
                    }
                    TextureAsset = newTextureAsset;
                    OnAssignedTexture();
                }
            }

            GUI.EndGroup();



            //	GUI.DragWindow();



            /*
             * EditorGUI.BeginChangeCheck();
             * textureAsset = (Texture)EditorGUI.ObjectField( rectInner, textureAsset, typeof( Texture ), false );
             * if( EditorGUI.EndChangeCheck() ) {
             *      OnAssignedTexture();
             * }
             * */
        }