Example #1
0
        public void SortingBlock(ref Rect r)
        {
            ps.StartIgnoreChangeCheck();
            bool prevAutoSort = autoSort;

            GUI.enabled = ps.catLighting.renderPath == SFPSC_Lighting.RenderPath.Forward;
            autoSort    = UndoableToggle(r, autoSort, autoSort ? "自动排序..." : "自动排序", "auto sort", null);
            GUI.enabled = true;
            if (autoSort != prevAutoSort && autoSort)
            {
                UpdateAutoSettings();
            }
            ps.EndIgnoreChangeCheck();

            r.xMin += 20;
            r.y    += 20;

            bool prevGUI = GUI.enabled;

            GUI.enabled = !autoSort;
            {
                int  wOrder  = SF_GUI.WidthOf("Order", EditorStyles.miniLabel) + 2;
                int  wPlus   = SF_GUI.WidthOf("+", EditorStyles.miniLabel) + 2;
                int  wOffset = 32;
                int  wEquals = SF_GUI.WidthOf("=", EditorStyles.miniLabel);
                int  wResult = 32;
                int  wField  = Mathf.FloorToInt(r.width - wOrder - wPlus - wEquals - wOffset - wResult);
                Rect tRect   = new Rect(r);
                tRect.width = wOrder;
                GUI.Label(tRect, new GUIContent("排序", "确定此着色器相对于其他渲染的顺序"), EditorStyles.miniLabel);
                SF_GUI.MoveRight(ref tRect, wField);
                //queuePreset = (Queue)EditorGUI.Popup(tRect, (int)queuePreset, strQueue );
                queuePreset = (Queue)UndoableEnumPopupNamed(tRect, queuePreset, strQueue, "render queue order");
                SF_GUI.MoveRight(ref tRect, wPlus);
                GUI.Label(tRect, "+");
                SF_GUI.MoveRight(ref tRect, wOffset);
                queueOffset = UndoableIntField(tRect, queueOffset, "render queue offset");
                SF_GUI.MoveRight(ref tRect, wEquals);
                GUI.Label(tRect, "=");
                SF_GUI.MoveRight(ref tRect, wResult);
                GUI.Label(tRect, (queueNumbers[(int)queuePreset] + queueOffset).ToString());
                r.y += 20;
                //renderType = (RenderType)SF_GUI.LabeledEnumField( r,new GUIContent("Render Type","Defines shader replacement; required for some rendering effects, such as SSAO"), renderType, EditorStyles.miniLabel );
                renderType = (RenderType)UndoableLabeledEnumPopupNamed(r, "渲染类型", renderType, strRenderType, "render type");
                r.y       += 20;
                //depthTest = (DepthTest)SF_GUI.LabeledEnumFieldNamed( r, strDepthTest, new GUIContent( "Depth Test", "Compared to the existing geometry in the scene, \nthis determines when to render this geometry. \u2264 is default, meaning:\n\"If this part is closer or as close to the camera as existing geometry, draw me!\"" ), (int)depthTest, EditorStyles.miniLabel );
                depthTest = (DepthTest)UndoableLabeledEnumPopupNamed(r, "深度测试", depthTest, strDepthTest, "depth test");
                r.y      += 20;
                //ignoreProjector = GUI.Toggle(r, ignoreProjector, "Ignore Projectors" );
                ignoreProjector = UndoableToggle(r, ignoreProjector, "忽略投影器", "ignore projectors", null);
                r.y            += 20;
                //writeDepth = GUI.Toggle( r, writeDepth, "Write to Depth buffer" );
                writeDepth = UndoableToggle(r, writeDepth, "写入深度缓冲区", "depth buffer write", null);
                r.y       += 20;
            }
            GUI.enabled = prevGUI;

            r.xMin -= 20;
        }
Example #2
0
        /*
         * public static Enum EnumPopupZoomCompensated(Rect r, Enum selected ){
         *
         *      // TODO: Custom enum popup proper zoom positioning
         *
         *      if(GUI.Button(r,selected.ToString(),EditorStyles.popup)){
         *
         *              GenericMenu gm = new GenericMenu();
         *              //gm.AddItem(selected);
         *
         *              Array enumList = Enum.GetValues(selected.GetType());
         *
         *              for(int i=0;i < enumList.Length;i++){
         *
         *                      gm.AddItem( new GUIContent(enumList.GetValue(i).ToString()), i == Convert.ToInt32(selected), (object o)=>{Debug.Log(o.ToString());},"Test " + i);
         *
         *
         *              }
         *
         *              gm.ShowAsContext();
         *
         *
         *
         *      }
         *
         *
         *
         *      return selected;
         *
         * }
         */

        public static void FillBackground(Rect r)
        {
            Color pCol = GUI.color;

            SF_GUI.UseBackgroundColor();
            GUI.DrawTexture(r, EditorGUIUtility.whiteTexture);
            GUI.color = pCol;
        }
Example #3
0
 public void InstructionLabel(ref Rect iRect, Texture2D icon, string label)
 {
     iRect.width = icon.width;
     GUI.DrawTexture(iRect, icon);
     iRect.x    += iRect.width;
     iRect.width = SF_GUI.WidthOf(label, headerStyle) + 2;
     GUI.Label(iRect, label, headerStyle);
     iRect.x += iRect.width;
 }
        public int UndoableLabeledEnumPopupNamed(Rect r, string label, Enum enumValue, string[] displayedOptions, string undoInfix)
        {
            int nextEnum = SF_GUI.LabeledEnumFieldNamed(r, displayedOptions, new GUIContent(label), (int)((object)enumValue), EditorStyles.miniLabel);

            if (nextEnum != ((int)((object)enumValue)))
            {
                string undoName = "set " + undoInfix + " to " + displayedOptions[nextEnum];
                Undo.RecordObject(this, undoName);
                return(nextEnum);
            }
            return((int)((object)enumValue));
        }
        public Enum UndoableLabeledEnumPopup(Rect r, string label, Enum enumValue, string undoInfix)
        {
            Enum nextEnum = SF_GUI.LabeledEnumField(r, label, enumValue, EditorStyles.miniLabel);

            if (nextEnum.ToString() != enumValue.ToString())
            {
                string undoName = "set " + undoInfix + " to " + nextEnum;
                Undo.RecordObject(this, undoName);
                enumValue = nextEnum;
            }
            return(enumValue);
        }
        public void UndoableConditionalToggle(Rect r, ref bool value, bool usableIf, bool disabledDisplayValue, string label, string undoSuffix)
        {
            bool nextValue = value;

            SF_GUI.ConditionalToggle(r, ref nextValue, usableIf, disabledDisplayValue, label);
            if (nextValue != value)
            {
                string undoName = (nextValue ? "enable" : "disable") + " " + undoSuffix;
                Undo.RecordObject(this, undoName);
                value = nextValue;
            }
        }
        public int UndoableContentScaledToolbar(Rect r, string label, int selected, string[] labels, string undoInfix)
        {
            int newValue = SF_GUI.ContentScaledToolbar(r, label, selected, labels);

            if (newValue != selected)
            {
                string undoName = "set " + undoInfix + " to " + labels[newValue];
                Undo.RecordObject(this, undoName);
                return(newValue);
            }
            return(selected);
        }
Example #8
0
        public static System.Enum LabeledEnumField(Rect r, GUIContent label, System.Enum enumVal, GUIStyle style, bool zoomCompensate = false)
        {
            Rect leftRect  = new Rect(r);
            Rect rightRect = new Rect(r);
            int  width     = WidthOf(label, style) + 4;

            leftRect.width  = width;
            rightRect.xMin += width;
            GUI.Label(leftRect, label, style);

            return(SF_GUI.EnumPopup(rightRect, GUIContent.none, enumVal, EditorStyles.popup, zoomCompensate));
            //return EditorGUI.EnumPopup( rightRect, GUIContent.none, enumVal, EditorStyles.popup );
            //return EnumPopupZoomCompensated( rightRect, enumVal );
        }
        public void UndoableEnterableNodeTextField(SF_Node node, Rect r, ref string value, string undoMsg, bool update = true, UnityEngine.Object extra = null)
        {
            string nextValue = value;

            SF_GUI.EnterableTextField(node, r, ref nextValue, EditorStyles.textField, update);
            if (nextValue != value)
            {
                Undo.RecordObject(this, undoMsg);
                if (extra != null)
                {
                    Undo.RecordObject(extra, undoMsg);
                }
                value = nextValue;
            }
        }
