protected override void OnMouseDown(Event e)
        {
            switch (e.button)
            {
            case 0:
                if (m_linkFrom != null)
                {
                    BehaviorNodeControl node = IsPointOnNode(e.mousePosition);

                    if (node != null)
                    {
                        m_linkFrom.SetOutput(node, m_linkFromIndex);
                    }

                    m_linkFrom      = null;
                    m_linkLine.From = Vector2.zero;
                    m_linkLine.To   = Vector2.zero;

                    e.Use();
                }
                break;

            case 1:
                if (m_linkFrom != null)
                {
                    m_linkFrom      = null;
                    m_linkLine.From = Vector2.zero;
                    m_linkLine.To   = Vector2.zero;

                    e.Use();
                }
                break;
            }
        }
        public bool Deserialize(string path, EditorNodeTypeCache typeCache, out string id, out BehaviorNodeControl[] controls)
        {
            id       = "";
            controls = new BehaviorNodeControl[0];

            m_childMapping = new Dictionary <BehaviorNodeControl, List <string> >();

            try
            {
                m_indexTable = new Dictionary <BehaviorNodeControl, string>();

                XmlDocument xml = new XmlDocument();
                xml.Load(path);

                XmlNode xmlRoot = xml.SelectSingleNode("BehaviorTreeLayout");
                id = xmlRoot.Attributes["id"].InnerText;

                List <BehaviorNodeControl> deserialized = new List <BehaviorNodeControl>();
                XmlNodeList xmlNodes = xmlRoot.SelectNodes("Node");
                foreach (XmlNode xmlNode in xmlNodes)
                {
                    string              nodeId;
                    List <string>       children;
                    BehaviorNodeControl c = DeserializeNode(xmlNode, typeCache, out nodeId, out children);

                    if (c != null)
                    {
                        m_indexTable.Add(c, nodeId);
                        m_childMapping.Add(c, children);
                        deserialized.Add(c);
                    }
                    else
                    {
                        Debug.LogWarning("Invalid node encountered, not all nodes have been deserialized");
                    }
                }

                // Map outputs
                foreach (BehaviorNodeControl c in deserialized)
                {
                    if (m_childMapping.ContainsKey(c))
                    {
                        int i = 0;
                        foreach (string cid in m_childMapping[c])
                        {
                            foreach (KeyValuePair <BehaviorNodeControl, string> kvp in m_indexTable)
                            {
                                if (kvp.Value == cid)
                                {
                                    c.SetOutput(kvp.Key, i);
                                    i++;
                                    break;
                                }
                            }
                        }
                    }
                }

                controls = deserialized.ToArray();

                return(true);
            }
            catch (System.Exception e)
            {
                Debug.LogError(string.Format("Could not load layout at `{0}` - {1}", path, e.Message));
            }

            return(false);
        }