Example #1
0
        protected override void OnAcceptDrop()
        {
            bool act = false;

            foreach (var obj in DragAndDrop.objectReferences)
            {
                if (obj is GameObject)
                {
                    var tree = ((GameObject)obj).GetComponent <BehaviourTreeRunner>();
                    if (tree != null)
                    {
                        mAssetBinder.SetBehaviourTreeRunner(tree);
                        act = true;
                        break;
                    }
                }
                else if (obj is BehaviourTreeAsset)
                {
                    mAssetBinder.SetBehaviourTreeAsset((BehaviourTreeAsset)obj);
                    act = true;
                    break;
                }
                else if (obj is BTAsset)
                {
                    var owner = ((BTAsset)obj).TreeAsset;
                    if (owner != null)
                    {
                        mAssetBinder.SetBehaviourTreeAsset(owner);
                        act = true;
                        break;
                    }
                }
                else if (obj is BlackboardAsset)
                {
                    sUsedBlackboard = obj as BlackboardAsset;
                    act             = true;
                    break;
                }
            }
            DragAndDrop.AcceptDrag();
            if (!act)
            {
                EditorUtility.DisplayDialog("Error", "没有可用的行为树资源.", "OK");
            }
        }
Example #2
0
        protected override void OnReadCustomData(JsonData data)
        {
            base.OnReadCustomData(data);
            HelpBox.Visible = (bool)data["help"];
            mAutoLink       = (bool)data["autoLink"];
            var his = (string)data["history"];

            if (!string.IsNullOrEmpty(his))
            {
                mHistory.Clear();
                StringUtil.ParseArray(his, mHistory, '\n');
            }
            var black = (string)data["black"];

            if (sUsedBlackboard == null && !string.IsNullOrEmpty(black))
            {
                sUsedBlackboard = AssetDatabase.LoadAssetAtPath <BlackboardAsset>(black);
            }
        }
Example #3
0
 private void OnEnable()
 {
     m_Properties = serializedObject.FindProperty("m_Properties");
     mAsset       = target as BlackboardAsset;
     editIndex    = -1;
     submitEdit   = false;
     UpdateContents();
     propertyList = new ReorderableList(serializedObject, m_Properties, true, true, true, true);
     propertyList.drawHeaderCallback = (rect) =>
     {
         EditorGUI.LabelField(rect, "Blackboard Propreties");
     };
     propertyList.elementHeightCallback         = (index) => index == editIndex ? 65 : 40;
     propertyList.drawElementBackgroundCallback = DrawBackgorund;
     propertyList.drawElementCallback           = DrawElement;
     propertyList.onReorderCallback             = (x) => { UpdateContents(); };
     propertyList.onAddCallback = (x) => {
         m_Properties.arraySize++;
         editIndex = m_Properties.arraySize - 1;
         var newit = m_Properties.GetArrayElementAtIndex(editIndex);
         newit.FindPropertyRelative("comment").stringValue = "";
         //propertyList.draggable = false;
         propertyList.index = editIndex;
         submitEdit         = false;
         UpdateContents();
     };
     propertyList.onRemoveCallback = (x) =>
     {
         if (propertyList.index >= 0 && propertyList.index < m_Properties.arraySize)
         {
             m_Properties.DeleteArrayElementAtIndex(propertyList.index);
         }
         if (editIndex != -1)
         {
             submitEdit = true;
         }
     };
 }
        public static void OnBlackboardInspectorGUI(BlackboardAsset asset)
        {
            drop = QuickGUI.DrawHeader("Blackboard", "BT", false);
            if (drop)
            {
                QuickGUI.BeginContents(200);
                scroll = GUILayout.BeginScrollView(scroll, GUILayout.MaxHeight(200));
                for (int i = 0; i < asset.m_Properties.Length; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("", "OL Minus", GUILayout.Width(20)))
                    {
                        BlackboardAsset.KeyValue[] keys = new BlackboardAsset.KeyValue[asset.m_Properties.Length - 1];
                        if (i > 0)
                        {
                            System.Array.Copy(asset.m_Properties, 0, keys, 0, i);
                        }
                        if (i < asset.m_Properties.Length - 1)
                        {
                            System.Array.Copy(asset.m_Properties, i + 1, keys, i, keys.Length - i);
                        }
                        asset.m_Properties = keys;
                        EditorUtility.SetDirty(asset);
                        break;
                    }
                    BlackboardAsset.KeyValue key = asset.m_Properties[i];
                    GUILayout.Label(key.m_Key, GUILayout.Width(140));
                    GUILayout.Label(key.m_Value, "textfield");
                    EditorGUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
                GUILayout.Space(10);

                if (JDateTime.NowMillies - repeatTip < 2000)
                {
                    GUILayout.Label("已经存在相同的属性", "flow overlay box");
                }
                EditorGUILayout.BeginHorizontal();
                dropIndex = Mathf.Min(dropIndex, BehaviourModuleManager.GetOrNewInstance().SharedTypeNames.Length - 1);
                if (GUILayout.Button("", "OL Plus", GUILayout.Width(20)))
                {
                    if (string.IsNullOrEmpty(newName) || asset.HasKey(newName))
                    {
                        repeatTip = JDateTime.NowMillies;
                    }
                    else
                    {
                        BlackboardAsset.KeyValue[] keys = new BlackboardAsset.KeyValue[asset.m_Properties.Length + 1];
                        if (keys.Length > 1)
                        {
                            System.Array.Copy(asset.m_Properties, keys, keys.Length - 1);
                        }
                        BlackboardAsset.KeyValue newk = new BlackboardAsset.KeyValue();
                        newk.m_Key            = newName;
                        newk.m_Value          = BehaviourModuleManager.GetOrNewInstance().SharedTypeNames[dropIndex];
                        keys[keys.Length - 1] = newk;
                        asset.m_Properties    = keys;
                        EditorUtility.SetDirty(asset);
                        newName = "newVariable";
                        scroll  = Vector2.up * asset.m_Properties.Length * 30;
                    }
                }
                newName   = GUILayout.TextField(newName ?? "newVariable", GUILayout.Width(140));
                dropIndex = EditorGUILayout.Popup(dropIndex, BehaviourModuleManager.GetOrNewInstance().SharedTypeNames);
                EditorGUILayout.EndHorizontal();
                QuickGUI.EndContents();
            }
        }