Example #10
0
        public override void DrawLowerPropertyBox()
        {
            if (selected && !SF_GUI.MultiSelectModifierHeld())
            {
                ColorPickerCorner(lowerRect);
            }

            //Color vecPrev = texture.dataUniform;
            Rect tRect = lowerRect;

            UndoableEnterableFloatField(tRect, ref texture.dataUniform.x, "R channel", null);
            tRect.x += tRect.width;
            UndoableEnterableFloatField(tRect, ref texture.dataUniform.y, "G channel", null);
            tRect.x += tRect.width;
            UndoableEnterableFloatField(tRect, ref texture.dataUniform.z, "B channel", null);
        }
Example #11
0
        public void UpdateExtraInputWidth()
        {
            int widest = SF_NodeConnector.defaultConnectorWidth;

            foreach (SF_NodeConnector con in connectors)
            {
                if (con.conType == ConType.cOutput)
                {
                    continue;
                }

                widest = Mathf.Max(SF_GUI.WidthOf(con.label, SF_Styles.MiniLabelOverflow) + 2, widest);
            }

            extraWidthInput = widest - SF_NodeConnector.defaultConnectorWidth;
        }
Example #12
0
        public override void DrawLowerPropertyBox()
        {
            if (selected && !SF_GUI.MultiSelectModifierHeld())
            {
                ColorPickerCorner(lowerRect);
            }

            Vector4 cPrev = texture.dataUniform;
            Rect    tRect = lowerRect;

            //SF_GUI.EnterableFloatField( this, tRect, ref texture.dataUniform.r, null );
            UndoableEnterableFloatField(tRect, ref texture.dataUniform.x, "R channel", null);
            tRect.x += tRect.width;
            //SF_GUI.EnterableFloatField( this, tRect, ref texture.dataUniform.g, null );
            UndoableEnterableFloatField(tRect, ref texture.dataUniform.y, "G channel", null);
            if (texture.dataUniform != cPrev)
            {
                OnUpdateNode();
            }
        }
        public void Draw(int yPos, int height)
        {
            rect.y      = yPos;
            rect.height = height;
            rect.width  = 7;

            GUI.Box(rect, "", EditorStyles.textField);
            Rect rHandle = new Rect(rect);

            rHandle.xMin += 0;
            rHandle.xMax -= 0;
            Rect uv = new Rect(rect);

            uv.x       = 0;
            uv.y       = 0;
            uv.width   = 1;
            uv.height /= SF_GUI.Handle_drag.height;
            GUI.DrawTextureWithTexCoords(rHandle, SF_GUI.Handle_drag, uv);

            if (rect.Contains(Event.current.mousePosition) || dragging)
            {
                SF_GUI.AssignCursor(rect, MouseCursor.ResizeHorizontal);
            }

            if (Event.current.isMouse)
            {
                if (SF_GUI.ReleasedRawLMB())
                {
                    StopDrag();
                }
                if (dragging)
                {
                    UpdateDrag();
                }
                if (SF_GUI.PressedLMB(rect))
                {
                    StartDrag();
                }
            }
        }
Example #14
0
        public override void DrawLowerPropertyBox()
        {
            if (selected && !SF_GUI.MultiSelectModifierHeld() && !IsGlobalProperty())
            {
                ColorPickerCorner(lowerRect);
            }

            Vector4 vecPrev = texture.dataUniform;

            PrepareWindowColor();
            Rect tRect = lowerRect;

            if (IsGlobalProperty())
            {
                texture.dataUniform[0] = texture.dataUniform[1] = texture.dataUniform[2] = 0.5f;
                texture.dataUniform[3] = 1f;
                GUI.enabled            = false;
            }

            texture.dataUniform[0] = UndoableFloatField(tRect, texture.dataUniform[0], "R channel");
            tRect.x += tRect.width;
            texture.dataUniform[1] = UndoableFloatField(tRect, texture.dataUniform[1], "G channel");
            tRect.x += tRect.width;
            texture.dataUniform[2] = UndoableFloatField(tRect, texture.dataUniform[2], "B channel");
            tRect.x += tRect.width;
            texture.dataUniform[3] = UndoableFloatField(tRect, texture.dataUniform[3], "A channel");
            ResetWindowColor();
            if (texture.dataUniform != vecPrev)
            {
                OnUpdateValue();
                OnUpdateNode();
            }

            if (IsGlobalProperty())
            {
                GUI.enabled = true;
            }
        }
Example #15
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);
        }
        public override void DrawLowerPropertyBox()
        {
            Vector4 vecPrev = texture.dataUniform;

            if (!IsGlobalProperty() && selected && !SF_GUI.MultiSelectModifierHeld())
            {
                ColorPickerCorner(lowerRect);
            }

            PrepareWindowColor();
            if (IsGlobalProperty())
            {
                texture.dataUniform[0] = texture.dataUniform[1] = texture.dataUniform[2] = 0.5f;
                texture.dataUniform[3] = 1f;
                GUI.enabled            = false;
            }
            Rect tRect = lowerRect;

            texture.dataUniform[0] = UndoableFloatField(tRect, texture.dataUniform[0], "R channel");
            tRect.x += tRect.width;
            texture.dataUniform[1] = UndoableFloatField(tRect, texture.dataUniform[1], "G channel");
            tRect.x += tRect.width;
            texture.dataUniform[2] = UndoableFloatField(tRect, texture.dataUniform[2], "B channel");
            tRect.x += tRect.width;
            texture.dataUniform[3] = UndoableFloatField(tRect, texture.dataUniform[3], "A channel");
            if (IsGlobalProperty())
            {
                GUI.enabled = true;
            }
            ResetWindowColor();
            if (texture.dataUniform != vecPrev)
            {
                OnUpdateNode(NodeUpdateType.Soft);
                editor.shaderEvaluator.ApplyProperty(this);
            }
        }
