Ejemplo n.º 1
0
 private void ReconstructBezier(float offset, int id)
 {
     this[ConnectionLineStyle.Bezier, id] = GUILines.ConnectionBezierOffsetArray(
         offset,
         connector,
         connector.inputCon,
         bezierSegments
         );
 }
Ejemplo n.º 2
0
        public void Draw()
        {
            if (aboutToBeDeleted && !connector.IsConnected())             // It's disconnected, don't mark it anymore
            {
                aboutToBeDeleted = false;
            }

            if (!connector.IsConnected())
            {
                return;
            }

#if UNITY_2018
            if (Event.current.rawType != EventType.Repaint)
#else
            if (Event.current.rawType != EventType.repaint)
#endif
            { return; }

            //Vector2 a = connector.GetConnectionPoint();
            //Vector2 b = connector.inputCon.GetConnectionPoint();
            int  cc          = connector.GetCompCount();
            bool isMatrix4x4 = (cc == 16);
            if (isMatrix4x4)
            {
                cc = 1;
            }

            Color color = DeleteImminent() ? new Color(1f, 0f, 0f, 0.7f) : connector.GetConnectionLineColor();

            // TEMP:
            ReconstructShapes();

            //GUILines.DrawStyledConnection( editor, a, b, cc,  color);


            //switch(SF_Settings.ConnectionLineStyle){
            //case ConnectionLineStyle.Bezier:
            if (isMatrix4x4)
            {
                //GUILines.DrawMatrixConnection( editor, connector.GetConnectionPoint(), connector.inputCon.GetConnectionPoint(), color );
                GUILines.DrawLines(editor, this[ConnectionLineStyle.Bezier, 0], color, GetConnectionWidth(), true);
                GUILines.DrawLines(editor, this[ConnectionLineStyle.Bezier, 1], color, GetConnectionWidth(), true, true);
                GUILines.DrawLines(editor, this[ConnectionLineStyle.Bezier, 2], color, GetConnectionWidth(), true);
            }
            else
            {
                for (int i = 0; i < cc; i++)
                {
                    GUILines.DrawLines(editor, this[ConnectionLineStyle.Bezier, i], color, GetConnectionWidth(), true);
                }
            }

            //break;
            //}
        }
Ejemplo n.º 3
0
        public static void DrawLinearConnection(SF_Editor editor, Vector2 p0, Vector2 p1, float offset, Color col)
        {
            p0 = editor.nodeView.ZoomSpaceToScreenSpace(p0);
            p1 = editor.nodeView.ZoomSpaceToScreenSpace(p1);

            p0 += new Vector2(0f, offset);
            p1 += new Vector2(0f, offset);

            GUILines.DrawLine(p0, p1, col, connectionWidth, true);
        }
Ejemplo n.º 4
0
        public static void DrawDashedLine(SF_Editor editor, Vector2 p0, Vector2 p1, Color col, float dashLength)
        {
//			p0 = editor.nodeView.ZoomSpaceToScreenSpace( p0 );
//			p1 = editor.nodeView.ZoomSpaceToScreenSpace( p1 );

            float frac = dashLength / (p0 - p1).magnitude;

            //int segcount = Mathf.Max(1, Mathf.RoundToInt(1f/frac));

            for (float t = 0; t < 1; t += frac * 2f)
            {
                float tNext = Mathf.Min(1f, t + frac);

                GUILines.DrawLine(Vector2.Lerp(p0, p1, t), Vector2.Lerp(p0, p1, tNext), col, connectionWidth, true);
            }
        }
Ejemplo n.º 5
0
        public static void DrawRectilinearConnection(SF_Editor editor, Vector2 p0, Vector2 p1, float offset, Color col)
        {
            p0 = editor.nodeView.ZoomSpaceToScreenSpace(p0);
            p1 = editor.nodeView.ZoomSpaceToScreenSpace(p1);

            p0 += new Vector2(0f, offset);
            p1 += new Vector2(0f, offset);


            Vector2 p0t = new Vector2((p0.x + p1.x) / 2f + (p0.y < p1.y ? -offset : offset), p0.y);
            Vector2 p1t = new Vector2(p0t.x, p1.y);


            GUILines.DrawLine(p0, p0t, col, connectionWidth, true);
            GUILines.DrawLine(p0t, p1t, col, connectionWidth, true);
            GUILines.DrawLine(p1t, p1, col, connectionWidth, true);
        }
