public bool BindNetwork(CommNetwork net)
 {
     // Use reflection to force the network to use this network's associated Lists
     try
     {
         Type netType = net.GetType();
         netType.GetField("candidates", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(net, this.candidates);
         netType.GetField("links", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(net, this.links);
         netType.GetField("nodeEnum", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(net, this.nodeEnum);
         netType.GetField("nodeLink", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(net, this.nodeLink);
         netType.GetField("nodeLinkEnum", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(net, this.nodeLinkEnum);
         netType.GetField("nodes", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(net, this.nodes);
         netType.GetField("occluders", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(net, this.occluders);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence)
        {
            CommNetwork networkInstance = commNetworks[methodTypes[method]];

    #if DEBUG
            if (andOrList.ContainsKey(method))
            {
                Debug.LogFormat("CommNetManager: Parsing {0} from {1} as {2} with {3}.", methodName, networkInstance.GetType().Name, sequence, andOrList[method]);
            }
            else
            {
                Debug.LogFormat("CommNetManager: Parsing {0} from {1} as {2}.", methodName, networkInstance.GetType().Name, sequence);
            }
    #endif
            try
            {
                switch (methodName)
                {
                case "SetNodeConnection":
                    Sequence_SetNodeConnection.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, bool>), networkInstance, method) as Func <CommNode, CommNode, bool>, andOrList[method]);
                    break;

                case "Add_CommNode":
                    Sequence_Add_CommNode.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode>), networkInstance, method) as Func <CommNode, CommNode>);
                    break;

                case "Add_Occluder":
                    Sequence_Add_Occluder.Add(sequence, Delegate.CreateDelegate(typeof(Func <Occluder, Occluder>), networkInstance, method) as Func <Occluder, Occluder>);
                    break;

                case "Connect":
                    Sequence_Connect.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, double, CommLink>), networkInstance, method) as Func <CommNode, CommNode, double, CommLink>);
                    break;

                case "CreateShortestPathTree":
                    Sequence_CreateShortestPathTree.Add(sequence, Delegate.CreateDelegate(typeof(Action <CommNode, CommNode>), networkInstance, method) as Action <CommNode, CommNode>);
                    break;

                case "Disconnect":
                    Sequence_Disconnect.Add(sequence, Delegate.CreateDelegate(typeof(Action <CommNode, CommNode, bool>), networkInstance, method) as Action <CommNode, CommNode, bool>, andOrList[method]);
                    break;

                case "FindClosestControlSource":
                    Sequence_FindClosestControlSource.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, bool>), networkInstance, method) as Func <CommNode, CommPath, bool>, andOrList[method]);
                    break;

                case "FindClosestWhere":
                    Sequence_FindClosestWhere.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, Func <CommNode, CommNode, bool>, CommNode>), networkInstance, method) as Func <CommNode, CommPath, Func <CommNode, CommNode, bool>, CommNode>);
                    break;

                case "FindHome":
                    Sequence_FindHome.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, bool>), networkInstance, method) as Func <CommNode, CommPath, bool>, andOrList[method]);
                    break;

                case "FindPath":
                    Sequence_FindPath.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, CommNode, bool>), networkInstance, method) as Func <CommNode, CommPath, CommNode, bool>, andOrList[method]);
                    break;

                case "GetLinkPoints":
                    Sequence_GetLinkPoints.Add(sequence, Delegate.CreateDelegate(typeof(Action <List <Vector3> >), networkInstance, method) as Action <List <Vector3> >);
                    break;

                case "PostUpdateNodes":
                    Sequence_PostUpdateNodes.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "PreUpdateNodes":
                    Sequence_PreUpdateNodes.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "Rebuild":
                    Sequence_Rebuild.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "Remove_CommNode":
                    Sequence_Remove_CommNode.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, bool>), networkInstance, method) as Func <CommNode, bool>, andOrList[method]);
                    break;

                case "Remove_Occluder":
                    Sequence_Remove_Occluder.Add(sequence, Delegate.CreateDelegate(typeof(Func <Occluder, bool>), networkInstance, method) as Func <Occluder, bool>, andOrList[method]);
                    break;

                case "TestOcclusion":
                    Sequence_TestOcclusion.Add(sequence, Delegate.CreateDelegate(typeof(Func <Vector3d, Occluder, Vector3d, Occluder, double, bool>), networkInstance, method) as Func <Vector3d, Occluder, Vector3d, Occluder, double, bool>, andOrList[method]);
                    break;

                case "TryConnect":
                    Sequence_TryConnect.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, double, bool, bool, bool, bool>), networkInstance, method) as Func <CommNode, CommNode, double, bool, bool, bool, bool>, andOrList[method]);
                    break;

                case "UpdateNetwork":
                    Sequence_UpdateNetwork.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "UpdateShortestPath":
                    Sequence_UpdateShortestPath.Add(sequence, Delegate.CreateDelegate(typeof(Action <CommNode, CommNode, CommLink, double, CommNode, CommNode>), networkInstance, method) as Action <CommNode, CommNode, CommLink, double, CommNode, CommNode>);
                    break;

                case "UpdateShortestWhere":
                    Sequence_UpdateShortestWhere.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, CommLink, double, CommNode, Func <CommNode, CommNode, bool>, CommNode>), networkInstance, method) as Func <CommNode, CommNode, CommLink, double, CommNode, Func <CommNode, CommNode, bool>, CommNode>);
                    break;

                default:
    #if DEBUG
                    log.warning("The method passed (" + methodName + ") was not a standard CommNet method.");
    #endif
                    return;
                }
                log.debug("Successfully parsed " + methodName + " from type " + networkInstance.GetType().Name);
            }
            catch (Exception ex)
            {
                log.error("Encountered an error creating a delegate for " + methodName + " from type " + networkInstance.GetType().Name);
                log.error(ex);
            }
        }