Example #17
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;
            }
        }
        public void DrawButton(SF_EditorNodeData entry, ref Rect btnRect)
        {
            GUI.color = entry.isProperty ? SF_Node.colorExposed : Color.white;

            bool usable = !(!entry.availableInDeferredPrePass && editor.ps.catLighting.renderPath == SFPSC_Lighting.RenderPath.Deferred);

            if (!usable)
            {
                //GUI.color = Color.red;
                GUI.enabled = false;
            }

            bool mouseOver = btnRect.Contains(Event.current.mousePosition);


            if (usable)
            {
                if (dragNode == entry)
                {
                    GUI.color = SF_GUI.selectionColorBright;
                }
                else if (mouseOver && dragNode == null)
                {
                    GUI.color = SF_GUI.selectionColorBrighter;
                }
            }


            GUI.Label(btnRect, (usable ? string.Empty : "    ") + entry.nodeName, styleButton);


            if (mouseOver && Event.current.type == EventType.MouseDown && Event.current.button == 0 && usable)
            {
                OnStartDrag(entry);
            }
            else if (Event.current.type == EventType.ContextClick)
            {
                Vector2 mousePos = Event.current.mousePosition;
                if (btnRect.Contains(mousePos))
                {
                    // Now create the menu, add items and show it
                    GenericMenu menu = new GenericMenu();
                    editor.ResetRunningOutdatedTimer();
                    //menu.AddItem( new GUIContent("Edit Comment"), false, ContextClick, "cmt_edit" );
                    menu.AddItem(new GUIContent("What does " + entry.nodeName + " do?"), false, ContextClick, entry);
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }



            GUI.color = Color.white;
            if (entry.isNew || entry.isUnstable)
            {
                GUIStyle miniStyle = new GUIStyle(EditorStyles.miniBoldLabel);
                miniStyle.alignment        = TextAnchor.UpperRight;
                miniStyle.normal.textColor = Color.red;
                GUI.Label(btnRect, entry.isNew ? "New" : "Unstable", miniStyle);
            }

            if (usable)
            {
                SF_GUI.AssignCursor(btnRect, MouseCursor.Pan);
            }
            else
            {
                if (Event.current.type == EventType.Repaint)
                {
                    GUI.enabled = true;
                    SF_GUI.DrawLock(btnRect.PadTop(4), "Forward rendering only", TextAlignment.Right);
                    //Draw(btnRect.PadTop(4), false, true, true, false); // Draw lock
                    GUI.enabled = false;
                }
            }
            GUI.enabled = true;
            btnRect.y  += btnRect.height;
        }
Example #19
0
        public override void NeatWindow( )
        {
            GUI.BeginGroup(rect);
            GUI.color             = Color.white;
            GUI.skin.box.clipping = TextClipping.Overflow;



            // Resize handle
            int size = 10;



            Rect topLeft = LocalRect().GetBorder(RectBorder.TopLeft, size);
            //Rect lowerRight = LocalRect().GetBorder(RectBorder.BottomRight,size);
            Rect topRight = LocalRect().GetBorder(RectBorder.TopRight, size);

            Rect left = LocalRect().GetBorder(RectBorder.Left, size);
            //Rect lowerRight = LocalRect().GetBorder(RectBorder.Center,size);
            Rect right = LocalRect().GetBorder(RectBorder.Right, size);


            Rect lowerLeft  = LocalRect().GetBorder(RectBorder.BottomLeft, size);           //new Rect(rect.width - size, rect.height-size,size,size);
            Rect lower      = LocalRect().GetBorder(RectBorder.Bottom, size);
            Rect lowerRight = LocalRect().GetBorder(RectBorder.BottomRight, size);


            /*
             * if(!resizing)
             *      SF_GUI.AssignCursor(lowerRight,MouseCursor.ResizeUpLeft);
             * else
             *      SF_GUI.AssignCursor(new Rect(0,0,Screen.width,Screen.height),MouseCursor.ResizeUpLeft);*/



            SF_GUI.DrawTextureTiled(LocalRect().GetBorder(RectBorder.TopLeft, size, showResizeCursor: true), SF_GUI.Handle_drag, local: true);
            //SF_GUI.DrawTextureTiled(LocalRect().GetBorder(RectBorder.Top			,size,  showResizeCursor:true), SF_GUI.Handle_drag, local:true );
            SF_GUI.DrawTextureTiled(LocalRect().GetBorder(RectBorder.TopRight, size, showResizeCursor: true), SF_GUI.Handle_drag, local: true);
            SF_GUI.DrawTextureTiled(LocalRect().GetBorder(RectBorder.Left, size, showResizeCursor: true), SF_GUI.Handle_drag, local: true);
            SF_GUI.DrawTextureTiled(LocalRect().GetBorder(RectBorder.Right, size, showResizeCursor: true), SF_GUI.Handle_drag, local: true);
            SF_GUI.DrawTextureTiled(LocalRect().GetBorder(RectBorder.BottomLeft, size, showResizeCursor: true), SF_GUI.Handle_drag, local: true);
            SF_GUI.DrawTextureTiled(LocalRect().GetBorder(RectBorder.Bottom, size, showResizeCursor: true), SF_GUI.Handle_drag, local: true);
            SF_GUI.DrawTextureTiled(LocalRect().GetBorder(RectBorder.BottomRight, size, showResizeCursor: true), SF_GUI.Handle_drag, local: true);


            // -1 = left / top
            //  0 = static
            //  1 = right / bottom



#if UNITY_2018
            bool clicked = Event.current.type == EventType.MouseDown && Event.current.button == 0;
#else
            bool clicked = Event.current.type == EventType.mouseDown && Event.current.button == 0;
#endif



            if (clicked)
            {
                xDrag = 0;
                yDrag = 0;
                Vector3 mPos = Event.current.mousePosition;

                /*
                 * bool[,] dragGrid = new bool[3,3]{
                 *      {topLeft.Contains(mPos),		false,				topRight.Contains(mPos)},
                 *      {left.Contains(mPos),		false,					right.Contains(mPos)},
                 *      {lowerLeft.Contains(mPos),	lower.Contains(mPos),	lowerRight.Contains(mPos)}
                 * };*/

                bool[,] dragGrid = new bool[3, 3] {
                    { topLeft.Contains(mPos), left.Contains(mPos), lowerLeft.Contains(mPos) },
                    { false, false, lower.Contains(mPos) },
                    { topRight.Contains(mPos), right.Contains(mPos), lowerRight.Contains(mPos) }
                };



                bool leftSide   = dragGrid[0, 0] || dragGrid[0, 1] || dragGrid[0, 2];
                bool rightSide  = dragGrid[2, 0] || dragGrid[2, 1] || dragGrid[2, 2];
                bool topSide    = dragGrid[0, 0] || dragGrid[1, 0] || dragGrid[2, 0];
                bool bottomSide = dragGrid[0, 2] || dragGrid[1, 2] || dragGrid[2, 2];


                if (leftSide)
                {
                    xDrag = -1;
                }
                else if (rightSide)
                {
                    xDrag = 1;
                }

                if (topSide)
                {
                    yDrag = -1;
                }
                else if (bottomSide)
                {
                    yDrag = 1;
                }


                bool contained = xDrag != 0 || yDrag != 0;


                if (contained)
                {
                    resizing = true;
                    Event.current.Use();
                }
            }



#if UNITY_2018
            if (resizing && Event.current.type == EventType.MouseDrag)
            {
#else
            if (resizing && Event.current.type == EventType.mouseDrag)
            {
#endif

                if (Event.current.delta.sqrMagnitude > 0)
                {
                    UndoRecord("resize node");
                }

                if (xDrag == 1)
                {
                    rect.width += Event.current.delta.x;
                }
                else if (xDrag == -1)
                {
                    rect.xMin += Event.current.delta.x;
                }

                if (yDrag == 1)
                {
                    rect.height += Event.current.delta.y;
                }
                if (yDrag == -1)
                {
                    rect.yMin += Event.current.delta.y;
                }

                //Debug.Log("RESIZING X " + xDrag + " Y " + yDrag);

                ClampSize();

                Event.current.Use();
            }

            if (resizing && SF_GUI.ReleasedRawLMB())
            {
                resizing = false;
                xDrag    = 0;
                yDrag    = 0;
                if (base.isDragging)
                {
                    base.OnRelease();
                }
                Event.current.Use();
            }

            Rect insideHandleRect = LocalRect().PadLeft(size).PadRight(size).PadBottom(size).PadTop(Mathf.Max(15, size));
            DrawInner(insideHandleRect);

            /*
             * if( showColor ) {
             *
             *      texture.Draw( rectInner );
             *
             *      if( SF_Debug.nodes ) {
             *              Rect r = new Rect( 0, 16, 96, 20 );
             *              GUI.color = Color.white;
             *              GUI.skin.box.normal.textColor = Color.white;
             *              GUI.Box( r, "ID: " + id );
             *              r.y += r.height;
             *              //GUI.Box( r, "Cmps: " + texture.CompCount );
             *              //r.y += r.height;
             *              //GUI.Box( r, "Unif: " + texture.dataUniform );
             *
             *      }
             *
             *
             * }*/

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

            //GUI.DragWindow();


            GUI.EndGroup( );


            //if(rect.center.x)
        }
Example #20
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);
        }
