public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        BezierCurve4PointRenderer curve      = (BezierCurve4PointRenderer)target;
        RectTransform             startPoint = curve.point1;
        RectTransform             endPoint   = curve.point4;

        if (GUILayout.Button("Update location"))
        {
            curve.snapEndpointsToConnectors();
        }
    }
Beispiel #2
0
    public void drawConnectionCurves()
    {
        StoryEditorManager sem = FindObjectOfType <StoryEditorManager>();

        foreach (GameObject element in nodeParts) //for every element in this pages nodeparts
        {
            ElementNodeGraphicManager engm = element.GetComponent <ElementNodeGraphicManager>();
            int connectionKey = 0;                                              //this will increment with every processed selection connector so that it will apply each connection to a selection connector
            foreach (GameObject selectionConnector in engm.selectionConnectors) //for every selection connector in this element
            {
                //get the connection
                ConnectionInfo            connection = engm.associatedElement.GetComponent <PageElementEventTrigger>().connections[connectionKey++];
                BezierCurve4PointRenderer curve      = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/StoryEditor/CurveRenderer.prefab")
                                                                              , contentWindow).GetComponent <BezierCurve4PointRenderer>();

                selectionConnector.GetComponentInChildren <ManipulateNodeLines>().curve = curve;
                curve.originConnector = selectionConnector.GetComponentInChildren <ManipulateNodeLines>().gameObject;

                foreach (GameObject graphic in sem.pageGraphics)
                {
                    PageNodeGraphicManager pngm = graphic.GetComponent <PageNodeGraphicManager>();
                    if (connection.connectedPage.Equals(pngm.page))                                                                                //if the connected page matches this page
                    {
                        if (connection.connectedElement != null)                                                                                   //if its connected to an element node and not a page node
                        {
                            foreach (GameObject otherElement in pngm.nodeParts)                                                                    //check all the elements in the origin page
                            {
                                if (connection.connectedElement.Equals(otherElement.GetComponent <ElementNodeGraphicManager>().associatedElement)) //when one matches thats the origin connector
                                {
                                    ReceiveNodeLines rnl = otherElement.GetComponentInChildren <ReceiveNodeLines>();
                                    curve.receivingConnector = rnl.gameObject;
                                    rnl.curves.Add(curve);
                                }
                            }
                        }
                        else
                        {
                            //The first ReceiveNodeLines should be the PageNodeConnector receiver since it his highest in hierarchy
                            ReceiveNodeLines rnl = pngm.GetComponentInChildren <ReceiveNodeLines>();
                            curve.receivingConnector = rnl.gameObject;
                            rnl.curves.Add(curve);
                        }
                    }
                }
                curve.setAction(connection.action);
                curve.snapEndpointsToConnectors();
            }
        }
    }
    private PageElementEventTrigger peet; //The peet this element is associated with

    void Start()
    {
        peet          = GetComponentInParent <ElementNodeGraphicManager>().associatedElement.GetComponent <PageElementEventTrigger>();
        connectionKey = GetComponentInChildren <ManipulateNodeLines>().connectionKey;
        dropdown      = GetComponentInChildren <Dropdown>();

        dropdown.onValueChanged.AddListener(delegate
        {
            //Check to see if the change is still valid to the connector it is connected to (Can call hide and show both on an element but not on a page)
            //If valid, change action and color of curve, otherwise break the link
            try
            {
                connectionKey = GetComponentInChildren <ManipulateNodeLines>().connectionKey;
                PageElementEventTrigger.Action selection = getDropdownSelection();
                if (selection == PageElementEventTrigger.Action.Change || selection == PageElementEventTrigger.Action.Edit) //These can only be connected to page connectors
                {
                    BezierCurve4PointRenderer curve = GetComponentInChildren <ManipulateNodeLines>().curve;
                    if (peet.connections[connectionKey].connectedElement != null) //if the connected receiver is from an Element then it cannot be page changed to
                    {
                        Debug.Log("Breaking link because trying to Change to Element");
                        curve.breakLink();
                    }
                    else
                    {
                        Debug.Log("Changing old selection to Change");
                        peet.connections[connectionKey].action = selection;
                        curve.setAction(selection);
                    }
                }
                else
                {
                    BezierCurve4PointRenderer curve = GetComponentInChildren <ManipulateNodeLines>().curve;
                    if (peet.connections[connectionKey].connectedElement == null) //if the connected receiver is from an page then it cannot have an element function applied
                    {
                        Debug.Log("Breaking link because trying to " + selection + " to Page");
                        curve.breakLink();
                    }
                    else
                    {
                        Debug.Log("Changing old selection to " + selection);
                        peet.connections[connectionKey].action = selection;
                        curve.setAction(selection);
                    }
                }
            }
            catch (KeyNotFoundException) { }   //If key wasn't found then there wasn't a connection already made
            catch (NullReferenceException) { } //if curve wasn't found then there wasnt a connection already made
        });
    }
Beispiel #4
0
    public new void OnBeginDrag(PointerEventData data)
    {
        //clear any references to next page or next element since previous curve is replaced so the link has been broken
        PageElementEventTrigger peet = GetComponentInParent <ElementNodeGraphicManager>().associatedElement.GetComponent <PageElementEventTrigger>();

        //peet.AddConnection(null, null, PageElementEventTrigger.Action.None); //shouldn't need this with current implementation
        if (curve != null)
        {
            curve.breakLink();
        }
        curve = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/StoryEditor/CurveRenderer.prefab")
                                       , contentWindow).GetComponent <BezierCurve4PointRenderer>();

        curve.setAction(GetComponentInParent <SelectionConnectorManager>().getDropdownSelection());

        curve.originConnector = gameObject; //Give reference to this connector's game object to the curve
        lastDraggedCurve      = curve.gameObject;
        dragging = true;
    }
    public new void OnDrop(PointerEventData data)
    {
        currentCurve = ManipulateNodeLines.lastDraggedCurve.GetComponent <BezierCurve4PointRenderer>();
        Debug.Log("Action: " + currentCurve.action + "Receiver Type" + connectionReceiverType);
        if (currentCurve.action == PageElementEventTrigger.Action.Change)
        {
            //Check if theres already a Change connection since each page element can only have one change
            foreach (ConnectionInfo connection in currentCurve.originConnector.GetComponentInParent <ElementNodeGraphicManager>().
                     associatedElement.GetComponent <PageElementEventTrigger>().connections.Values)
            {
                if (connection.action == PageElementEventTrigger.Action.Change)
                {
                    Debug.Log("Already has a change connection, cannot have more than one per page element");
                    currentCurve.breakLink();
                    return;
                }
            }

            if (connectionReceiverType == ConnectionReceiverType.Element)
            {
                Debug.Log("Wrong receiver type, please connect to the page receiver");
                //Give the user some kind of feedback
                currentCurve.breakLink();
            }
            else
            {
                giveConnectionReferences();
            }
        }
        else
        {
            if (connectionReceiverType == ConnectionReceiverType.Page)
            {
                Debug.Log("Wrong Receiver type, please connect to the element receiver");
                //give user feedback
                currentCurve.breakLink();
            }
            else
            {
                giveConnectionReferences();
            }
        }
    }