Ejemplo n.º 6
0
        public static void DrawBezierConnection(SF_Editor editor, Vector2 p0, Vector2 p1, float offset, Color col, bool railway = false)
        {
            p0 = editor.nodeView.ZoomSpaceToScreenSpace(p0);
            p1 = editor.nodeView.ZoomSpaceToScreenSpace(p1);

            Vector2 p0t = p0;
            Vector2 p1t = p1;

            bool reversed = p0.x < p1.x;

            float hDist = Mathf.Max(20f, Mathf.Abs(p0.x - p1.x) * 0.5f);

            p0t.x = p0.x - hDist;
            p1t.x = p1.x + hDist;

            int segments = 25;

            if (!reversed)
            {
                if (offset == 0)
                {
                    GUILines.DrawCubicBezier(p0, p0t, p1t, p1, col, connectionWidth, true, segments, railway);
                }
                else
                {
                    GUILines.DrawCubicBezierOffset(offset, p0, p0t, p1t, p1, col, connectionWidth, true, segments);
                }
            }
            else
            {
                Vector2 mid   = (p0 + p1) * 0.5f;
                Vector2 mid0t = new Vector2(p0t.x, mid.y);
                Vector2 mid1t = new Vector2(p1t.x, mid.y);
                if (offset == 0)
                {
                    GUILines.DrawCubicBezier(p0, p0t, mid0t, mid, col, connectionWidth, true, segments, railway);
                    GUILines.DrawCubicBezier(mid, mid1t, p1t, p1, col, connectionWidth, true, segments, railway);
                }
                else
                {
                    GUILines.DrawCubicBezierOffset(offset, p0, p0t, mid0t, mid, col, connectionWidth, true, segments);
                    GUILines.DrawCubicBezierOffset(offset, mid, mid1t, p1t, p1, col, connectionWidth, true, segments);
                }
            }
        }
Ejemplo n.º 7
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;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
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);
        }
        public override void DrawLowerPropertyBox()
        {
            EditorGUI.BeginChangeCheck();
            Rect r = lowerRect;

            r.height = 24;
            r.width  = 26;
            r.y     -= 26;

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

            r = r.PadTop(1).PadBottom(1).PadLeft(2);

            r.width = r.height + 2;
            //r.xMin += 3;

            //Handles.BeginGUI(rect);

            bool hovering = rect.Contains(Event.current.mousePosition + rect.TopLeft());



            if (hovering)
            {
                targetConnectorHeight = on ? 43 : 23;
                Vector2 p0 = new Vector2(rect.width, 23);
                Vector2 p1 = new Vector2(0, smoothConnectorHeight);
                GUILines.QuickBezier(p0, p1, conLineBg, 12, 5);
                GUILines.QuickBezier(p0, p1, conLineFg, 12, 3);
                GUILines.QuickBezier(p0, p1, conLineFg, 12, 3);
                bool prevVal = on;
                GUI.color = new Color(SF_Node.colorExposed.r, SF_Node.colorExposed.g, SF_Node.colorExposed.b, GUI.color.a);
                bool newVal = GUI.Button(r, string.Empty) ? !prevVal : prevVal;

                if (newVal)
                {
                    Rect chkRect = r;
                    chkRect.width  = SF_GUI.Toggle_check_icon.width;
                    chkRect.height = SF_GUI.Toggle_check_icon.height;
                    chkRect.x     += (r.width - chkRect.width) * 0.5f;
                    chkRect.y     += 2;
                    GUI.DrawTexture(chkRect, SF_GUI.Toggle_check_icon);
                }

                GUI.color = Color.white;

                if (prevVal != newVal)
                {
                    string dir = on ? "on" : "off";
                    UndoRecord("switch " + dir + " " + property.nameDisplay);
                    on = newVal;
                    OnUpdateNode(NodeUpdateType.Soft, true);
                    editor.shaderEvaluator.ApplyProperty(this);
                }
            }


            //GUILines.DrawMultiBezierConnection(editor,,GetEvaluatedComponentCount(),Color.white);

            //Handles.DrawLine(new Vector3(0,0),new Vector3(32,32));
            //
            //Handles.EndGUI();



            //GUI.enabled = true;
        }