Example #21
0
        public void Draw(Vector2 pos)
        {
            bool isUnconnectedChild = IsChild() && !IsConnected();

            if (ShouldBeInvisible())
            {
                return;
            }


            // Don't draw if invalid

            rect = new Rect(pos.x, pos.y, defaultConnectorWidth, 14);

            if (conType == ConType.cInput)
            {
                rect.x -= node.rect.width + rect.width;
            }

            if (conType == ConType.cInput)
            {
                rect.xMin -= node.extraWidthInput;
            }
            else
            {
                rect.width += node.extraWidthOutput;
            }



            //GUIStyle cStyle = conType == ConType.cInput ? EditorStyles.miniButtonRight : EditorStyles.miniButtonLeft;
            //GUIStyle cStyle = (GUIStyle)"ShurikenModuleTitle";



            if (!DisplayLock())
            {
                GUI.color = GetConnectorColor();
                GUI.Box(rect, string.Empty);
                if (SF_GUI.ProSkin)
                {
                    GUI.Box(rect, string.Empty);
                    GUI.Box(rect, string.Empty);
                    GUI.Box(rect, string.Empty);
                }
            }

            if (SF_GUI.ProSkin)
            {
                GUI.color = DisplayAsValid() ? Color.white : Color.grey;
            }
            else
            {
                GUI.color = DisplayAsValid() ? Color.white : new Color(1f, 1f, 1f, 0.25f);
            }

            bool showConditionA = !(Hovering(true) && canValidlyConnectToPending);
            bool showConditionB = !(SF_NodeConnector.pendingConnectionSource == this);

            if (HasErrors() && (showConditionA && showConditionB))
            {
                Rect iconRect = new Rect(rect);
                iconRect.x     -= SF_Styles.IconErrorSmall.width;
                iconRect.height = iconRect.width = 16;
                iconRect.y     -= 1;
                GUI.DrawTexture(iconRect, SF_Styles.IconErrorSmall);
            }



            Rect labelRect = rect;


            if (SF_Debug.nodes)
            {
                Rect typeRect = rect;
                typeRect.width *= 3f;

                if (conType == ConType.cInput)
                {
                    GUI.skin.label.alignment = TextAnchor.MiddleLeft;
                    typeRect.x += rect.width;
                }
                else
                {
                    GUI.skin.label.alignment = TextAnchor.MiddleRight;
                    typeRect.x -= typeRect.width;
                }

                GUI.Label(typeRect, valueType.ToString());
                GUI.skin.label.alignment = TextAnchor.MiddleLeft;
            }



            if (outerLabel)
            {
                labelRect.width = node.rect.width;
                //labelRect.x -= EditorStyles.miniLabel.CalcSize( new GUIContent( label ) ).x + 4;
                labelRect.x += rect.width + 4;
            }



            GUI.Label(labelRect, isUnconnectedChild ? "+" : label, isUnconnectedChild ? EditorStyles.boldLabel : SF_Styles.MiniLabelOverflow);


            if (DisplayLock())
            {
                Rect lockRect = labelRect;
                lockRect.xMin  = node.rect.xMin - lockRect.height - 3;
                lockRect.xMax  = node.rect.xMax;
                lockRect.yMin -= 3;
                lockRect.yMax += 4;
                GUI.color      = new Color(0.8f, 0.8f, 0.8f, 0.3f);
                GUI.Box(lockRect, string.Empty, GUI.skin.button);
                GUI.color = Color.white;
                //GUI.color = Color.white;
                //GUI.Label(lockRect,"//");
                //GUI.drawe
                //GUI.Box(lockRect, "", );
                if (Event.current.type == EventType.Repaint)
                {
                    SF_GUI.DrawLock(lockRect.PadTop(4), "Unavailable when using deferred rendering", TextAlignment.Right);
                }
            }


            CheckIfDeleted();

            GUI.color = Color.white;
        }
Example #22
0
        public static Rect GetBorder(this Rect r, RectBorder border, int size, bool showResizeCursor = false)
        {
            Rect retRect = r;

            // Dimensions
            if (border == RectBorder.Left || border == RectBorder.Right)
            {
                retRect.height = r.height - size * 2;
            }
            else
            {
                retRect.height = size;
            }

            if (border == RectBorder.Top || border == RectBorder.Bottom)
            {
                retRect.width = r.width - size * 2;
            }
            else
            {
                retRect.width = size;
            }

            // Position
            if (border == RectBorder.Left || border == RectBorder.Center || border == RectBorder.Right)
            {
                retRect.y += size;
            }
            if (border == RectBorder.BottomLeft || border == RectBorder.Bottom || border == RectBorder.BottomRight)
            {
                retRect.y += r.height - size;
            }

            if (border == RectBorder.Top || border == RectBorder.Center || border == RectBorder.Bottom)
            {
                retRect.x += size;
            }
            if (border == RectBorder.TopRight || border == RectBorder.Right || border == RectBorder.BottomRight)
            {
                retRect.x += r.width - size;
            }


            if (showResizeCursor)
            {
                MouseCursor cursor;

                if (border == RectBorder.Top || border == RectBorder.Bottom)
                {
                    cursor = MouseCursor.ResizeVertical;
                }
                else if (border == RectBorder.Left || border == RectBorder.Right)
                {
                    cursor = MouseCursor.ResizeHorizontal;
                }
                else if (border == RectBorder.TopLeft || border == RectBorder.BottomRight)
                {
                    cursor = MouseCursor.ResizeUpLeft;
                }
                else if (border == RectBorder.BottomLeft || border == RectBorder.TopRight)
                {
                    cursor = MouseCursor.ResizeUpRight;
                }
                else
                {
                    cursor = MouseCursor.MoveArrow;
                }

                SF_GUI.AssignCursor(retRect, cursor);
            }

            return(retRect);
        }
        public void OnGUI()
        {
            /*
             * selectionBox.x = Event.current.mousePosition.x;
             * selectionBox.y = Event.current.mousePosition.y;
             * selectionBox.width = 128;
             * selectionBox.height = 128;
             */


            if (SF_GUI.ReleasedRawLMB() && boxSelecting)
            {
                ExecuteBoxSelect();
            }


            if (SF_GUI.PressedLMB() && SF_GUI.HoldingBoxSelect())
            {
                boxSelecting = true;

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

                selectionBox.x = Event.current.mousePosition.x;
                selectionBox.y = Event.current.mousePosition.y;
                Event.current.Use();
            }


            // Duplicate, copy, cut, paste
            EventType et = Application.platform == RuntimePlatform.OSXEditor ? EventType.KeyDown : EventType.KeyUp;             // TODO: Use KeyDown for Windows too



            if (SF_GUI.HoldingControl() && Event.current.type == et && !SF_Node.isEditingAnyNodeTextField)
            {
                switch (Event.current.keyCode)
                {
                case (KeyCode.D):
                    DuplicateSelection();
                    break;

                case (KeyCode.C):
                    CopySelection();
                    break;

                case (KeyCode.X):
                    CutSelection();
                    break;

                case (KeyCode.V):
                    PasteFromClipboard();
                    break;
                }
            }

            // Selection box
            if (boxSelecting)
            {
                selectionBox.width  = Event.current.mousePosition.x - selectionBox.x;
                selectionBox.height = Event.current.mousePosition.y - selectionBox.y;

                if (Event.current.isMouse)
                {
                    Event.current.Use();
                }
            }

            if (SF_GUI.PressedDelete() && !SF_Node.isEditingAnyNodeTextField)
            {
                DeleteSelected();
                Event.current.Use();
            }
        }
