public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            ValidateProperty(property);
            label = EditorGUI.BeginProperty(position, label, property);
            var lv = EditorGUI.indentLevel;

            var pos = EditorGUI.PrefixLabel(position, label);

            string txt;

            if (position.height < 20)
            {
                EditorGUI.indentLevel = 0;
                txt = EditorGUI.TextArea(new Rect(pos.x, pos.y, pos.width - 90, pos.height), Prop(p_txt).stringValue);
                DevilEditorUtility.Hint(new Rect(pos.xMax - 90, pos.y, 90, pos.height), Prop(p_id).intValue.ToString());
            }
            else
            {
                DevilEditorUtility.Hint(pos, Prop(p_id).intValue.ToString());
                txt = EditorGUI.TextArea(new Rect(position.x, position.y + 15, position.width, position.height - 15), Prop(p_txt).stringValue);
            }
            Prop(p_id).intValue     = StringUtil.ToHash(txt);
            Prop(p_txt).stringValue = txt;

            EditorGUI.indentLevel = lv;
            EditorGUI.EndProperty();
        }
Пример #2
0
 public void ValidateProperty(SerializedProperty property)
 {
     if (property != this.property)
     {
         this.property = property;
         var properties = GetRelativeProperties();
         if (cachedProperties == null || cachedProperties.Length != properties.Length)
         {
             cachedProperties = new SerializedProperty[properties.Length];
         }
         if (property != null)
         {
             for (int i = 0; i < cachedProperties.Length; i++)
             {
                 cachedProperties[i] = DevilEditorUtility.FindRelativeProperty(property, properties[i]);
             }
         }
         else
         {
             for (int i = 0; i < cachedProperties.Length; i++)
             {
                 cachedProperties[i] = null;
             }
         }
         OnValidateProperty();
     }
 }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            ValidateProperty(property);
            label = EditorGUI.BeginProperty(position, label, property);

            var lv = EditorGUI.indentLevel;

            EditorGUI.BeginDisabledGroup(Application.isPlaying);

            EditorGUI.LabelField(position, DevilEditorUtility.EmptyContent, (GUIStyle)"helpbox");
            var row = new Rect(position.x + 3, position.y + 5, position.width - 6, 18);
            //EditorGUI.LabelField(row, DevilEditorUtility.EmptyContent, "helpbox");
            var s = Prop(p_comment).stringValue;

            s = EditorGUI.TextField(row, string.IsNullOrEmpty(s) ? comHint : s, DevilEditorUtility.HintStyle("label"));
            Prop(p_comment).stringValue = s == comHint ? "" : s;

            EditorGUI.indentLevel = lv;
            label.text            = " Varialbe Name";
            row.y += 20;
            var   pos  = EditorGUI.PrefixLabel(row, label);
            float size = pos.x - row.x;

            EditorGUI.indentLevel    = 0;
            Prop(p_name).stringValue = EditorGUI.TextField(pos, Prop(p_name).stringValue);

            EditorGUI.indentLevel = lv;
            row.y += 20;
            //label.text = " Data Type";
            pos = new Rect(row.x, row.y, size - 5, row.height);
            Prop(p_lst).boolValue = EditorGUI.Popup(pos, Prop(p_lst).boolValue ? 1 : 0, dtType, (GUIStyle)"ShurikenPopup") != 0;
            //pos = EditorGUI.PrefixLabel(row, label);
            pos = new Rect(row.x + size, row.y, row.width - size, row.height);

            EditorGUI.indentLevel = 0;
            var sel = GlobalUtil.FindIndex(AIModules.SharedTypeNames, (x) => x == Prop(p_type).stringValue);

            if (sel == -1)
            {
                sel = 0;
            }
            //pos.width -= 20;
            sel = EditorGUI.Popup(pos, sel, AIModules.SharedTypeNames, (GUIStyle)"ExposablePopupMenu");
            Prop(p_type).stringValue = AIModules.SharedTypeNames[sel];
            //pos = new Rect(pos.xMax + 3, pos.y, 15, 15);
            //Prop(p_lst).boolValue = EditorGUI.Toggle(pos, Prop(p_lst).boolValue, (GUIStyle)"MuteToggle");

            EditorGUI.indentLevel = lv;
            EditorGUI.EndDisabledGroup();
            EditorGUI.EndProperty();
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            ValidateProperty(property);
            label = EditorGUI.BeginProperty(position, label, property);
            if (property.propertyType == SerializedPropertyType.Generic)
            {
                var pos = position;
                EditorGUI.LabelField(pos, DevilEditorUtility.EmptyContent, (GUIStyle)"helpbox");

                int lv = EditorGUI.indentLevel;

                var h = pos.height - 40;
                EditorGUI.indentLevel++;
                var rect = new Rect(pos.x, pos.y + 3, pos.width, h);
                EditorGUI.PropertyField(rect, Prop(p_value), label, true);

                rect                  = new Rect(pos.x, pos.y + h + 3, pos.width, pos.height - h);
                label.text            = " Blackboard Variable";
                position              = EditorGUI.PrefixLabel(rect, label);
                EditorGUI.indentLevel = 0;

                rect = new Rect(position.x, position.y, position.width, 18);
                var index = mSelectedIndex;
                mSelectedIndex = EditorGUI.Popup(rect, mSelectedIndex, mPopNames, (GUIStyle)"ExposablePopupMenu");
                if (mSelectedIndex > 0)
                {
                    Prop(p_name).stringValue = mPopNames[mSelectedIndex].text;
                    rect = new Rect(position.x, position.y + 18, position.width, 20);
                    EditorGUI.LabelField(rect, mVars[mSelectedIndex - 1].comment, DevilEditorUtility.HintStyle("label"));
                }
                else
                {
                    if (index > 0)
                    {
                        mCusCache = "";
                    }
                    rect      = new Rect(position.x, position.y + 18, position.width, 18);
                    mCusCache = EditorGUI.TextField(rect, mCusCache, (GUIStyle)"helpbox");
                    Prop(p_name).stringValue = mCusCache;
                }

                EditorGUI.indentLevel = lv;
            }
            else
            {
                EditorGUI.PropertyField(position, property);
            }
            //TextFieldDropDown TextFieldDropDownText
            EditorGUI.EndProperty();
        }
