static bool OpenCanvasAsset(int instanceID, int line)
        {
            var          tree = EditorUtility.InstanceIDToObject(instanceID) as BehaviourTree;
            BonsaiWindow w    = OpenTree(tree);

            if (w)
            {
                // If a tree asset was created but has no blackboard, add one upon opening.
                // This is for convenience.
                BonsaiSaver.AddBlackboardIfMissing(tree);

                w.SwitchToViewModeIfRequired();
            }

            return(w);
        }
        private static bool OpenCanvasAsset(int instanceID, int line)
        {
            var treeSelected = EditorUtility.InstanceIDToObject(instanceID) as BehaviourTree;

            if (treeSelected != null)
            {
                BonsaiWindow windowToUse = null;

                // Try to find an editor window without a canvas...
                var bonsaiWindows = Resources.FindObjectsOfTypeAll <BonsaiWindow>();
                foreach (var w in bonsaiWindows)
                {
                    // The canvas is already opened
                    if (w.Tree == treeSelected)
                    {
                        return(false);
                    }

                    // Found a window with no active canvas.
                    if (w.Tree == null)
                    {
                        windowToUse = w;
                        break;
                    }
                }

                // No windows available...just make a new one.
                if (!windowToUse)
                {
                    windowToUse = CreateInstance <BonsaiWindow>();
                    windowToUse.Show();
                }

                // If a tree asset was created but has no blackboard, add one upon opening.
                // This is for convenience.
                BonsaiSaver.AddBlackboardIfMissing(treeSelected);

                windowToUse.SetTree(treeSelected);
                windowToUse.Repaint();
                return(true);
            }

            return(false);
        }