Example #24
0
        public override void DrawInner(Rect r)
        {
            //Debug.Log("GUI THREAD: " + Event.current.type + " - " + GUI.GetNameOfFocusedControl());

            //if(Event.current.type == EventType.layout)
            //return;

            if (Event.current.type == EventType.Repaint)
            {
                guiIncID++;
            }

            //if(Event.current.type == EventType.repaint)
            //if(hoveringNode){
            //hoveringNode = r.Margin(128).Contains(Event.current.mousePosition);
            //} else {
            hoveringNode = r.Contains(Event.current.mousePosition);
            //}


            if (!isEditing)            // Don't resize while editing
            {
                targetSideButtonWidth = (selected) ? 70f : 0f;
            }


            int sideButtonHeight = 16;
            int buttonTextMargin = 4;

            int sideButtonWidth = Mathf.RoundToInt(currentSideButtonWidth);

            if (Event.current.type == EventType.Repaint)
            {
                currentSideButtonWidth = Mathf.Lerp(currentSideButtonWidth, targetSideButtonWidth, 0.6f);
            }

            Rect txtRect = r;



            txtRect = txtRect.PadRight(/*(int)sideButtonWidth +*/ buttonTextMargin);
            txtRect = txtRect.PadLeft((int)sideButtonWidth * 2 + buttonTextMargin);
            txtRect = txtRect.PadBottom(buttonTextMargin);


            // BUTTONS
            if (sideButtonWidth > 12f)
            {
                Rect btnOutput = txtRect;
                Rect btnInput  = txtRect;
                btnOutput.width  = sideButtonWidth;
                btnInput.width   = sideButtonWidth * 2;
                btnOutput.height = btnInput.height = sideButtonHeight;
                btnOutput.x     += txtRect.width - sideButtonWidth;
                btnInput.x      += -buttonTextMargin / 2 - sideButtonWidth * 2;

                DrawTypecastButtons(btnOutput, btnInput);
            }


            txtRect = txtRect.PadTop((int)(sideButtonWidth * 0.32f));



            if (isEditing && !justFocused && Event.current.type == EventType.Repaint)
            {
                //Debug.Log("GUI THREAD " + Event.current.type + " LOWER");
                if (GUI.GetNameOfFocusedControl() != controlName)
                {
                    //Debug.Log("DEFOCUS - " + Event.current.type + " fc: " + GUI.GetNameOfFocusedControl() );
                    isEditing = false;
                    isEditingAnyNodeTextField = false;
                }
            }



            if (Event.current.type == EventType.Repaint)
            {
                justFocused = false;
            }

            //Debug.Log("GUI THREAD B: " + Event.current.type + " - " + GUI.GetNameOfFocusedControl());

            if (isEditing)
            {
                controlName = base.id + "_codeArea";

                GUI.SetNextControlName(controlName);

                string codeBefore = code;
                //code = GUI.TextArea(txtRect,code,SF_Styles.CodeTextArea);
                code = UndoableTextArea(txtRect, code, "code", SF_Styles.CodeTextArea);

                SF_GUI.AssignCursor(txtRect, MouseCursor.Text);

                //if(copied){
                //	code = codeBefore;
                //	txtEditor.pos += copyLength-1;
                //}


                txtEditor          = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                savedCaretPosition = txtEditor.cursorIndex;
                //txtEditor.selectPos = 4;



                //if(SF_GUI.HoldingControl() && Event.current.type == EventType.keyDown && Event.current.keyCode == KeyCode.C)


                if (Event.current.keyCode == KeyCode.Tab && Event.current.type == EventType.KeyDown)
                {
                    //Debug.Log("Tab");
                    UndoRecord("insert tab in " + functionName + " code");
                    code = code.Insert(txtEditor.cursorIndex, "\t");
                    //Debug.Log("Caret position = " + txtEditor.pos);
                    savedCaretPosition         = txtEditor.cursorIndex;
                    pressedTabLastFrameCounter = 5;                     // Force it for five GUI frames
                    Event.current.Use();
                    GUI.FocusControl(controlName);
                }

                if (pressedTabLastFrameCounter > 0 /*&& GUI.GetNameOfFocusedControl() != controlName*/)
                {
                    GUI.FocusControl(controlName);
                    txtEditor             = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                    txtEditor.cursorIndex = savedCaretPosition + 1;
                    txtEditor.selectIndex = savedCaretPosition + 1;
                    pressedTabLastFrameCounter--;
                }

                /*
                 * if(Event.current.keyCode == KeyCode.Tab && Event.current.type == EventType.keyUp){
                 *      GUI.FocusControl(controlName);
                 *      Event.current.Use();
                 *      GUI.FocusControl(controlName);
                 * }
                 *
                 * if(Event.current.Equals( Event.KeyboardEvent("tab") )){
                 *      GUI.FocusControl(controlName);
                 *      Event.current.Use();
                 *      GUI.FocusControl(controlName);
                 * }*/



                if (code != codeBefore)
                {
                    OnUpdateNode(NodeUpdateType.Soft, false);
                }
                //if(focusBefore != string.Empty && GUI.GetNameOfFocusedControl() != focusBefore){
                //	GUI.FocusControl(focusBefore);
                //}
                //Debug.Log("GUI THREAD B_A_1: " + Event.current.type + " - " + GUI.GetNameOfFocusedControl());
            }
            else
            {
                //Debug.Log("GUI THREAD " + Event.current.type + " UPPER");
                //Debug.Log("GUI THREAD B_B_0: " + Event.current.type + " - " + GUI.GetNameOfFocusedControl());
                GUI.Box(txtRect.PadBottom(1), code, SF_Styles.CodeTextArea);
                if (hoveringNode)
                {
                    bool doubleClicked = Event.current.isMouse && Event.current.type == EventType.MouseDown && Event.current.clickCount == 2;

                    Rect btnRect = new Rect(txtRect.xMax, txtRect.yMax, 46, 16).MovedUp().MovedLeft();
                    btnRect.x -= 3;
                    btnRect.y -= 4;

                    btnRect.xMin -= 3;
                    btnRect.yMin -= 4;

                    // Workaround for a weird issue
                    //bool clickedBtn = btnRect.Contains(Event.current.mousePosition) && Event.current.type == EventType.mouseUp && Event.current.button == 0;

                    //Debug.Log("GUI THREAD B_B_1: " + Event.current.type + " - " + GUI.GetNameOfFocusedControl());
                    if (GUI.Button(btnRect, "Edit", EditorStyles.miniButton) || doubleClicked && Event.current.type == EventType.Repaint)
                    {
                        isEditing = true;
                        //Debug.Log("FOCUS - " + Event.current.type + " fc: " + GUI.GetNameOfFocusedControl() );
                        pressedEditLastFrameCounter = 5;
                        isEditingAnyNodeTextField   = true;
                        GUI.FocusControl(controlName);
                        //	forceFocusCodeField = true;
                        Event.current.Use();
                        justFocused = true;
                    }
                    //Debug.Log("GUI THREAD B_B_2: " + Event.current.type + " - " + GUI.GetNameOfFocusedControl());
                }
            }

            if (pressedEditLastFrameCounter > 0)
            {
                GUI.FocusControl(controlName);
                //Debug.Log("REFOCUSING " + controlName + " fc: " + GUI.GetNameOfFocusedControl() );
                pressedEditLastFrameCounter--;
            }

            //Debug.Log("GUI THREAD C: " + Event.current.type + " - " + GUI.GetNameOfFocusedControl());



            /*
             * if (forceFocusCodeField) {
             *      //GUI.SetNextControlName("focusChange");
             *      if (GUI.GetNameOfFocusedControl() != controlName) {
             *              GUI.FocusControl(controlName);
             *      } else {
             *              forceFocusCodeField = false;
             *      }
             *
             * }*/



            //Debug.Log("GUI THREAD END: " + Event.current.type + " - " + GUI.GetNameOfFocusedControl());
        }
