public static void LoadModules()
        {
            sColors[CATES[CATE_COMPOSITE]] = new Color(0.3f, 0.3f, 0.3f);
            sColors[CATES[CATE_TASK]]      = new Color(0.6f, 0.1f, 1f);
            sColors[CATES[CATE_SERVICE]]   = new Color(0.1f, 0.35f, 0.1f);
            sColors[CATES[CATE_CONDITION]] = new Color(0.1f, 0.3f, 0.5f);

            sSharedTypes.Clear();
            sSharedTypes.Add(typeof(GameObject));
            sSharedTypes.Add(typeof(Transform));
            sSharedTypes.Add(typeof(float));
            sSharedTypes.Add(typeof(bool));
            sSharedTypes.Add(typeof(int));
            sSharedTypes.Add(typeof(Vector3));
            sSharedTypes.Add(typeof(string));

            icon = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/DevilFramework/Gizmos/AI Icons/BehaviourTree Icon.png");
            for (int i = 0; i < sModules.Length; i++)
            {
                sModules[i] = new List <Module>();
            }
            sAllModules.Clear();

            List <System.Type> lst = new List <System.Type>();

            Ref.GetAssemblyTypes(lst);
            foreach (var tp in lst)
            {
                var mod = Module.GetModule(tp);
                if (mod != null)
                {
                    sAllModules.Add(mod);
                    sModules[mod.CategoryId].Add(mod);
                }
                var bts = Ref.GetCustomAttribute <BTSharedTypeAttribute>(tp);
                if (bts != null)
                {
                    sSharedTypes.Add(tp);
                }
            }

            sSharedTypes.Add(typeof(object));
            sSharedTypeNames = new string[sSharedTypes.Count];
            for (int i = 0; i < sSharedTypeNames.Length; i++)
            {
                sSharedTypeNames[i] = sSharedTypes[i].FullName;
            }
            BehaviourTreeEditor.InitModules();
            OnReloead();
        }
            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));
            }
Exemplo n.º 3
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);
        }