Exemplo n.º 1
0
        public static void StartLinking(OutputVisual linkStart)
        {
            linkInitiator = linkStart;
            status        = LINKING;

            GameObject link = new GameObject(linkStart.name + "_link_" + linkStart.links.Count);

            linkStart.pendingLink = link.AddComponent <LinkVisual>();
            linkStart.pendingLink.FollowMouse(linkStart.gameObject);
            linkStart.pendingLink.outputThatCreatedMe = linkStart;
            link.transform.SetParent(linkStart.transform, false);
        }
Exemplo n.º 2
0
        OutputVisual CreateOutputVisual(Output output, string label)
        {
            GameObject go = new GameObject();

            go.AddComponent <RectTransform>();
            go.transform.SetParent(rectTransform, false);
            OutputVisual outp = go.AddComponent <OutputVisual>();

            outp.outputAttachedTo = output;
            outp.host             = this;
            outp.SetLabel(label);
            return(outp);
        }
Exemplo n.º 3
0
        private void OnClick(BaseEventData arg0)
        {
            PointerEventData ev = arg0 as PointerEventData;

            if (ev == null)
            {
                return;
            }
            if (ev.button == PointerEventData.InputButton.Left)
            {
                if (OutputVisual.status == OutputVisual.LINKING)
                {
                    //linking
                    if (OutputVisual.linkInitiator.host != host)
                    {
                        Disconnect();
                        OutputVisual.CompleteLink(this);
                    }
                }
                else
                {
                    //not linking
                    if (ev.clickCount == 2)
                    {
                        Disconnect();
                    }
                }
            }
            else if (ev.button == PointerEventData.InputButton.Right)
            {
                stay = !stay;
            }
            else if (ev.button == PointerEventData.InputButton.Middle)
            {
                List <Type> allowed = inputAttachedTo.GetAllowedDataTypes();
                if (allowed.Count != 0)
                {
                    StringBuilder builder = new StringBuilder("Allowed:\n");
                    for (int i = 0; i < allowed.Count; i++)
                    {
                        string cleanName = TabMenu.CleanClassName(allowed[i].ToString());
                        builder.Append(cleanName);
                        if (i != allowed.Count - 1)
                        {
                            builder.Append(", ");
                        }
                    }
                    MouseToast.MakeToastFixed(2f, builder.ToString(), UnityEngine.Input.mousePosition);
                }
            }
        }
Exemplo n.º 4
0
        void BuildOutputs()
        {
            //Debug.Log("Building outputs for " + GetType());

            outputsVisuals = new OutputVisual[node.outputs.Count];
            oldOutputTypes = new Type[outputsVisuals.Length];

            for (int i = 0; i < node.outputs.Count; i++)//outputs
            {
                OutputVisual outp = CreateOutputVisual(node.outputs[i], GetOutputLabel(i));
                outp.name = "output_" + i;
                outp.UpdateType();

                outputsVisuals[i] = outp;
                oldOutputTypes[i] = node.outputs[i].GetDataType();
            }
            PlaceOutputs();
        }
Exemplo n.º 5
0
        public static void CompleteLink(InputVisual linkEnd)
        {
            if (linkInitiator.outputAttachedTo.ConnectTo(linkEnd.inputAttachedTo))
            {
                linkInitiator.pendingLink.FinishFollowingMouse(linkEnd.gameObject);
                linkInitiator.links.Add(linkInitiator.pendingLink);

                linkEnd.outputConnectedTo = linkInitiator;


                linkInitiator.pendingLink = null;
                linkInitiator             = null;
                status = IDLE;
            }
            else
            {
                Debug.Log("linking refused");
                CancelLink();
            }
        }
Exemplo n.º 6
0
        void OutputsCountChanged()
        {
            List <OutputVisual> nOutputVisuals  = new List <OutputVisual>();
            List <Type>         nOldOutputTypes = new List <Type>();

            for (int i = 0; i < node.outputs.Count; i++)
            {
                if (outputsVisuals.Length > i)
                {
                    //if there is an old output here
                    //update it
                    UpdateOutput(i);
                    nOutputVisuals.Add(outputsVisuals[i]);
                    nOldOutputTypes.Add(node.outputs[i].GetDataType());
                }
                else
                {
                    //if there is not and old outpute here
                    //create output
                    OutputVisual outp = CreateOutputVisual(node.outputs[i], GetOutputLabel(i));
                    outp.name = "output_" + i;
                    outp.UpdateType();

                    PlaceOutput(outp, i);
                    nOutputVisuals.Add(outp);
                    nOldOutputTypes.Add(node.outputs[i].GetDataType());
                }
            }
            if (outputsVisuals.Length > node.outputs.Count)
            {
                //there is some output in surplus
                //delete them (the surplus)
                for (int i = node.outputs.Count; i < outputsVisuals.Length; i++)
                {
                    outputsVisuals[i].Disconnect();
                    Destroy(outputsVisuals[i].gameObject);
                }
            }
            outputsVisuals = nOutputVisuals.ToArray();
            oldOutputTypes = nOldOutputTypes.ToArray();
        }
Exemplo n.º 7
0
 public static void CancelLink()
 {
     Destroy(linkInitiator.pendingLink.gameObject);
     linkInitiator = null;
     status        = IDLE;
 }
Exemplo n.º 8
0
 void PlaceOutput(OutputVisual outp, int i)
 {
     outp.rectTransform.anchoredPosition = new Vector2(+GetWidth() / 2f, (GetHeight() / 2f) - (25f * i) - 20f);
 }