예제 #1
0
        public void DoDraggedEdge()
        {
            if (_sDragSourceSlot != null)
            {
                EventType typeForControl = Event.current.GetTypeForControl(0);
                if (typeForControl != EventType.Repaint)
                {
                    if (typeForControl == EventType.MouseDrag)
                    {
                        _sDropTarget = null;
                        DontDrawEdge = null;
                        Event.current.Use();
                    }
                }
                else
                {
                    Assembly unityEngineAssembly = Assembly.GetAssembly(typeof(UnityEngine.GUI));
                    Type     guiClipType         = unityEngineAssembly.GetType("UnityEngine.GUIClip", true);

                    FieldInfo propInfo = typeof(Slot).GetField(
                        "m_Position",
                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                    if (propInfo == null)
                    {
                        Debug.LogError("PropInfo m_Position is null!");
                    }
                    Rect position = (Rect)propInfo.GetValue(_sDragSourceSlot);

                    Vector2 end = Event.current.mousePosition;

                    if (_sDropTarget != null)
                    {
                        Rect position2 = (Rect)propInfo.GetValue(_sDropTarget);

                        object[]          endArgs = { new Vector2(position2.x, position2.y + 9f) };
                        ParameterModifier endP    = new ParameterModifier(1);
                        endP[0] = true;
                        ParameterModifier[] endMods     = { endP };
                        MethodInfo          endClipRect = guiClipType.GetMethod(
                            "Clip",
                            BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic |
                            BindingFlags.FlattenHierarchy,
                            Type.DefaultBinder,
                            new Type[] { typeof(Vector2) },
                            endMods);

                        end = (Vector2)endClipRect.Invoke(null, endArgs);
                    }

                    object[]          startArgs = { new Vector2(position.xMax, position.y + 9f) };
                    ParameterModifier startP    = new ParameterModifier(1);
                    startP[0] = true;
                    ParameterModifier[] startMods     = { startP };
                    MethodInfo          startClipRect = guiClipType.GetMethod(
                        "Clip",
                        BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic |
                        BindingFlags.FlattenHierarchy,
                        Type.DefaultBinder,
                        new Type[] { typeof(Vector2) },
                        startMods);

                    Vector2 start = (Vector2)startClipRect.Invoke(null, startArgs);

                    Color edgeColor = Color.white;
                    if (_sDragSourceSlot.dataType != null)
                    {
                        edgeColor = UdonGraphGUI.MapTypeToColor(_sDragSourceSlot.dataType);
                    }

                    DrawEdge(start, end, (Texture2D)Styles.selectedConnectionTexture.image, edgeColor, edgeStyle);
                }
            }
        }
예제 #2
0
        public void DoEdges()
        {
            int num  = 0;
            int num2 = 0;

            if (Event.current.type == EventType.Repaint)
            {
                foreach (Edge current in host.graph.edges)
                {
                    if (current == DontDrawEdge || current == MoveEdge)
                    {
                        continue;
                    }

                    Texture2D tex = (Texture2D)Styles.connectionTexture.image;
                    if (num < edgeSelection.Count && edgeSelection[num] == num2)
                    {
                        num++;
                        tex = (Texture2D)Styles.selectedConnectionTexture.image;
                    }

                    // TODO: CLEAN-UP
                    Color color;
                    if (!current.toSlot.isFlowSlot && current.toSlot.dataType != null &&
                        current.toSlot.dataType.IsSubclassOf(typeof(UnityEngine.Object)))
                    {
                        color = EdgeGUI.kObjectTypeEdgeColor;
                    }

                    Color niceGrey = new Color(.85f, .85f, .85f);
                    color = current.fromSlot.dataType != null?UdonGraphGUI.MapTypeToColor(current.fromSlot.dataType) : niceGrey;

                    Color endColor = new Color(.85f, .85f, .85f);
                    if (current.toSlot.dataType != null)
                    {
                        endColor = UdonGraphGUI.MapTypeToColor(current.toSlot.dataType);
                    }

                    DrawEdge(current, tex, color != endColor ? Color.Lerp(color, endColor, .5f) : color, edgeStyle);
                    num2++;
                }
            }

            if (_sDragSourceSlot == null)
            {
                return;
            }
            if (Event.current.type != EventType.MouseUp)
            {
                return;
            }

            if (MoveEdge != null)
            {
                host.graph.RemoveEdge(MoveEdge);
                MoveEdge = null;
            }

            if (_sDropTarget != null)
            {
                return;
            }

            EndDragging();
            Event.current.Use();
        }