/// <summary> /// Attaches a <see cref="CNMBodyComponent"/>. /// </summary> /// <param name="componentType">Type of the component.</param> /// <returns><c>true</c> if successful.</returns> public bool AttachComponent(Type componentType) { CNMBodyComponent modularCommNetBodyInstance = null; try { modularCommNetBodyInstance = gameObject.AddComponent(componentType) as CNMBodyComponent; modularCommNetBodyInstance.Initialize(this); } catch (Exception ex) { log.error("Encountered an exception while calling the constructor for " + componentType.Name); log.error(ex); } if (modularCommNetBodyInstance != null) { Components.Add(modularCommNetBodyInstance); modularRefs.Add(componentType, modularCommNetBodyInstance); log.debug("Activated an instance of type: " + componentType.Name); return(true); } else { log.error("Failed to activate " + componentType.Name); } return(false); }
private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence) { CNMBodyComponent instance = modularRefs[methodTypes[method]]; #if DEBUG Debug.LogFormat("CommNetManager: Parsing {0} from {1} as {2}.", methodName, instance.GetType().Name, sequence); #endif try { switch (methodName) { case "CreateOccluder": Sequence_CreateOccluder.Add(sequence, Delegate.CreateDelegate(typeof(Func <Occluder>), instance, method) as Func <Occluder>); break; case "OnNetworkInitialized": Sequence_OnNetworkInitialized.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action); break; case "OnNetworkPreUpdate": Sequence_OnNetworkPreUpdate.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action); break; case "Start": Sequence_Start.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action); 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 " + instance.GetType().Name); } catch (Exception ex) { log.error("Encountered an error creating a delegate for " + methodName + " from type " + instance.GetType().Name); log.error(ex); } }