Exemple #1
0
        /// <summary>
        /// Constructor for a Script object.
        /// <param name="parent">The parent category of this item.</param>
        /// <param name="name">The name of the item.</param>
        /// <param name="type">The MonoScript that will be stored in this item.</param>
        /// <param name="nodeInfo">Meta information about the node type in the type.</param>
        /// </summary>
        public Script (Category parent, string name, System.Type type, NodeInfoAttribute nodeInfo) : base (parent, name) {
            this.type = type;
            this.nodeInfo = nodeInfo;

            if (type.IsSubclassOf(typeof(ConditionNode)))
                nodeType = NodeType.Condition;
            else if (type.IsSubclassOf(typeof(DecoratorNode)))
                nodeType = NodeType.Decorator;
            else if (type == typeof(MissingNode))
                nodeType = NodeType.MissingNode;
            else if (type.IsSubclassOf(typeof(CompositeNode)))
                nodeType = NodeType.Composite;
            else
                nodeType = NodeType.Action;
        }
Exemple #2
0
        /// <summary>
        /// Adds a new child in this category.
        /// If category is not null creates a new category child; otherwise creates a new Script child.
        /// <param name="category">The name of the category.</param>
        /// <param name="type">The type of the node.</param>
        /// <param name="NodeInfo">The node info of the script.</param>
        /// </summary>
        public void AddChild (string category, System.Type type, NodeInfoAttribute NodeInfo) {
            if (category == null)
                category = string.Empty;

            string[] splitedCategory = category.Split('/');

            // The category is not null or empty?
            if (splitedCategory.Length > 0 && splitedCategory[0] != string.Empty) {
                var desiredCategoryChild = GetChild(splitedCategory[0]) as Category;

                // The Category does not exist?
                if (desiredCategoryChild == null) {
                    // Create a new category
                    desiredCategoryChild = new Category(this, splitedCategory[0]);
                    m_Children.Add(desiredCategoryChild);
                }

                // Continues searching in the children category
                string removeSubString =  category.Contains(splitedCategory[0] + "/") ? splitedCategory[0] + "/" : splitedCategory[0];
                int index = category.IndexOf(removeSubString);
                desiredCategoryChild.AddChild(category.Remove(index, removeSubString.Length), type, NodeInfo);
            }
            else {
                Item desiredChild = GetChild(type.ToString());
                // The Script does not exist?
                if (desiredChild == null)
                    m_Children.Add(new Script(this, type.Name, type, NodeInfo));
            }
        }