Пример #5
0
        public static void OnUnityLoaded()
        {
            IsInited = false;
            DevilEditorUtility.ReleaseCache();
            titleStyle.alignment         = TextAnchor.MiddleCenter;
            titleStyle.richText          = true;
            titleStyle.fontSize          = 13;
            titleStyle.wordWrap          = false;
            titleStyle.fontStyle         = FontStyle.Bold;
            titleStyle.normal.textColor  = Color.green;
            titleStyle.onHover.textColor = Color.yellow;

            contentStyle.alignment         = TextAnchor.MiddleCenter;
            contentStyle.richText          = true;
            contentStyle.fontSize          = 10;
            contentStyle.wordWrap          = false;
            contentStyle.fontStyle         = FontStyle.Normal;
            contentStyle.normal.textColor  = Color.white;
            contentStyle.onHover.textColor = Color.white;


            string  txt  = "ABCDEFG";
            Vector2 size = SizeOfTitle(txt);

            TitleHeight   = size.y;
            size          = SizeOfContent(txt);
            ContentHeight = size.y;

            EditorPrefs.SetBool("Devil.Editor.first", false);
            string[] assets = AssetDatabase.FindAssets("t:script Installizer");
            string   ends   = "/DevilFramework/Editor/Installizer.cs";

            foreach (string s in assets)
            {
                string path = AssetDatabase.GUIDToAssetPath(s);
                if (path.EndsWith(ends))
                {
                    path = path.Substring(0, path.Length - ends.Length);
                    EditorPrefs.SetString("Devil.Root", path);
                    InstallRoot = path;
                    Debug.Log("Devil Framework install at path: " + path);
                }
            }
            DevilCfg.LoadConfiguration();
            BehaviourModuleManager.GetOrNewInstance().Load();
            IsInited = true;
            OnReloaded();
        }
        void HandleTransition(Rect from, Rect to, Color baseColor, bool twoside)
        {
            Vector2 dir = to.center - from.center;
            Vector2 p0  = GetCollidePoint(from, dir);
            Vector2 p1  = GetCollidePoint(to, -dir);

            if (twoside)
            {
                DevilEditorUtility.Draw2SideArrow(p0, p1, baseColor, 3 * cellScale);
            }
            else
            {
                DevilEditorUtility.DrawArrow(p0, p1, baseColor, 3 * cellScale);
            }
            //Handles.color = baseColor;
            //DrawArrow(p0, p1);
        }
