示例#1
0
        /// <summary>
        /// Attaches a <see cref="CNMHomeComponent"/>.
        /// </summary>
        /// <param name="componentType">Type of the component.</param>
        /// <returns><c>true</c> if successful.</returns>
        public bool AttachComponent(Type componentType)
        {
            CNMHomeComponent modularCommNetHomeInstance = null;

            try
            {
                modularCommNetHomeInstance             = gameObject.AddComponent(componentType) as CNMHomeComponent;
                modularCommNetHomeInstance.CommNetHome = this;
                modularCommNetHomeInstance.Initialize(this);
            }
            catch (Exception ex)
            {
                log.error("Encountered an exception while calling the constructor for " + componentType.Name);
                log.error(ex);
            }
            if (modularCommNetHomeInstance != null)
            {
                Components.Add(modularCommNetHomeInstance);
                modularRefs.Add(componentType, modularCommNetHomeInstance);
                log.debug("Activated an instance of type: " + componentType.Name);
                return(true);
            }
            else
            {
                log.warning("Failed to activate " + componentType.Name);
            }
            return(false);
        }
示例#2
0
        private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence)
        {
            CNMHomeComponent instance = modularRefs[methodTypes[method]];

    #if DEBUG
            Debug.LogFormat("CNMHome: Parsing {0} from {1} as {2}.", methodName, instance.GetType().Name, sequence);
    #endif

            try
            {
                switch (methodName)
                {
                case "CreateNode":
                    Sequence_CreateNode.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    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;

                case "Update":
                    Sequence_Update.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);
            }
        }