示例#1
0
        private void DrawGUIConnectDrag()
        {
            if (dragSlot != null)
            {
                Rect cp = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0);
                DrawNodeCurve(dragSlot.SlotRect, cp);
            }

            if (Event.current.type == EventType.Repaint && !leftMouseDown && dragSlot != null)
            {
                foreach (BocsSlotBase s in BocsCyclesNodeManager.Slots)
                {
                    if (s.SlotRect.Contains(Event.current.mousePosition))
                    {
                        if (s.SlotType == BocsSlotBase.BocsSlotType.Input)
                        {
                            if (s.Node != dragSlot.Node)
                            {
                                //if (s._slotValType == _dragSlot._slotValType)
                                {
                                    s.RemoveConnection();
                                    dragSlot.AddConnection(s);
                                    SaveNodes();
                                    cyclesNeedsUpdate = true;
                                }
                            }
                        }
                    }
                }
                dragSlot = null;
            }
        }
        public static void LoadGraph(string g)
        {
            //Debug.Log("LoadGraph");
            Reset();

            if (g == null)
            {
                return;
            }

            string[] sn = g.Split(':');

            foreach (string n in sn)
            {
                //Debug.Log(n);
                string[] s = n.Split('|');
                //foreach(string ts in s) Debug.Log(ts);

                if (s.Length > 0)
                {
                    if (s[0] == "node")
                    {
                        string[] p = s[1].Split(',');
                        //foreach(string ts in p) Debug.Log(ts);

                        int    x = 0;
                        int    y = 0;
                        int    c = 0;
                        string t = string.Empty;
                        foreach (string ts in p)
                        {
                            string[] v = ts.Split('=');
                            if (v.Length > 1)
                            {
                                if (v[0] == "t")
                                {
                                    t = v[1];
                                }
                                if (v[0] == "x")
                                {
                                    x = int.Parse(v[1]);
                                }
                                if (v[0] == "y")
                                {
                                    y = int.Parse(v[1]);
                                }
                                if (v[0] == "c")
                                {
                                    c = int.Parse(v[1]);
                                }
                            }
                        }
                        CreateNode(t, x, y, c);
                    }

                    if (s[0] == "val")
                    {
                        string[] p = s[1].Split(',');
                        //foreach(string ts in p) Debug.Log(ts);

                        int    ni = -1;
                        string ss = string.Empty;
                        string sv = string.Empty;

                        foreach (string ts in p)
                        {
                            string[] v = ts.Split('=');
                            if (v.Length > 1)
                            {
                                if (v[0] == "n")
                                {
                                    ni = int.Parse(v[1]);
                                }
                                if (v[0] == "s")
                                {
                                    ss = v[1];
                                }
                                if (v[0] == "v")
                                {
                                    sv = v[1];
                                }
                            }
                        }

                        if (ni >= 0 && ni < BocsCyclesNodeManager.Nodes.Count)
                        {
                            BocsNodeBase nb = BocsCyclesNodeManager.Nodes[ni];
                            if (nb != null)
                            {
                                foreach (BocsSlotBase us in nb.Slots)
                                {
                                    if (us.SlotName == ss)
                                    {
                                        us.SetString(sv);
                                    }
                                }
                            }
                        }
                    }
                    if (s[0] == "connect")
                    {
                        string[] p = s[1].Split(',');
                        //foreach(string ts in p) Debug.Log(ts);

                        int    n1 = -1;
                        int    n2 = -1;
                        string s1 = string.Empty;
                        string s2 = string.Empty;

                        foreach (string ts in p)
                        {
                            string[] v = ts.Split('=');
                            if (v.Length > 1)
                            {
                                if (v[0] == "n1")
                                {
                                    n1 = int.Parse(v[1]);
                                }
                                if (v[0] == "n2")
                                {
                                    n2 = int.Parse(v[1]);
                                }
                                if (v[0] == "s1")
                                {
                                    s1 = v[1];
                                }
                                if (v[0] == "s2")
                                {
                                    s2 = v[1];
                                }
                            }
                        }

                        if (n1 != -1 && n2 != -1 && s1 != string.Empty && s2 != string.Empty && n1 < Nodes.Count && n2 < Nodes.Count)
                        {
                            BocsSlotBase f = FindOutputSlotFromString(BocsCyclesNodeManager.Nodes[n1], s1);
                            BocsSlotBase t = FindInputSlotFromString(BocsCyclesNodeManager.Nodes[n2], s2);
                            if (f != null && t != null)
                            {
                                f.AddConnection(t);
                            }
                        }
                    }
                }
            }
        }