Пример #7
0
        void SaveAsset()
        {
            bool refresh = false;

            if (BehaviourAsset == null)
            {
                BehaviourAsset = DevilEditorUtility.CreateAsset <BehaviourTreeAsset>(null, true);
                mRootGUI.UpdateLocalData();
                refresh = true;
            }
            if (BehaviourAsset == null)
            {
                return;
            }
            ExportTreeData();
            if (refresh)
            {
                AssetDatabase.Refresh();
            }
        }
Пример #8
0
        public static void LoadConfiguration()
        {
            string path = DevilEditorUtility.FindFile("DevilFramework-Cfg.xml");

            if (path == null)
            {
                path = DevilEditorUtility.FindFile("DevilFramework-Cfg-Default.xml");
            }
            //string[] assets = AssetDatabase.FindAssets("t:textasset DevilFramework-Cfg");
            string cfg = DEFAULT_CFG;

            //if (assets == null || assets.Length == 0)
            //    assets = AssetDatabase.FindAssets("t:textasset DevilFramework-Cfg-Default");
            if (string.IsNullOrEmpty(path))
            {
                EditorUtility.DisplayDialog("ERROR", "\"DevilFramework-Cfg.xml\" 文件丢失,将使用默认配置:\n" + cfg, "OK");
            }
            else
            {
                //string path = AssetDatabase.GUIDToAssetPath(assets[0]);
                Debug.Log("Devil Framewok Load Cfg: " + path);
                StreamReader reader = File.OpenText(path);
                cfg = reader.ReadToEnd();
                reader.Close();
            }
            try
            {
                ParseCfg(cfg);
            }
            catch (System.Exception e)
            {
                cfg = DEFAULT_CFG;
                ParseCfg(cfg);
                Debug.LogException(e);
            }
            finally
            {
                CFG_RAW = cfg;
            }
        }
Пример #9
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            label = EditorGUI.BeginProperty(position, label, property);
            if (property.propertyType == SerializedPropertyType.String)
            {
                position = EditorGUI.PrefixLabel(position, label);
                int lv = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;


                var rect  = new Rect(position.x, position.y, position.width, 18);
                var index = mSelectedIndex;
                mSelectedIndex = EditorGUI.Popup(rect, mSelectedIndex, mPopNames, (GUIStyle)"ExposablePopupMenu");
                if (mSelectedIndex > 0)
                {
                    property.stringValue = mPopNames[mSelectedIndex].text;
                    rect = new Rect(position.x, position.y + 18, position.width, 20);
                    EditorGUI.LabelField(rect, mVars[mSelectedIndex - 1].comment, DevilEditorUtility.HintStyle("label"));
                }
                else
                {
                    if (index > 0)
                    {
                        mCusCache = "";
                    }
                    rect                 = new Rect(position.x, position.y + 18, position.width, 18);
                    mCusCache            = EditorGUI.TextField(rect, mCusCache, (GUIStyle)"helpbox");
                    property.stringValue = mCusCache;
                }

                EditorGUI.indentLevel = lv;
            }
            else
            {
                EditorGUI.PropertyField(position, property);
            }
            //TextFieldDropDown TextFieldDropDownText
            EditorGUI.EndProperty();
        }
Пример #10
0
 public BehaviourRootGUI(BehaviourTreeDesignerWindow window) : base()
 {
     mWindow  = window;
     mLockTex = DevilEditorUtility.GetTexture(Path.Combine(Installizer.InstallRoot, "DevilFramework/Editor/Icons/lock.png"));
 }
 public override void OnInspectorGUI()
 {
     serializedObject.Update();
     if (target != null)
     {
         OnConditionGUI();
         DrawTitle();
         EditorGUILayout.BeginHorizontal("helpbox");
         comment = EditorGUILayout.TextArea(string.IsNullOrEmpty(comment) ? comHint : comment, DevilEditorUtility.HintStyle("label"), GUILayout.Height(50));
         EditorGUILayout.EndHorizontal();
         if (comment != comHint)
         {
             mComment.stringValue = comment;
         }
         else
         {
             mComment.stringValue = "";
         }
         serializedObject.ApplyModifiedProperties();
     }
     if (serializedObject != null)
     {
         base.OnInspectorGUI();
     }
 }