Example #25
0
        public override float DrawInner(ref Rect r)
        {
Restart:
            //int propCount = editor.nodeView.treeStatus.propertyList.Count;

            List <SF_Node> propertyList = editor.nodeView.treeStatus.propertyList;

            //GUI.Label( r.MovedUp(), "propertyList.Count = " + propertyList.Count );

            int propCount = propertyList.Count;

            bool multiple = propCount > 1;


            float prevYpos = r.y;

            r.y = 0;


            if (propCount == 0)
            {
                r.y        += 16;
                GUI.enabled = false;
                GUI.Label(r, "No properties in this shader yet");
                GUI.enabled = true;
                r.y        -= 16;
            }


            r.y    += 23;
            r.xMin += 20;             // Indent
            r.xMax -= 3;



            r.height = propertyHeight;



            // On drop...
            if (draggingProperty != null && SF_GUI.ReleasedRawLMB())
            {
                int moveDist = Mathf.RoundToInt((Event.current.mousePosition.y - startMouseY) / propertyHeight);

                // Execute reordering!
                if (moveDist != 0)                    // See if it actually moved to another slot
                {
                    int newIndex = Mathf.Clamp(dragStartIndex + moveDist, 0, propCount - 1);
                    Undo.RecordObject(editor.nodeView.treeStatus, "property reorder");
                    editor.nodeView.treeStatus.propertyList.RemoveAt(dragStartIndex);
                    //if( newIndex > dragStartIndex )
                    //	newIndex--;
                    editor.nodeView.treeStatus.propertyList.Insert(newIndex, draggingProperty);
                }

                draggingProperty = null;
            }

            float yStart = r.y;


            int i = 0;


            for (int j = 0; j < propertyList.Count; j++)
            {
                SF_Node prop = propertyList[j];


                if (prop.property == null)                    // Due to a weird bug - remove these nodes

                // Disconnect
                {
                    foreach (SF_NodeConnector con in prop.connectors)
                    {
                        if (con.conType == ConType.cOutput)
                        {
                            con.Disconnect();
                        }
                    }
                    prop.Deselect(registerUndo: false);
                    propertyList.Remove(prop);
                    editor.nodeView.treeStatus.propertyList.Remove(prop);
                    editor.nodes.Remove(prop);
                    //Debug.Log("Removing broken property...");
                    DestroyImmediate(prop);
                    goto Restart;
                }


                bool draggingThis = (draggingProperty == prop);
                bool dragging     = (draggingProperty != null);

                r.y = yStart + propertyHeight * i;

                if (draggingThis)
                {
                    r.x -= 5;
                    r.y  = Mathf.Clamp(Event.current.mousePosition.y + dragStartOffsetY, yStart, yStart + propertyHeight * (propCount - 1));
                }
                else if (dragging)
                {
                    if (i < dragStartIndex)
                    {
                        float offset = propertyHeight + SF_Tools.Smoother(Mathf.Clamp(r.y - DragRectPosY, -propertyHeight, 0) / -propertyHeight) * -propertyHeight;
                        r.y += offset;
                    }
                    else if (i > dragStartIndex)
                    {
                        r.y -= propertyHeight - SF_Tools.Smoother(Mathf.Clamp(r.y - DragRectPosY, 0, propertyHeight) / propertyHeight) * propertyHeight;
                    }
                }



                GUI.Box(r, string.Empty, draggingThis ? SF_Styles.HighlightStyle : SF_Styles.NodeStyle);
                bool mouseOver = r.Contains(Event.current.mousePosition);



                // We're now in the property box
                // We need: Grabber, Text field, Internal label



                bool imagePreview  = (prop.property is SFP_Tex2d || prop.property is SFP_Cubemap);
                bool colorInput    = (prop.property is SFP_Color);
                bool checkboxInput = (prop.property is SFP_ToggleProperty || prop.property is SFP_SwitchProperty);


                // GRABBER
                Rect gRect = SF_Tools.GetExpanded(r, -6);
                gRect.width = gRect.height / 2f;

                gRect.yMin += 8;

                Rect gRectCoords = new Rect(gRect);

                gRectCoords.x       = 0;
                gRectCoords.y       = 0;
                gRectCoords.width  /= SF_GUI.Handle_drag.width;
                gRectCoords.height /= SF_GUI.Handle_drag.height;
                if (multiple)
                {
                    GUI.DrawTextureWithTexCoords(gRect, SF_GUI.Handle_drag, gRectCoords);
                }
                gRect.yMin -= 8;

                /*
                 * if( propCount > 1 ) {
                 *      if( gRect.Contains( Event.current.mousePosition ) && SF_GUI.PressedLMB() && !dragging ) {
                 *              dragStartOffsetY = r.y - Event.current.mousePosition.y;
                 *              draggingProperty = prop;
                 *              dragStartIndex = i;
                 *              startMouseY = Event.current.mousePosition.y;
                 *      }
                 *      SF_GUI.AssignCursor( gRect,MouseCursor.Pan);
                 *      GUI.DrawTextureWithTexCoords(gRect, SF_GUI.Handle_drag, gRectCoords );
                 * }
                 */



                // Property type name
                Color c = GUI.color;
                c.a       = 0.5f;
                GUI.color = c;
                Rect propTypeNameRect = new Rect(gRect);
                //propTypeNameRect.x += propTypeNameRect.width + 8;
                propTypeNameRect.y -= 5;
                if (imagePreview || colorInput || checkboxInput)
                {
                    propTypeNameRect.width = r.width - r.height - 38;
                }
                else
                {
                    propTypeNameRect.width = r.width - 48;
                }
                propTypeNameRect.height = 16;
                //if( prop.property != null )
                GUI.Label(propTypeNameRect, prop.property.nameType, EditorStyles.miniLabel);
                propTypeNameRect.x += gRect.width + 8;
                c.a       = 1f;
                GUI.color = c;
                //else
                //return (int)r.yMax;


                // INTERNAL NAME

                if (mouseOver)
                {
                    c.a       = 0.5f;
                    GUI.color = c;
                    Rect intRect = new Rect(propTypeNameRect);
                    intRect.xMin += intRect.width - SF_GUI.WidthOf(prop.property.nameInternal, EditorStyles.label);
                    //SF_GUI.AssignCursor( intRect, MouseCursor.Text );
                    GUI.Label(intRect, prop.property.nameInternal, EditorStyles.label);
                    c.a       = 1f;
                    GUI.color = c;
                }



                // DISPLAY NAME
                Rect dispNameRect = new Rect(propTypeNameRect);
                dispNameRect.y += 18;
                //dispNameRect.x += dispNameRect.width + 4;
                //dispNameRect.height = 16;
                //dispNameRect.y += 10;
                //dispNameRect.width = ( r.width - dispNameRect.width - texRect.width - 20 ) * 0.5f;

                ps.StartIgnoreChangeCheck();
                string bef = prop.property.nameDisplay;
                SF_GUI.AssignCursor(dispNameRect, MouseCursor.Text);
                //if( mouseOver )
                UndoableEnterableNodeTextField(prop.property.node, dispNameRect, ref prop.property.nameDisplay, "change property name", update: false, extra: prop.property);
                //else
                //GUI.Label( dispNameRect, prop.property.nameDisplay, EditorStyles.boldLabel );
                if (prop.property.nameDisplay != bef)                    // Changed
                {
                    prop.property.UpdateInternalName();
                }
                ps.EndIgnoreChangeCheck();



                // Texture preview
                Rect texRect = new Rect(0, 0, 0, 0);
                c = GUI.color;
                if (imagePreview)
                {
                    texRect       = SF_Tools.GetExpanded(new Rect(r), -4);
                    texRect.xMin += texRect.width - texRect.height;
                    //texRect.x += gRect.width + 4;
                    //texRect.width = texRect.height;
                    GUI.Box(SF_Tools.GetExpanded(texRect, 1f), string.Empty, SF_Styles.NodeStyle);
                    GUI.color = Color.white;
                    GUI.DrawTexture(texRect, prop.texture.texture);
                    GUI.color = c;
                }


                if (prop.property is SFP_Slider)
                {
                    SFN_Slider slider = (prop as SFN_Slider);

                    ps.StartIgnoreChangeCheck();
                    Rect sR = new Rect(dispNameRect);
                    sR.y    += sR.height + 5;
                    sR.width = 28;
                    GUI.Label(sR, "Min");
                    //sR.x += sR.width;
                    sR = sR.MovedRight();
                    prop.UndoableEnterableFloatField(sR, ref slider.min, "min value", null);


                    sR = sR.MovedRight();

                    sR.width = r.width - 164;

                    float beforeSlider = slider.current;

                    string sliderName = "slider" + slider.id;
                    GUI.SetNextControlName(sliderName);

                    sR.xMin += 4;
                    sR.xMax -= 4;

                    slider.current = prop.UndoableHorizontalSlider(sR, slider.current, slider.min, slider.max, "value");
                    if (beforeSlider != slider.current)
                    {
                        GUI.FocusControl(sliderName);
                        slider.OnValueChanged();
                    }
                    //SF_GUI.AssignCursor( sR, MouseCursor.Arrow );

                    sR.x    += sR.width + 4;
                    sR.width = 32;
                    prop.UndoableEnterableFloatField(sR, ref slider.max, "max value", null);
                    sR.x += sR.width;
                    GUI.Label(sR, "Max");

                    ps.EndIgnoreChangeCheck();
                }
                else if (colorInput)
                {
                    SFN_Color colNode = (prop as SFN_Color);

                    texRect       = SF_Tools.GetExpanded(new Rect(r), -4);
                    texRect.xMin += texRect.width - texRect.height;
                    //GUI.Box( SF_Tools.GetExpanded( texRect, 1f ), string.Empty, SF_Styles.NodeStyle );
                    GUI.color     = Color.white;
                    texRect.yMax -= 21;
                    texRect.yMin += 15;
                    texRect.xMin += 2;
                    //texRect.xMax -= 2;

                    SF_GUI.AssignCursor(texRect, MouseCursor.Arrow);

                    ps.StartIgnoreChangeCheck();
                    //Color col = EditorGUI.ColorField( texRect, colNode.texture.dataUniform );
                    Color col = colNode.UndoableColorField(texRect, colNode.texture.dataUniform, "set color of " + colNode.property.nameDisplay);
                    ps.EndIgnoreChangeCheck();
                    colNode.SetColor(col);
                    GUI.color = c;
                }
                else if (prop.property is SFP_Vector4Property)
                {
                    SFN_Vector4Property vec4 = (prop as SFN_Vector4Property);

                    ps.StartIgnoreChangeCheck();
                    Rect sR = new Rect(dispNameRect);
                    sR.y    += sR.height + 5;
                    sR.width = 20;

                    int lbWidth = 12;


                    //string channelStr = "XYZW";



                    sR.width = lbWidth;
                    GUI.Label(sR, "X", EditorStyles.miniLabel);
                    sR.x    += sR.width;
                    sR.width = 32;
                    prop.UndoableEnterableFloatField(sR, ref vec4.texture.dataUniform.x, "X channel", EditorStyles.textField);
                    SF_GUI.AssignCursor(sR, MouseCursor.Text);
                    sR.x += sR.width + 3;


                    sR.width = lbWidth;
                    GUI.Label(sR, "Y", EditorStyles.miniLabel);
                    sR.x    += sR.width;
                    sR.width = 32;
                    prop.UndoableEnterableFloatField(sR, ref vec4.texture.dataUniform.y, "Y channel", EditorStyles.textField);
                    SF_GUI.AssignCursor(sR, MouseCursor.Text);
                    sR.x += sR.width + 3;


                    sR.width = lbWidth;
                    GUI.Label(sR, "Z", EditorStyles.miniLabel);
                    sR.x    += sR.width;
                    sR.width = 32;
                    prop.UndoableEnterableFloatField(sR, ref vec4.texture.dataUniform.z, "Z channel", EditorStyles.textField);
                    SF_GUI.AssignCursor(sR, MouseCursor.Text);
                    sR.x += sR.width + 3;


                    sR.width = lbWidth;
                    GUI.Label(sR, "W", EditorStyles.miniLabel);
                    sR.x    += sR.width;
                    sR.width = 32;
                    prop.UndoableEnterableFloatField(sR, ref vec4.texture.dataUniform.w, "W channel", EditorStyles.textField);
                    SF_GUI.AssignCursor(sR, MouseCursor.Text);



                    ps.EndIgnoreChangeCheck();
                }
                else if (prop.property is SFP_ValueProperty)
                {
                    SFN_ValueProperty val = (prop as SFN_ValueProperty);

                    ps.StartIgnoreChangeCheck();
                    Rect sR = new Rect(dispNameRect);
                    sR.y    += sR.height + 5;
                    sR.width = 20;

                    sR.width = 35;
                    GUI.Label(sR, "Value", EditorStyles.miniLabel);
                    sR.x    += sR.width;
                    sR.width = 55;
                    //SF_GUI.EnterableFloatField( prop, sR, ref val.texture.dataUniform.r, EditorStyles.textField );
                    prop.UndoableEnterableFloatField(sR, ref val.texture.dataUniform.x, "value", EditorStyles.textField);
                    SF_GUI.AssignCursor(sR, MouseCursor.Text);
                    ps.EndIgnoreChangeCheck();
                }
                else if (checkboxInput)
                {
                    bool isToggle = (prop.property is SFP_ToggleProperty);

                    bool prevValue = isToggle ? (prop.property.node as SFN_ToggleProperty).on : (prop.property.node as SFN_SwitchProperty).on;



                    ps.StartIgnoreChangeCheck();

                    texRect       = SF_Tools.GetExpanded(new Rect(r), -4);
                    texRect.xMin += texRect.width - texRect.height;
                    //GUI.Box( SF_Tools.GetExpanded( texRect, 1f ), string.Empty, SF_Styles.NodeStyle );

                    texRect.yMax -= 21;
                    texRect.yMin += 15;
                    texRect.xMin += 2;
                    //texRect.xMax -= 2;

                    SF_GUI.AssignCursor(texRect, MouseCursor.Arrow);

                    bool newValue = prevValue;

                    if (isToggle)
                    {
                        prop.property.node.UndoableToggle(texRect, ref (prop.property.node as SFN_ToggleProperty).on, "", "property checkbox", EditorStyles.toggle);
                        newValue = (prop.property.node as SFN_ToggleProperty).on;
                    }
                    else
                    {
                        prop.property.node.UndoableToggle(texRect, ref (prop.property.node as SFN_SwitchProperty).on, "", "property checkbox", EditorStyles.toggle);
                        newValue = (prop.property.node as SFN_SwitchProperty).on;
                    }

                    if (newValue != prevValue)
                    {
                        //if(isToggle){
                        //	(prop.property.node as SFN_ToggleProperty).on = newValue;
                        //} else {
                        //	(prop.property.node as SFN_SwitchProperty).on = newValue;
                        ////}
                        if (isToggle)
                        {
                            prop.property.node.texture.dataUniform = Color.white * (newValue ? 1f : 0f);
                        }
                        else
                        {
                            //prop.property.node.texture.UpdateColorPreview("",true);
                        }
                        prop.property.node.OnUpdateNode(NodeUpdateType.Soft);
                    }
                    ps.EndIgnoreChangeCheck();
                }



                if (r.Contains(Event.current.mousePosition) && SF_GUI.PressedLMB() && !dragging && multiple)
                {
                    dragStartOffsetY = r.y - Event.current.mousePosition.y;
                    draggingProperty = prop;
                    dragStartIndex   = i;
                    startMouseY      = Event.current.mousePosition.y;
                    editor.Defocus();
                }
                if (multiple)
                {
                    SF_GUI.AssignCursor(r, MouseCursor.Pan);
                }



                if (draggingThis)
                {
                    r.x += 5;
                }

                //GUI.Label( r, "prop.property.nameType = " + prop.property.nameType );

                r.y += propertyHeight;
                i++;
            }



            r.y      = yStart + propCount * propertyHeight;
            r.height = 20;

            r.y += prevYpos;

            return(r.yMax);
        }
        public SF_EditorNodeData CheckHotkeyInput(bool mouseOverSomeNode)
        {
            bool mouseInNodeView = SF_Editor.instance.nodeView.MouseInsideNodeView(false);


            if (Event.current.type == EventType.Repaint)
            {
                smoothHotkeySelectorIndex = Mathf.Lerp(smoothHotkeySelectorIndex, hotkeySelectorIndex, 0.5f);
            }

            bool useScroll = SF_Settings.quickPickScrollWheel;

            if (holding && Event.current.type == EventType.ScrollWheel && HotkeyFriends.Count > 0 && mouseInNodeView)
            {
                if (useScroll)
                {
                    hotkeySelectorIndex += (int)Mathf.Sign(Event.current.delta.y);
                    hotkeySelectorIndex  = Mathf.Clamp(hotkeySelectorIndex, 0, HotkeyFriends.Count - 1);
                }


                // hotkeySelectorIndex = ( hotkeySelectorIndex + HotkeyFriends.Count ) % HotkeyFriends.Count; // Wrap
                Event.current.Use();
            }

            if (key == KeyCode.None)
            {
                return(null);
            }

            if (Event.current.keyCode == key)
            {
                if (Event.current.type == EventType.KeyDown && !SF_GUI.HoldingControl() && holding == false && mouseInNodeView)
                {
                    hotkeySelectorIndex       = defaultHotkeySelectorIndex;
                    smoothHotkeySelectorIndex = defaultHotkeySelectorIndex;

                    quickpickerStartPosition = Event.current.mousePosition;

                    holding = true;
                }
                if (Event.current.rawType == EventType.KeyUp)
                {
                    holding = false;
                }
            }



            if (holding && !mouseOverSomeNode)
            {
                float width   = 166f; // nodeName.Length*8 + 10;
                Rect  dispPos = new Rect(0, 0, width, 36);

                Vector2 centerPos = useScroll ? Event.current.mousePosition : quickpickerStartPosition;

                dispPos.center = centerPos;
                dispPos.y     -= dispPos.height * 0.3333f;

                //
                //GUI.Box(dispPos, nodeName, GUI.skin.button);
                //



                // Draw hotkey node picker
                //if(Event.current.type == EventType.keyDown){
                //Debug.Log(Event.current.keyCode);
                Rect nRect = dispPos; //new Rect(0,0,128,32);
                nRect.center = centerPos - Vector2.up * nRect.height * 0.3333f;
                //nRect = nRect.MovedRight();
                if (useScroll)
                {
                    nRect.y -= nRect.height * smoothHotkeySelectorIndex;
                }
                else
                {
                    nRect.y -= nRect.height * defaultHotkeySelectorIndex;
                }
                //if(Event.current.keyCode != KeyCode.None){

                Color prevCol = GUI.color;



                int i = 0;
                foreach (SF_EditorNodeData node in HotkeyFriends)
                {
                    //float dist = Mathf.Abs(smoothHotkeySelectorIndex - i);
                    //float alpha = Mathf.Clamp(1f-Mathf.Clamp01(dist*0.25f), 0.2f, 0.8f);


                    float offset = 0f;//(dist*dist)/3f;



                    //if(i == hotkeySelectorIndex){
                    //alpha = 1;
                    //offset -= 8f;
                    //GUI.Box(nRect, node.nodeName, PopupButtonStyle);
                    //}
                    Rect newNRect = nRect;
                    newNRect.x += offset;


                    if (!useScroll && newNRect.Contains(Event.current.mousePosition))
                    {
                        hotkeySelectorIndex = i;
                    }

                    bool selected = (i == hotkeySelectorIndex);

                    if (selected)
                    {
                        GUI.color = new Color(1f, 1f, 1f, 1f);
                    }
                    else
                    {
                        GUI.color = new Color(0.6f, 0.6f, 0.6f, 0.5f);
                    }

                    if (node.isProperty)
                    {
                        GUI.color *= SF_Node.colorExposed;
                    }

                    Texture2D icon = SF_Resources.LoadNodeIcon(node.type.Split('.')[1].ToLower());

                    if (icon != null)
                    {
                        newNRect.width -= newNRect.height;
                    }

                    //if(useScroll){
                    GUI.Box(newNRect, node.nodeName, PopupButtonStyle);
                    //} else {
                    //if(GUI.Button(newNRect, node.nodeName, PopupButtonStyle)){
                    //hotkeySelectorIndex = i;
                    //}
                    //}



                    if (icon != null)
                    {
                        Rect iconRect = newNRect;
                        iconRect       = iconRect.MovedRight();
                        iconRect.width = iconRect.height;
                        GUI.color      = selected ? Color.white : new Color(1f, 1f, 1f, 0.4f);
                        GUI.DrawTexture(iconRect, icon);
                    }



                    nRect = nRect.MovedDown();

                    i++;
                }
                GUI.color = prevCol;



                //}
                if (Event.current.type == EventType.KeyDown /* && Event.current.type == EventType.layout*/ /*&& GUI.GetNameOfFocusedControl() == "defocus"*/)
                {
                    Event.current.Use();
                }
                //}

                //}

                //GUI.Label(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 256,32),"currentindex = " + hotkeySelectorIndex);
            }



            bool clicked = Event.current.type == EventType.MouseDown;

            if (holding && clicked)
            {
                return(HotkeyFriends[hotkeySelectorIndex]);
            }
            else
            {
                return(null);
            }
        }
