Beispiel #1
0
    public bool CanLinkTo(EditorPin Other)
    {
        if (OwnerID != Other.OwnerID)
        {
            if (PinLinkType == EPinLinkType.Input && Other.PinLinkType == EPinLinkType.Output)
            {
                if (TypeInfo == null && Other.TypeInfo == null)
                {
                    return(true);
                }
                else
                {
                    if (TypeInfo.TypeString.Equals(Other.TypeInfo.TypeString))
                    {
                        return(true);
                    }
                    else
                    {
                        Debug.LogWarning("My type = " + TypeInfo.TypeString + ", their type = " + TypeInfo.TypeString);
                    }
                }
            }
            else
            {
                Debug.LogWarning("My Link Type = " + PinLinkType + ", other Link Type = " + Other.PinLinkType);
                Debug.LogWarning("Mine should be input, theirs output.");
            }
        }
        else
        {
            Debug.LogWarning(OwnerID + " == " + Other.OwnerID);
        }

        return(false);
    }
    public Rect GetPinRect(int ID)
    {
        EditorPin    Pin      = Pins[ID];
        EPinLinkType LinkType = Pin.GetPinLinkType();

        int TypeIndex = 1;

        for (int Index = 0; Index < ID; ++Index)
        {
            if (Pins[Index].GetPinLinkType() == LinkType)
            {
                ++TypeIndex;
            }
        }

        Rect    ReturnRect   = new Rect();
        Vector2 RectPosition = new Vector2();

        ReturnRect.width  = _renderData.PinSize;
        ReturnRect.height = _renderData.PinSize;
        RectPosition.y    = _renderData.NodeRect.position.y + _renderData.PinVerticalOffset + TypeIndex * (ReturnRect.height + _renderData.PinVerticalSpacing);
        if (LinkType == EPinLinkType.Input)
        {
            RectPosition.x = _renderData.NodeRect.position.x + _renderData.InputPinHorizontalOffset;
        }
        else
        {
            RectPosition.x = _renderData.NodeRect.position.x + _renderData.OutputPinHorizontalOffset - _renderData.PinSize;
        }
        ReturnRect.position = RectPosition;

        return(ReturnRect);
    }
    private int AddPin(EPinLinkType _LinkType, System.Type _Type, string _Name)
    {
        int PinID = Pins.Count;

        Debug.Log("Adding pin to node with ID " + ID + ", pinID = " + PinID);
        EditorPin NewPin = new EditorPin((_Type == null) ? "null" : _Type.ToString(), _Name, ID, PinID, _LinkType);

        Pins.Add(NewPin);
        UpdateNodeRect();
        return(PinID);
    }
    public bool LinkPins(EditorPinIdentifier pinA, EditorPinIdentifier pinB)
    {
        EditorPin pinAData = GraphToEdit.GetPinFromID(pinA);
        EditorPin pinBData = GraphToEdit.GetPinFromID(pinB);

        if (!pinBData.CanLinkTo(pinAData))
        {
            Debug.LogWarning("Failed to link pin " + pinA + " to " + pinB + ".");
            return(false);
        }

        GraphToEdit.LinkPins(pinA, pinB);
        return(true);
    }
    private int GetNumPins(EPinLinkType PinLinkType)
    {
        int OutNumPins = 0;

        for (int PinIndex = 0; PinIndex < PinCount; ++PinIndex)
        {
            EditorPin Pin = Pins[PinIndex];
            if (Pin.GetPinLinkType() == PinLinkType)
            {
                ++OutNumPins;
            }
        }
        return(OutNumPins);
    }
    public EditorPin GetPinFromID(EditorPinIdentifier PinIdentifier)
    {
        if (PinMap == null)
        {
            PinMap = new Dictionary <EditorPinIdentifier, EditorPin>();
        }
        else if (PinMap.ContainsKey(PinIdentifier))
        {
            return(PinMap[PinIdentifier]);
        }

        EditorNode _Node = GetNodeFromID(PinIdentifier.NodeID);

        if (_Node != null)
        {
            EditorPin Pin = _Node.GetPin(PinIdentifier.PinID);
            PinMap[PinIdentifier] = Pin;
            return(Pin);
        }

        return(null);
    }
 private bool RemovePin(EditorPin _Pin)
 {
     return(Pins.Remove(_Pin));
 }