Пример #12
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);
        }
        public override void OnInspectorGUI()
        {
            TryGetMissingAssets();
            UpdateBinders();
            if (!string.IsNullOrEmpty(missAssets))
            {
                EditorGUILayout.HelpBox(missAssets, MessageType.Warning);
            }
            var tree = target as BehaviourTreeAsset;

            if (tree != null)
            {
                EditorGUILayout.BeginHorizontal("helpbox");
                var s = EditorGUILayout.TextArea(string.IsNullOrEmpty(tree.m_Comment) ? comHint : tree.m_Comment, DevilEditorUtility.HintStyle("label"), GUILayout.Height(120));
                if (s == comHint)
                {
                    tree.m_Comment = "";
                }
                else
                {
                    tree.m_Comment = s;
                }
                EditorGUILayout.EndHorizontal();
            }
            //EditorGUI.BeginDisabledGroup(true);
            //base.OnInspectorGUI();

            //EditorGUI.EndDisabledGroup();

            if (mServices.Count > 0)
            {
                EditorGUILayout.LabelField("服务", (GUIStyle)"LODLevelNotifyText", GUILayout.Height(30));
            }
            foreach (var t in mServices)
            {
                t.DrawGUI();
            }

            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(40);

            var editing = BehaviourTreeEditor.ActiveBTEditor == null ? null : BehaviourTreeEditor.ActiveBTEditor.TargetTree;

            if (target != editing && GUILayout.Button("打开编辑器", "LargeButton"))
            {
                BehaviourTreeEditor.OpenBTEditor(target as BehaviourTreeAsset);
            }
            if (target != editing && GUILayout.Button("修复资源引用", "LargeButton"))
            {
                ((BehaviourTreeAsset)target).EditorResovleAsset();
                getMissAsset = true;
                if (BehaviourTreeEditor.ActiveBTEditor != null && BehaviourTreeEditor.ActiveBTEditor.Binder != null)
                {
                    BehaviourTreeEditor.ActiveBTEditor.Binder.Reset();
                }
            }
            GUILayout.Space(40);
            EditorGUILayout.EndHorizontal();
        }
        private void OnGUI()
        {
            var rect = new Rect(10, 10, 230, 20);

            EditorGUI.SelectableLabel(rect, "Animation Clips");
            rect  = new Rect(10, 30, 230, 130);
            clips = DevilEditorUtility.TextArea(rect, clips, " List-out Animation Clips");
            rect  = new Rect(40, 165, 80, 30);
            if (GUI.Button(rect, "Create"))
            {
                GUI.FocusControl(null);
                arr.Clear();
                if (string.IsNullOrEmpty(clips) || !StringUtil.ParseArray(clips, arr, '\n'))
                {
                    return;
                }
                if (controller == null || string.IsNullOrEmpty(path))
                {
                    EditorUtility.DisplayDialog("Error", "Can't find controller.", "OK");
                    return;
                }
                var oldassets = AssetDatabase.LoadAllAssetsAtPath(path);
                foreach (var t in arr)
                {
                    if (string.IsNullOrEmpty(t))
                    {
                        continue;
                    }
                    var old = GlobalUtil.Find(oldassets, (x) => x.name == t);
                    if (old != null)
                    {
                        continue;
                    }
                    var clip = AnimCtrl.AllocateAnimatorClip(t);
                    AssetDatabase.AddObjectToAsset(clip, controller);
                }
                AssetDatabase.ImportAsset(path);
                Close();
            }
            rect = new Rect(130, 165, 80, 30);
            if (GUI.Button(rect, "Delete"))
            {
                GUI.FocusControl(null);
                arr.Clear();
                if (string.IsNullOrEmpty(clips) || !StringUtil.ParseArray(clips, arr, '\n'))
                {
                    return;
                }
                if (controller == null || string.IsNullOrEmpty(path))
                {
                    EditorUtility.DisplayDialog("Error", "Can't find controller.", "OK");
                    return;
                }
                var oldassets = AssetDatabase.LoadAllAssetsAtPath(path);
                foreach (var t in arr)
                {
                    if (string.IsNullOrEmpty(t))
                    {
                        continue;
                    }
                    var old = GlobalUtil.Find(oldassets, (x) => x is AnimationClip && x.name == t);
                    if (old == null)
                    {
                        continue;
                    }
                    Object.DestroyImmediate(old, true);
                }
                AssetDatabase.ImportAsset(path);
                Close();
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            ValidateProperty(property);
            label    = EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, label);
            var lv = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;
            if (sNames != null && sNames.Length > 1)
            {
                var w2   = position.width - 15f;
                var type = (AnimatorControllerParameterType)Prop(p_type).intValue;
                if (type == AnimatorControllerParameterType.Bool)
                {
                    w2 -= 16f;
                }
                else if (type == AnimatorControllerParameterType.Float || type == AnimatorControllerParameterType.Int)
                {
                    w2 = Mathf.Max(w2 * 0.5f, w2 - 60);
                }
                var w3 = position.width - 15 - w2;

                var index = EditorGUI.Popup(new Rect(position.x, position.y, w2, position.height), FindParamIndex(Prop(p_id).intValue), sNames);
                if (index > 0)
                {
                    Prop(p_name).stringValue = sList[index - 1].name;
                    Prop(p_id).intValue      = sList[index - 1].id;
                    Prop(p_type).intValue    = (int)sList[index - 1].type;
                }
                else
                {
                    Prop(p_name).stringValue = "";
                    Prop(p_id).intValue      = 0;
                    Prop(p_type).intValue    = 0;
                }
                if (type == AnimatorControllerParameterType.Bool)
                {
                    Prop(p_value).floatValue = EditorGUI.Toggle(new Rect(position.x + w2, position.y, w3, position.height), Prop(p_value).floatValue > 0.2f) ? 1 : 0;
                }
                else if (type == AnimatorControllerParameterType.Float)
                {
                    Prop(p_value).floatValue = DevilEditorUtility.FloatField(new Rect(position.x + w2, position.y, w3, position.height), "value", Prop(p_value).floatValue);
                }
                else if (type == AnimatorControllerParameterType.Int)
                {
                    Prop(p_value).floatValue = DevilEditorUtility.IntField(new Rect(position.x + w2, position.y, w3, position.height), (int)Prop(p_value).floatValue, "value");
                }
            }
            else
            {
                var w = position.width - 15;
                w = Mathf.Min(w * 0.5f, 60);
                var type = (AnimatorControllerParameterType)EditorGUI.EnumPopup(new Rect(position.x, position.y, w, position.height),
                                                                                (AnimatorControllerParameterType)Prop(p_type).intValue);
                Prop(p_type).intValue = (int)type;

                var w2 = position.width - w - 15;
                if (type == AnimatorControllerParameterType.Bool)
                {
                    w2 -= 16f;
                }
                else if (type == AnimatorControllerParameterType.Float || type == AnimatorControllerParameterType.Int)
                {
                    w2 = Mathf.Max(w2 * 0.5f, w2 - 60);
                }
                var w3 = position.width - 15 - w - w2;

                Prop(p_name).stringValue = DevilEditorUtility.TextField(new Rect(position.x + w, position.y, w2, position.height), Prop(p_name).stringValue, "param name");
                Prop(p_id).intValue      = Animator.StringToHash(Prop(p_name).stringValue);
                if (type == AnimatorControllerParameterType.Bool)
                {
                    Prop(p_value).floatValue = EditorGUI.Toggle(new Rect(position.x + w + w2, position.y, w3, position.height), Prop(p_value).floatValue > 0.2f) ? 1 : 0;
                }
                else if (type == AnimatorControllerParameterType.Float)
                {
                    Prop(p_value).floatValue = DevilEditorUtility.FloatField(new Rect(position.x + w + w2, position.y, w3, position.height), "value", Prop(p_value).floatValue);
                }
                else if (type == AnimatorControllerParameterType.Int)
                {
                    Prop(p_value).floatValue = DevilEditorUtility.IntField(new Rect(position.x + w + w2, position.y, w3, position.height), (int)Prop(p_value).floatValue, "value");
                }
            }
            if (GUI.Button(new Rect(position.xMax - 15, position.y, 15, 15), DevilEditorUtility.EmptyContent, "Icon.ExtrapolationPingPong"))
            {
                FindAnim();
            }
            EditorGUI.indentLevel = lv;
            EditorGUI.EndProperty();
        }