Example #27
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;
                            }
                        }
                    }
                }
            }
        }
Example #28
0
        public static int ContentScaledToolbar(Rect r, string label, int selected, string[] labels)
        {
            r.height = 15;

            Rect rLeft  = new Rect(r);
            Rect rRight = new Rect(r);

            rLeft.width  = SF_GUI.WidthOf(label, EditorStyles.miniLabel) + 4;
            rRight.width = r.width - rLeft.width;
            rRight.x    += rLeft.width;

            GUI.Label(rLeft, label, EditorStyles.miniLabel);


            // Full pixel width of strings:
            float[] lblPxWidth   = new float[labels.Length];
            float   pxWidthTotal = 0;

            for (int i = 0; i < labels.Length; i++)
            {
                lblPxWidth[i] = SF_GUI.WidthOf(labels[i], EditorStyles.miniButtonMid);
                pxWidthTotal += lblPxWidth[i];
            }

            // Scale all buttons to fit the rect
            float scale = rRight.width / pxWidthTotal;

            for (int i = 0; i < labels.Length; i++)
            {
                lblPxWidth[i] *= scale;
            }



            GUIStyle style  = EditorStyles.miniButtonLeft;
            int      retval = selected;

            Rect rTemp = new Rect(rRight);

            for (int i = 0; i < labels.Length; i++)
            {
                rTemp.width = lblPxWidth[i];

                if (i == labels.Length - 1)
                {
                    style = EditorStyles.miniButtonRight;
                }
                else if (i > 0)
                {
                    style = EditorStyles.miniButtonMid;
                }

                bool prev   = selected == i;
                bool newVal = GUI.Toggle(rTemp, prev, labels[i], style);
                if (newVal != prev)
                {
                    retval = i;
                }

                rTemp.x += rTemp.width;
            }
            GUI.color = Color.white;
            return(retval);
        }
