コード例 #1
0
            private Module(int cate, System.Type type, string defaultIcon)
            {
                var category = CATES[cate];

                this.type       = type;
                this.CategoryId = cate;
                this.Category   = category;
                composite       = Ref.GetCustomAttribute <BTCompositeAttribute>(type);
                Hotkey          = composite == null ? 0 : composite.HotKey;
                Title           = composite == null || string.IsNullOrEmpty(composite.Title) ? type.Name : composite.Title;
                Detail          = composite == null ? null : composite.Detail;
                Color c;

                if (composite != null && !string.IsNullOrEmpty(composite.color) && ColorUtility.TryParseHtmlString(composite.color, out c))
                {
                    color = c;
                }
                else
                {
                    color = AIModules.GetColor(category);
                }
                icon = AssetDatabase.LoadAssetAtPath <Texture2D>(composite == null || string.IsNullOrEmpty(composite.IconPath) ? defaultIcon : composite.IconPath);
                var buf = StringUtil.GetBuilder();

                buf.Append(category).Append('/');
                if (composite != null && !string.IsNullOrEmpty(composite.Category))
                {
                    CateTitle = StringUtil.Concat(composite.Category, '/', Title);
                }
                else if (!string.IsNullOrEmpty(type.Namespace) && type.Namespace != "Devil.AI")
                {
                    CateTitle = StringUtil.Concat(type.Namespace, '/', Title);
                }
                else
                {
                    CateTitle = Title;
                }
                buf.Append(CateTitle);
                Path = new GUIContent(StringUtil.ReleaseBuilder(buf));
            }
コード例 #2
0
        public BehaviourMeta(System.Type target)
        {
            //TargetType = target;
            Name        = target.Name;
            DisplayName = Name;
            Namespace   = target.Namespace;
            string iconPath = "";

            if (target.IsSubclassOf(typeof(BTNodeBase)))
            {
                NodeType = EBTNodeType.controller;
                Category = "Composite";
                iconPath = Installizer.InstallRoot + "/DevilFramework/Editor/Icons/composite.png";
            }
            else if (target.IsSubclassOf(typeof(BTTaskBase)))
            {
                NodeType = EBTNodeType.task;
                Category = "Task";
                iconPath = Installizer.InstallRoot + "/DevilFramework/Editor/Icons/task.png";
            }
            else if (target.IsSubclassOf(typeof(BTConditionBase)))
            {
                NodeType = EBTNodeType.condition;
                Category = "Condition";
                iconPath = Installizer.InstallRoot + "/DevilFramework/Editor/Icons/condition.png";
            }
            else if (target.IsSubclassOf(typeof(BTServiceBase)))
            {
                NodeType = EBTNodeType.service;
                Category = "Service";
                iconPath = Installizer.InstallRoot + "/DevilFramework/Editor/Icons/service.png";
            }
            else
            {
                NodeType = EBTNodeType.invalid;
                Category = "Invalid";
            }

            BTCompositeAttribute attr = Ref.GetCustomAttribute <BTCompositeAttribute>(target);

            if (attr != null)
            {
                if (!string.IsNullOrEmpty(attr.Title))
                {
                    DisplayName = attr.Title;
                }
                if (!string.IsNullOrEmpty(attr.Detail))
                {
                    SubTitle = attr.Detail;
                }
                if (!string.IsNullOrEmpty(attr.IconPath))
                {
                    iconPath = attr.IconPath;
                }
                if (!string.IsNullOrEmpty(attr.Category))
                {
                    Category = attr.Category;
                }
                HideProperty = attr.HideProperty;
            }
            FieldInfo[]            fields      = target.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            List <BTInputProperty> propperties = new List <BTInputProperty>();

            for (int i = 0; i < fields.Length; i++)
            {
                BTVariableAttribute vatt = Ref.GetCustomAttribute <BTVariableAttribute>(fields[i]);
                if (vatt != null)
                {
                    BTInputProperty pro = new BTInputProperty(fields[i], vatt);
                    propperties.Add(pro);
                }
            }
            Icon           = DevilEditorUtility.GetTexture(iconPath);
            Properties     = propperties.ToArray();
            NotDisplayName = string.Format("<b><color=yellow>NOT</color></b> {0}", DisplayName);
            SearchName     = Name.ToLower() + " " + DisplayName.ToLower();
            color          = BehaviourModuleManager.GetOrNewInstance().GetCategoryColor(Category);
        }