Example #29
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;
            }
        }
Example #30
0
        public override float DrawInner(ref Rect r)
        {
            float prevYpos = r.y;

            r.y = 0;

            r.y    += 20;
            r.xMin += 20; // Indent

            BlendModePreset before = blendModePreset;

            GUI.enabled     = ps.catLighting.renderPath == SFPSC_Lighting.RenderPath.Forward;
            blendModePreset = (BlendModePreset)UndoableLabeledEnumPopupNamed(r, "混合模式", blendModePreset, strBlendModePreset, "blend mode");
            GUI.enabled     = true;
            if (blendModePreset != before)
            {
                ConformBlendsToPreset();
            }
            if (blendModePreset == BlendModePreset.Custom)
            {
                GUI.color = new Color(1f, 1f, 1f, 0.5f);
                GUI.Label(r.PadLeft(70).PadTop(-1), "自定义混合 点击选择预设", EditorStyles.miniLabel);
                GUI.color = Color.white;
            }

            r.y += 20;

            //if( blendModePreset != BlendModePreset.Opaque ) {
            //if( blendModePreset != BlendModePreset.Custom )
            //GUI.enabled = false;
            //EditorGUILayout.BeginHorizontal( GUILayout.Width( maxWidth ) );
            //{
            //Indent();

            string srcStr      = "来源 * ";
            string dstStr      = " + 目标 * ";
            int    srcStrWidth = SF_GUI.WidthOf(srcStr, EditorStyles.miniLabel);
            int    dstStrWidth = SF_GUI.WidthOf(dstStr, EditorStyles.miniLabel);
            int    fieldWidth  = Mathf.FloorToInt((r.width - srcStrWidth - dstStrWidth) / 2);

            Rect rSrcLb    = new Rect(r); rSrcLb.width = srcStrWidth;
            Rect rSrcField = new Rect(r); rSrcField.x = rSrcLb.xMax; rSrcField.width = fieldWidth;
            Rect rDstLb    = new Rect(r); rDstLb.x = rSrcField.xMax; rDstLb.width = dstStrWidth;
            Rect rDstField = new Rect(rSrcField); rDstField.x = rDstLb.xMax;

            EditorGUI.BeginChangeCheck();

            GUI.Label(rSrcLb, srcStr, EditorStyles.miniLabel);
            blendSrc = (BlendMode)UndoableEnumPopup(rSrcField, blendSrc, "blend source");
            GUI.Label(rDstLb, dstStr, EditorStyles.miniLabel);
            blendDst = (BlendMode)UndoableEnumPopup(rDstField, blendDst, "blend destination");

            if (EditorGUI.EndChangeCheck())
            {
                ConformPresetToBlend();
            }

            //if( blendModePreset != BlendModePreset.Custom )
            //GUI.enabled = true;

            r.y += 20;
            //}


            UndoableColorMask(r, "颜色遮罩", ref colorMask);
            r.y += 20;

            bool canEditDithering = editor.mainNode.alphaClip.IsConnectedAndEnabled();

            EditorGUI.BeginDisabledGroup(!canEditDithering);
            if (canEditDithering)
            {
                dithering = (Dithering)UndoableLabeledEnumPopupNamed(r, "抖动的 alpha 剪辑", dithering, strDithering, "dithered alpha clip");
            }
            else
            {
                UndoableLabeledEnumPopup(r, "抖动的 alpha 剪辑", Dithering.Off, "dithered alpha clip");
            }
            EditorGUI.EndDisabledGroup();
            r.y += 20;

            bool canEditAlphaToCoverage = editor.mainNode.alphaClip.IsConnectedAndEnabled() || editor.mainNode.alpha.IsConnectedAndEnabled();

            EditorGUI.BeginDisabledGroup(!canEditAlphaToCoverage);
            if (canEditAlphaToCoverage)
            {
                alphaToCoverage = UndoableToggle(r, alphaToCoverage, "Alpha 叠加(MSAA 一起发送)", "alpha to coverage");
            }
            else
            {
                GUI.Toggle(r, false, "Alpha 叠加(MSAA 一起发送)");
            }
            EditorGUI.EndDisabledGroup();
            r.y += 20;


            OffsetBlock(ref r);


            RefractionBlock(ref r);


            FogBlock(ref r);

            SortingBlock(ref r);



            StencilBlock(ref r);

            r.y += prevYpos;

            return((int)r.yMax);
        }